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 


attempt to call a nil value cheat engine

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

Joined: 14 Sep 2017
Posts: 33

PostPosted: Wed Dec 13, 2017 11:18 am    Post subject: attempt to call a nil value cheat engine Reply with quote

Hi Guyes ... can anyone tell me how fix ches problem please ?
attempt to call a nil value cheat engine
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Wed Dec 13, 2017 2:54 pm    Post subject: Reply with quote

find where you're trying to call a function that doesn't exist (is "nil"), line numbers can often help you, at that point you can use print(tostring(...)) for any function/variable you're trying to use (copy + paste) to make sure you haven't mistyped it or verify that it was properly set.
Back to top
View user's profile Send private message
dedlyblady
Cheater
Reputation: 0

Joined: 14 Sep 2017
Posts: 33

PostPosted: Wed Dec 13, 2017 8:10 pm    Post subject: Reply with quote

FreeER wrote:
find where you're trying to call a function that doesn't exist (is "nil"), line numbers can often help you, at that point you can use print(tostring(...)) for any function/variable you're trying to use (copy + paste) to make sure you haven't mistyped it or verify that it was properly set.


thanks for replay ... u can uplaod u my Script see this problems and fixed it because i dont have enogh Experience For this .. Rolling Eyes
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Thu Dec 14, 2017 10:44 am    Post subject: Reply with quote

If you can write the script you should be able to go to the given line number and add "print(tostring(some variable name))" before it... but sure you can share the script here and maybe I'll be able to figure it out without having to run the script (because if I do have to run the script then the likelihood of me having the game to test with is pretty low).
Back to top
View user's profile Send private message
tolo
How do I cheat?
Reputation: 0

Joined: 15 Dec 2017
Posts: 2

PostPosted: Tue Dec 19, 2017 6:15 am    Post subject: Reply with quote

this is my script and i always get the error:

Error:[string "ByX = readFloat('[[[[["game..."]:21: attempt to perform arithmetic on a nil value

Code:

ByX = readFloat('[[[[["game.exe"+0016C451C]+444]+2c]+108]+4]+30')
ByY = readFloat('[[[[["game.exe"+0016C451C]+444]+2c]+108]+4]+38')
ByZ = readFloat('[[[[["game.exe"+0016C451C]+444]+2c]+108]+4]+34')
botX = readFloat('[[[[["game.exe"+01691940]+DC]+0]+1C]+110]+64')
botY = readFloat('[[[[["game.exe"+01691940]+DC]+0]+1C]+110]+6C')
botZ = readFloat('[[[[["game.exe"+01691940]+DC]+0]+1C]+110]+68')
Cam_X = readFloat('[[[[["game.exe"+016C0E24]+464]+4]+EC]+4]+44')
Cam_Y = readFloat('[[[["game.exe"+016C44EC]+74]+f8]+1C]+4f4')

print (ByX)
print (ByY)
print (ByZ)
print (botX)
print (botY)
print (botZ)
print (Cam_X)
print (Cam_Y)

function sight_angle()

         calcX=readFloat(ByX)-readFloat(botX)
         calcY=readFloat(ByY)-readFloat(botY)
         calcZ=readFloat(ByZ)-readFloat(botZ)+5

         distance=math.sqrt(math.pow(calcX, 2)+math.pow(calcY, 2))

         angleX=math.deg(math.atan2(calcX, calcY))+180
         angleY=math.deg(math.atan2(calcZ, distance))


         if (isKeyPressed(VK_V)) then
          writeFloat(Cam_X, angleX)
          writeFloat(Cam_Y, angleY)
         end
end


t=createTimer(1)
timer_setInterval(t, 10000)
timer_onTimer(t, sight_angle)




the float values get printed in the lua Output like in cheat engine but the calculation of the function doesn't work, why!?
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Tue Dec 19, 2017 7:55 am    Post subject: Reply with quote

Ok, since I don't have the game I modified it to this for testing
Code:
ByX = 1
ByY = 2
ByZ = 3
botX = 4
botY = 5
botZ = 6
Cam_X = 7
Cam_Y = 8


I still get an error on line 21 which is
Code:
calcX=readFloat(ByX)-readFloat(botX)
Which is trying to use the values ByX and botX as addresses/pointers to floats, but you read those as floats, so it looks like you're trying to use the x positions as addresses, since those are probably invalid addresses one or both read calls return nil and you then get an error trying to subtract [from] nil.

So, did you really intend to read from memory again there or did you just want to use the floats that you'd already read from memory?

----

btw, with the check for key v inside the timer it will only check for v once every 10 seconds (since the timer is set to an interval of 10000 milliseconds), that doesn't really seem like what you'd want. With the values being global (not local to the script) you can use CE's hotkeys which "constantly" check for you and allow up to 5 keys eg.

Code:
...
-- to disable, destroy timer t and hotkey h
t=createTimer(1)
timer_setInterval(t, 3000) -- can also use t.Interval = 3000
timer_onTimer(t, sight_angle) -- can also use t.OnTimer = sight_angle

-- set initial values so they aren't nil if user presses v before timer runs
-- passing nil will write 0, but it's more intuitive to use 0 if you want that :)
angleX = readFloat(Cam_X)
angleY = readFloat(Cam_Y)

-- takes a function to run and up to 5 virtual key codes (can be in a table)
h = createHotkey(function()
  writeFloat(Cam_X, angleX)
  writeFloat(Cam_Y, angleY)
end, VK_V)
Back to top
View user's profile Send private message
jgoemat
Master Cheater
Reputation: 22

Joined: 25 Sep 2011
Posts: 252

PostPosted: Wed Feb 21, 2018 3:27 am    Post subject: Reply with quote

To help you debug in the future, the error message says line 21:

Code:
calcX=readFloat(ByX)-readFloat(botX)


The first thing I'd do would be to separate that out into the smallest pieces of code you can and print the values:

Code:
local x1 = readFloat(ByX)
print("x1 is "..tostring(x1).." from address "..tostring(ByX))
local x2 = readFloat(botX)
print("x2 is "..tostring(x2).." from address "..tostring(botX))
calcX = x1-x2


That takes about 2 minutes and you can see quickly in the lua window that at least one of x1 or x2 is nil and why, and that the error is on the last line now so the subtract is failing and not the calls to readFloat().
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