View previous topic :: View next topic |
Author |
Message |
bknight2602 Grandmaster Cheater Reputation: 0
Joined: 08 Oct 2012 Posts: 577
|
Posted: Tue Jan 19, 2016 6:38 pm Post subject: Getting nil value |
|
|
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 |
|
|
Zanzer I post too much Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Tue Jan 19, 2016 7:05 pm Post subject: |
|
|
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 |
|
|
bknight2602 Grandmaster Cheater Reputation: 0
Joined: 08 Oct 2012 Posts: 577
|
Posted: Tue Jan 19, 2016 8:52 pm Post subject: |
|
|
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 |
|
|
|