William Wolfrom
William Wolfrom

Reputation: 1

Attempt to perform arithmetic on a nil value

Here is the code im working with,

 function Speedhack1()
boost = 1.5
if (readBytes('[_speed]') ~- nil) then
writeFloat ('[_speed]+DC', readFloat('[_speed]+DC')*boost)
writeFloat ('[_speed]+E0', readFloat('[_speed]+E0')*boost)
writeFloat ('[_speed]+E4', readFloat('[_speed]+E4')*boost)
end
end
createHotkey(Speedhack1, VK_UP)

function Speedhack2()
boost = 0.5
if (readBytes('[_speed]') ~- nil) then
writeFloat ('[_speed]+DC', readFloat('[_speed]+DC')*boost)
writeFloat ('[_speed]+E0', readFloat('[_speed]+E0')*boost)
writeFloat ('[_speed]+E4', readFloat('[_speed]+E4')*boost)
end
end
createHotkey(Speedhack2, VK_DOWN)

Ive defined speed and made pointers with the corresponding offsets my aob script to find speed works and the lua script gets executed but when pressing one of the hotkeys to start the function it gives me

Error:[string "function Speedhack1() ..."]:3: attempt to perform arithmetic on a nil value

if _speed has been defined and the offsets match i thought ~-nil would be the proper way to say "whatever the value is"

Upvotes: 0

Views: 4762

Answers (1)

Ivo
Ivo

Reputation: 23234

You probably meant to write ~= because ~- doesn't make much sense here. But it can also just be left out and you can write

if (readBytes('[_speed]')) then

This also checks whether it's not nil (or false)

Upvotes: 0

Related Questions