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 


help with lua workaround/error

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

Joined: 27 Jul 2021
Posts: 5

PostPosted: Sun Aug 08, 2021 7:56 pm    Post subject: help with lua workaround/error Reply with quote

I am using a script to multiply the amount of some velocities every second, it works fine when the pointers are found, but when the pointers are ?? i get a lua error " attempt to perform arithmetic on a string value (field 'Value')" and since this repeats every second it gives me an error every second. Is there any work around for this?

code:
Code:
{$lua}
local al = getAddressList()
local lpvx1 = al.getMemoryRecordByDescription("LPVelX1")
local lpvz1 = al.getMemoryRecordByDescription("LPVelZ1")
local mp = 1.5
[ENABLE]
function enable(timer)

lpvx1.Value = lpvx1.Value * mp
lpvz1.Value = lpvz1.Value * mp
end

t=createTimer(0)
timer_setInterval(t, 1000)
timer_onTimer(t, enable)
timer_setEnabled(t, true)


[DISABLE]
timer_onTimer(t, disable)
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4706

PostPosted: Sun Aug 08, 2021 8:28 pm    Post subject: Reply with quote

The Value property of memory records is a string. Use tonumber to explicitly convert it to a number, and only continue if that succeeds (i.e. doesn't return nil).
Code:
local x,z = tonumber(lpvx1.Value), tonumber(lpvz1.Value)
if x and z 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
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine 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