Jump to content
  • 0

Error I can't fix since days


YeetMeister

Question

hello, im working on a Open Source Cham Editor for Forward Assault and i got some problems.

1. the values doesnt get saved
2. the modification of the values(if they get saved) doesnt work

Error:
Line 47
"gg.addListItems(x) bad argument, nil: table expected got nil"

base = false
pOffset = false
sOffset = false
wOffset = false



function chamSearch()
  if base == false
    then
      base = true
      --search for ChamBase
      gg.setRanges(gg.REGION_VIDEO)
      gg.searchNumber("8;9;24;1,065,814,589::", 4)
      gg.refineNumber("1,065,814,589", 4)
      _G.ChamBase = gg.getResults(3)
      cP = {
        ChamBase[1]
      }
      cS = {
        ChamBase[2]
      }
      cW = {
        ChamBase[3]
     }
      gg.addListItems(ChamBase)
      gg.clearResults()
      PlayerOffset()
    end
end

function PlayerOffset()
if pOffset == false
  then
    pOffset = true
    gg.setRanges(gg.REGION_VIDEO)
    gg.loadResults(cP)
    _G.chamPlayer = gg.getResults(1)[1]
      for x = 1, 3
        do
          chamPlayer[x] = {}
          chamPlayer[x].flags = gg.TYPE_DWORD
        end 
        chamPlayer[1].address = gg.getResults(1)[1].address - 0x134
        chamPlayer[2].address = gg.getResults(1)[1].address - 0x144
        chamPlayer[3].address = gg.getResults(1)[1].address - 0x14C
        gg.addListItems(chamPlayer[x])
        print(chamPlayer[x])
        gg.clearResults()
        ScopeOffset()
    end
end

function ScopeOffset()
if sOffset == false
  then
    sOffset = true
    gg.setRanges(gg.REGION_VIDEO)
    gg.loadResults(cS)
    _G.chamScope = gg.getResults(1)[1]
      for x = 1, 3
        do
          chamScope[x] = {}
          chamaScope[x].flags = gg.TYPE_DWORD
        end
        chamScope[1].address = gg.getResults(1)[1].address - 0x134
        chamScope[2].address = gg.getResults(1)[1].address - 0x144
        chamScope[3].address = gg.getResults(1)[1].address - 0x14C
        gg.addListItems(x)
        print(chamScope)
        gg.clearResults()
        ScopeOffset()
    end
end

function WeaponOffset()
if wOffset == false
  then
    wOffset = true
    gg.setRanges(gg.REGION_VIDEO)
    gg.loadResults(cW)
    _G.chamWeapon = gg.getResults(1)[1]
      for x = 1, 3
        do
        	chamWeapon[x] = {}
        	chamWeapon[x].flags = gg.TYPE_DWORD
       end
       chamWeapon[1].address = gg.getResults(1)[1].address - 0x134
       chamWeapon[2].address = gg.getResults(1)[1].address - 0x144
       chamWeapon[3].address = gg.getResults(1)[1].address-  0x14C
       gg.removeListItems(cW)
       gg.addListItems(x)
       print(chamWeapon)
       gg.clearResults()
     end
end

--[[]
t = player/scope/weapon, 
r = r value of t, 
g = g value of t, 
b = b value of t
]]

function modify(t, r, g, b)
  if t == player
      then
        gg.getListItems(chamPlayer)
        for v, k in ipairs(chamPlayer)
          do
            v[1].value = b
            v[2].value = g
            v[3].value = r
          end
    gg.setValues(v)
  end
  if t == scope
      then
        gg.getListItems(chamScope)
        for v, k in ipairs(chamScope)
          do
            v[1].value = b
            v[2].value = g
            v[3].value = r
          end
    gg.setValues(v)
  end
if t == weapon
  then
    gg.getListItems(chamPlayer)
        for v, k in ipairs(chamPlayer)
          do
            v[1].value = b
            v[2].value = g
            v[3].value = r
          end
    gg.setValues(v)
  end
  if t == scope
      then
        gg.getListItems(chamScope)
        for v, k in ipairs(chamScope)
          do
            v[1].value = b
            v[2].value = g
            v[3].value = r
          end
    gg.setValues(v)
  end
end
chamSearch()
modify("player", 1, 2, 3)

[Script Download]

 

output.lua

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • Administrators

You mess with indentation.

So you can not see error in obvious way.

Your code:

      for x = 1, 3
        do
          chamPlayer[x] = {}
          chamPlayer[x].flags = gg.TYPE_DWORD
        end 
        chamPlayer[1].address = gg.getResults(1)[1].address - 0x134
        chamPlayer[2].address = gg.getResults(1)[1].address - 0x144
        chamPlayer[3].address = gg.getResults(1)[1].address - 0x14C
        gg.addListItems(chamPlayer[x])
        print(chamPlayer[x])
        gg.clearResults()
        ScopeOffset()

Proper indentation:

        for x = 1, 3 do
          chamPlayer[x] = {}
          chamPlayer[x].flags = gg.TYPE_DWORD
        end 
        chamPlayer[1].address = gg.getResults(1)[1].address - 0x134
        chamPlayer[2].address = gg.getResults(1)[1].address - 0x144
        chamPlayer[3].address = gg.getResults(1)[1].address - 0x14C
        gg.addListItems(chamPlayer[x])
        print(chamPlayer[x])
        gg.clearResults()
        ScopeOffset()

Now you can see: you try use `x` outside loop. And get nil. So you try index with nil. And get nil. This nil you pass to gg.addListItems.

 

And if you print something, you need print it before error, not after. After is never run so it is useless.

And one line can help you if you add before `gg.addListItems(chamPlayer[x])`:

print(x, chamPlayer[x])

Here you must see `nil, nil` which not expected output.

Link to comment
Share on other sites

1 hour ago, YeetMeister said:

2. the modification of the values(if they get saved) doesnt work

This is because your usage of "getListItems" function is wrong. You pass an argument to it and don't store returned value, when in the documentation it is written that the function does not have parameters and returns a table of the saved list items (https://gameguardian.net/help/classgg.html#a4fd09c150fe2527816abb729dfea2801).

Another moment is that when working with saved list items, you need a way to identify desired items. For example, it can be special names of those items. Also, I think that using saved list for your case is completely optional, because you can store tables with needed values in variables and use them whenever you need to modify those values.

Link to comment
Share on other sites

  • Administrators

Here a lot of odd code.

gg.loadResults(cP)
_G.chamPlayer = gg.getResults(1)[1]
[...]
gg.clearResults()

Look like you need here getValues.
Similar code happens 3 times.

for x = 1, 3 do
    chamScope[x] = {}
    chamaScope[x].flags = gg.TYPE_DWORD
end
[...]
gg.addListItems(x)
print(chamScope)

Use x outside loop.
Use index self instead of retrieve value from table.
Typo in var name - chamaScope instead of chamScope.

_G.chamWeapon = gg.getResults(1)[1]
for x = 1, 3 do
    chamWeapon[x] = {}
    chamWeapon[x].flags = gg.TYPE_DWORD
end
chamWeapon[1].address = gg.getResults(1)[1].address - 0x134
chamWeapon[2].address = gg.getResults(1)[1].address - 0x144
chamWeapon[3].address = gg.getResults(1)[1].address-  0x14C

gg.getResults(1)[1] called four times.
First line do not do anything at all. Same as
chamWeapon = {}

[added 1 minute later]

And all three functions are so similar to each other that they can definitely be replaced with one with a cycle.

Strictly speaking, there is much where else this can be done.

Link to comment
Share on other sites

4 hours ago, YeetMeister said:

Can you tell me more about this

Basically, you can achieve that in 2 steps: 

  1. Save information about desired memory items in a table. The table can be obtained using any of the following ways (or their combinations): 
        - returned by "getResults" function;
        - returned by "getValues" function;
        - created or modified manually.
    Basic example: 
    gg.searchNumber('123', gg.TYPE_DWORD)
    local results = gg.getResults(10)
  2. Use saved table to modify the values of desired memory items. The changes can be applied by calling "setValues" function with modified table as argument..
    Basic example: 
    -- Using the table from previous example
    for i, v in ipairs(results) do
      v.value = '456'
    end
    gg.setValues(results)

 

Link to comment
Share on other sites

22 minutes ago, YeetMeister said:

so I can do gg.loadResults() and save the results then in a table?

You can, but this would be redundant, if you already have a table with information about desired memory items (essentially, addresses and types). For your case it is enough to perform first step from my previous post once (per script run), then perform second step whenever it is needed. Therefore, you don't need to use "loadResults" at all.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.