Posted: Thu Oct 25, 2012 10:58 pm Post subject: Passing variables to functions called by hotkeys
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:
...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...
Joined: 09 May 2003 Posts: 25288 Location: The netherlands
Posted: Fri Oct 26, 2012 1:29 am Post subject:
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
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!
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...
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