Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Getting nil value

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Tue Jan 19, 2016 6:38 pm    Post subject: Getting nil value Reply with quote

Here is a small code
Code:

AL = getAddressList()
if tonumber(memoryrecord_getValue(addresslist_getMemoryRecordByDescription(AL, "Rec 1 Alt Sec Weapon 1st Name"))) >= 131 or
        tonumber(memoryrecord_getValue(addresslist_getMemoryRecordByDescription(AL, "Rec 1 Alt Sec Weapon 1st Name"))) >= 136 and
        tonumber(memoryrecord_getValue(addresslist_getMemoryRecordByDescription(AL, "Rec 1 Alt Sec Weapon 2nd Name"))) >= 0 then
          memoryrecord_setValue(addresslist_getMemoryRecordByDescription(AL, "Rec 1 Alt Sec Weapon Group Num"), 99)
        end

When running I get an error "attempting to compare nil with number"
Now when typing into the debug window
Code:

print(tonumber(memoryrecord_getValue(addresslist_getMemoryRecordByDescription(AL, "Rec 1 Alt Sec Weapon 1st Name"))))
print(tonumber(memoryrecord_getValue(addresslist_getMemoryRecordByDescription(AL, "Rec 1 Alt Sec Weapon 2nd Name"))))

I receive the values of
136
0
These are correct, currently. So why do I get the error?
ETA: The error notification occurs on the first comparison.
Back to top
View user's profile Send private message Yahoo Messenger
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Tue Jan 19, 2016 7:05 pm    Post subject: Reply with quote

I have no problem executing your script. You sure the problem is there?
I would like to point out that the last two statements in the IF will never evaluate to true and are useless.
Anyway, try changing it up to:
Code:
local AL = getAddressList()
local var1 = tonumber(memoryrecord_getValue(addresslist_getMemoryRecordByDescription(AL, "Rec 1 Alt Sec Weapon 1st Name")))
local var2 = tonumber(memoryrecord_getValue(addresslist_getMemoryRecordByDescription(AL, "Rec 1 Alt Sec Weapon 2nd Name")))
print(var1)
print(var2)
if var1 >= 131 or var1 >= 136 and var2 >= 0 then
  memoryrecord_setValue(addresslist_getMemoryRecordByDescription(AL, "Rec 1 Alt Sec Weapon Group Num"), 99)
end
Back to top
View user's profile Send private message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Tue Jan 19, 2016 8:52 pm    Post subject: Reply with quote

Actually the code was not correct as the values were equality instead of an inequality. After setting to == the statements worked without error, but in answer to your question, yes I was getting the error I reported. The error quit happening after the statements were changed to equalities.
Thanks
Back to top
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites