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 


lua help with 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: Wed Aug 18, 2021 4:43 pm    Post subject: lua help with error Reply with quote

Hi, I have this code that multiplies your velocity every second but it uses pointers, so when the pointers are ?? it gives me this lua error "attempt to compare nil with number" is there any way to fix this
Note: the velocities are negative or positive because of how the game does velocities. So -1 would be subtracting a coordinate and +1 could be adding the coordinate.

Code:

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

  if lpvx1.Value ~= nil then

    if tonumber(lpvx1.Value) < -1 then
    lpvx1.Value = -1.663
    elseif tonumber(lpvx1.Value) > 1 then
    lpvx1.Value = 1.663
    end
   end
 if lpvz1.Value ~= nil then

    if tonumber(lpvz1.Value) < -1 then
    lpvz1.Value = -1.663
    elseif tonumber(lpvz1.Value) > 1 then
    lpvz1.Value = 1.663
    end
  end
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
Frouk
Grandmaster Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 510

PostPosted: Thu Aug 19, 2021 1:02 am    Post subject: Reply with quote

Code:
PlayerPTR = '[[[game.exe] + 0x4C] + 0x16] + 0x0' --Example of pointer
if PlayerPTR ~= nil then
--Paste your code here
end

or
Code:

PlayerPTR = '[[[game.exe] + 0x4C] + 0x16] + 0x0' --Example of pointer
if readPointer(PlayerPTR) ~= nil then
--Paste your code here
end
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 51

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Thu Aug 19, 2021 4:00 pm    Post subject: Reply with quote

TitusHM wrote:
...

Because you're reading the value multiple times, it's likely changing after you check for nil. So I'd read the value to a variable and check that.


Frouk wrote:
Code:
PlayerPTR = '[[[game.exe] + 0x4C] + 0x16] + 0x0' --Example of pointer
if PlayerPTR ~= nil then
--Paste your code here
end

...

In this example you're setting the variable to a string then checking for nil, so this will always equate to TRUE. You should use "getAddressSafe" to check if the address is good.

_________________
Back to top
View user's profile Send private message Visit poster's website
Frouk
Grandmaster Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 510

PostPosted: Fri Aug 20, 2021 10:10 am    Post subject: Reply with quote

TheyCallMeTim13 wrote:
TitusHM wrote:
...

Because you're reading the value multiple times, it's likely changing after you check for nil. So I'd read the value to a variable and check that.


Frouk wrote:
Code:
PlayerPTR = '[[[game.exe] + 0x4C] + 0x16] + 0x0' --Example of pointer
if PlayerPTR ~= nil then
--Paste your code here
end

...

In this example you're setting the variable to a string then checking for nil, so this will always equate to TRUE. You should use "getAddressSafe" to check if the address is good.


well, i was using my code in many cases
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