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 


What is the best way to filter out a nil value.

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

Joined: 15 Dec 2016
Posts: 29

PostPosted: Wed Sep 15, 2021 2:23 pm    Post subject: What is the best way to filter out a nil value. Reply with quote

This address I'm using to get a value from can sometimes give a nil value. I was trying to filter out the nil result. I wanted it to keep looping until it got a result that wasn't nil. But it still fails when doing the math.floor because it was trying to do math on a nil value.


Code:

while true do
  if tonumber(DirectionFloatValue.Value) ~= nil then
    ArrowMath = math.floor(tonumber(DirectionFloatValue.Value))
    break
  end
end
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

Joined: 09 May 2003
Posts: 25287
Location: The netherlands

PostPosted: Wed Sep 15, 2021 2:54 pm    Post subject: Re: What is the best way to filter out a nil value. Reply with quote

AmyGrrl wrote:
This address I'm using to get a value from can sometimes give a nil value. I was trying to filter out the nil result. I wanted it to keep looping until it got a result that wasn't nil. But it still fails when doing the math.floor because it was trying to do math on a nil value.


Code:

while true do
  if tonumber(DirectionFloatValue.Value) ~= nil then
    ArrowMath = math.floor(tonumber(DirectionFloatValue.Value))
    break
  end
end


perhaps the value becomes unreadable again right after one proper read

try

Code:
 
while true do
  local v=tonumber(DirectionFloatValue.Value)
  if v ~= nil then
    ArrowMath = v
    break
  end
end


or better use a timer instead of while loop

_________________
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
View user's profile Send private message MSN Messenger
AmyGrrl
Cheater
Reputation: 0

Joined: 15 Dec 2016
Posts: 29

PostPosted: Wed Sep 15, 2021 3:15 pm    Post subject: Reply with quote

Thanks. So I just needed to store the value and then check if it was nil. If the stored value isn't nil. Then do the math.floor on the stored value.
Back to top
View user's profile Send private message
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