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 


Attempting to compare nil with number (ReadFloat)

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
BlasterXD
How do I cheat?
Reputation: 0

Joined: 18 Jan 2019
Posts: 2

PostPosted: Fri Jan 18, 2019 7:15 am    Post subject: Attempting to compare nil with number (ReadFloat) Reply with quote

Hello

I wrote a script which checks the player's hp (using a pointer), and if it is below 60 it will slowly add back 1 health point (sleep(500)) until it reaches a value.

Code looks something like this:
Code:

while (value < RegenValue)
do
writeFloat(address,value+1)
sleep(500)
end




It works perfectly, except for one thing. When there is a map/level change in the game, the script will error out, attempting to compare nil with number, most likely because between level loads, before the player has spawned, the hp value does not exist.

Is there any way I could work around this? Very Happy
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4289

PostPosted: Fri Jan 18, 2019 9:35 am    Post subject: Reply with quote

Code:
if value then
  ...
end

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
BlasterXD
How do I cheat?
Reputation: 0

Joined: 18 Jan 2019
Posts: 2

PostPosted: Fri Jan 18, 2019 10:19 am    Post subject: Reply with quote

Thank you for your reply!
I already tried that and it didn't seem to work, because the script stops thanks to the error, I don't want it to stop. I tried using PCall, which made the error disappear, but the script just stops itself.

Let me try something again.

EDIT: Managed to fix it! I changed while(hp < hpregen) to if statements, and added a check if (hp == nil) then it will just repeat itself.

Thanks for the help! Very Happy
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