| View previous topic :: View next topic |
| Author |
Message |
mindoff Advanced Cheater
Reputation: 0
Joined: 12 Jun 2016 Posts: 96
|
Posted: Thu Aug 01, 2019 3:31 am Post subject: Why loop through list get index error? |
|
|
I got 4 item in cheat table and run the following lua code
| Code: |
local addressList = getAddressList()
if addressList.getCount() >= 1 then
for i in ipairs(addressList) do
print(i)
end
end
|
It gives me this output
1
2
3
Error:TTreeNodes.GetNodeFromIndex Index 4 out of bounds (Count=4)
If I use for do loop to loop through addressList,it won't give me error
But if I use for loop in a script not just the lua test window.
It will still give me index error,why? |
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25830 Location: The netherlands
|
Posted: Thu Aug 01, 2019 4:13 am Post subject: |
|
|
ipairs functions by looping 1 to infinite until it returns nil
addressList does not return nil but errors out if you go above
alson addressList starts the index at 0, not 1
so don't use ipairs for addressList but use a for loop instead
for i=0,addressList.Count-1 do
print(i)
end _________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
mindoff Advanced Cheater
Reputation: 0
Joined: 12 Jun 2016 Posts: 96
|
Posted: Thu Aug 01, 2019 5:01 am Post subject: |
|
|
Here is the errorTest.
Could someone explain what's wrong?
can't post attachment so I paste the ct source here.
I still get index error when I destroy MemoryRecord from script not lua test window.
That lua test window and script always give me different result really make me confused...
| Code: |
<?xml version="1.0" encoding="utf-8"?>
<CheatTable CheatEngineTableVersion="26">
<CheatEntries>
<CheatEntry>
<ID>7</ID>
<Description>"Auto Assemble script"</Description>
<LastState/>
<VariableType>Auto Assembler Script</VariableType>
<AssemblerScript>[ENABLE]
{$lua}
local addressList = getAddressList()
len = addressList.Count
if addressList.Count > 0 then
for i = len - 1, 0, -1 do
itemDesc = addressList[i].getDescription()
ret = string.match(itemDesc, "hero_")
if ret == "hero_" then
addressList[i].destroy()
end
end
end
[DISABLE]
</AssemblerScript>
</CheatEntry>
<CheatEntry>
<ID>0</ID>
<Description>"1"</Description>
<LastState Value="3" RealAddress="01014000"/>
<VariableType>4 Bytes</VariableType>
<Address>01014000</Address>
</CheatEntry>
<CheatEntry>
<ID>1</ID>
<Description>"2"</Description>
<LastState Value="3" RealAddress="01014000"/>
<VariableType>4 Bytes</VariableType>
<Address>01014000</Address>
</CheatEntry>
<CheatEntry>
<ID>2</ID>
<Description>"3"</Description>
<LastState Value="3" RealAddress="01014000"/>
<VariableType>4 Bytes</VariableType>
<Address>01014000</Address>
</CheatEntry>
<CheatEntry>
<ID>3</ID>
<Description>"4"</Description>
<LastState Value="3" RealAddress="01014000"/>
<VariableType>4 Bytes</VariableType>
<Address>01014000</Address>
</CheatEntry>
<CheatEntry>
<ID>8</ID>
<Description>"hero_1"</Description>
<LastState Value="3" RealAddress="01014000"/>
<VariableType>4 Bytes</VariableType>
<Address>01014000</Address>
</CheatEntry>
<CheatEntry>
<ID>9</ID>
<Description>"hero_2"</Description>
<LastState Value="3" RealAddress="01014000"/>
<VariableType>4 Bytes</VariableType>
<Address>01014000</Address>
</CheatEntry>
</CheatEntries>
<UserdefinedSymbols/>
</CheatTable>
|
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25830 Location: The netherlands
|
Posted: Thu Aug 01, 2019 5:20 am Post subject: |
|
|
you're destroying the memoryrecord you're activating as well
so when the function returns to set the state of the memoryrecord to active or not active it'll crash _________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
mindoff Advanced Cheater
Reputation: 0
Joined: 12 Jun 2016 Posts: 96
|
Posted: Thu Aug 01, 2019 5:45 am Post subject: |
|
|
So what should I do if I want to delete memoryrecord with specfic description name from script to make things work withour error?Any method I can do this correctly?
And you know what,the funny thing is if you move the script down to the bottom and run it again,it will work.
Since I will add memoryrecord from script and will add to bottom by default,so I need to figure why those thing really different.
And how to make a correct script run at any place. |
|
| Back to top |
|
 |
panraven Grandmaster Cheater
Reputation: 62
Joined: 01 Oct 2008 Posts: 959
|
Posted: Thu Aug 01, 2019 6:44 am Post subject: |
|
|
Somehow the memory record has an unlisted method 'delete',
probably from treenode class (but no deleteChildren method);
you can delete itself or its children like these:
| Code: |
mr.delete() -- delete itself
while mr.Count>0 do mr[0].delete() end -- delete all its children
|
_________________
- Retarded. |
|
| Back to top |
|
 |
|