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 


Passing variables to functions called by hotkeys

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

Joined: 05 Oct 2012
Posts: 4

PostPosted: Thu Oct 25, 2012 10:58 pm    Post subject: Passing variables to functions called by hotkeys Reply with quote

I've wrote a pretty serviceable lua script for finding and registering coordinates for my player in a unity game. I want to be able to skew myself around the map. It works when I do it manually in CE so this script is meant to automate the process of finding and assigning hotkeys. The problem is that when I call a generic function with the hotkeys and pass variables ("birdx" and an integer to move by) to it like so:

hk_XMinus1 = createHotkey( Warp( "birdx", -1 ), VK_X, 189);

...it works on the first pass through the script but subsequent calls produce the "Attempt to call nil value" error. It won't even get into the function-- I've proven this by using a debug print message at the beginning of the function.

So, I figure that what's happening is that somehow the hotkey assignment loses the variables after it runs once or during initial script execution. It works fine if I just reduce it to one function for each movement, like this:

hk_XMinus1 = createHotkey( WarpXUp1, VK_X, 189);

But that seems so 'uncivilized.' Is there a way to use a global variable or some other method to keep CE for losing track of the variables assigned to the function a hotkey is calling??

_________________
Yep, I'm a bird veterinarian and an amateur programmer/hacker...
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

Joined: 09 May 2003
Posts: 25288
Location: The netherlands

PostPosted: Fri Oct 26, 2012 1:29 am    Post subject: Reply with quote

It was supposed to be a "function name(sender)" calling method with sender the GenericHotkey object returned by createHotkey, where you can then lookup the sender in a list and decide what to do with it.
But it seems that's broken...
So yeah, for now use different functions

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
akeaglevet
How do I cheat?
Reputation: 0

Joined: 05 Oct 2012
Posts: 4

PostPosted: Sun Oct 28, 2012 12:24 am    Post subject: Reply with quote

Thanks for the quick reply, DarkByte. Sorry I seem to have found a flaw in what has otherwise been a totally awesome bag of tools. Thanks for all you do! Smile

For the record, this is what I did to make it work and save a little bit of redundancy in the code:

1) Used something like this to define the hotkeys:
hk_XMinus1 = createHotkey( WarpXUp1, VK_X, 189 );

2) The WarpXUp1 function is used to supply variables to the Warp function...looks like this:
function WarpXUp1( )
Warp( "birdx", 1 );
return true;
end

3) And then I use one function to actually do the work:
function Warp( sym, factor )
v = readFloat( sym );
writeFloat( sym, v + factor );
beep()
return v + factor;
end

_________________
Yep, I'm a bird veterinarian and an amateur programmer/hacker...
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