Unending lua loop

How can be this controlled in that simulator? Can HIDmacros be used with this application?
Post Reply
Zapp Brannigan
Posts: 2
Joined: 21 Dec 2018, 02:04

Unending lua loop

Post by Zapp Brannigan » 21 Dec 2018, 03:44

Hey everyone, new to posting on the site but used it as a quick help for the last year or so. Thanks for all the help.

Currently I am trying to setup a script for the game Forts on my Logitech G510 keyboard. I am wanting to press G9 and then having a loop of "E", a wait, "TAB", and then another wait, until I release G9. And also I want to press G12 and have it loop "U", wait, "TAB", wait, until I press G12 again.

Normally for other games, I simply plug in what I want to happen and set the G-key to a repeating option such as repeat every 50ms and the key as a toggle. However for some reason, while this does work on other games and when I test the profile it works flawlessly, in Forts it does nothing.

So I decided to try create a script for the keyboard to run when I press the G-keys in Forts (the G510 has a scripting section for each profile). Currently the script does work with what I have coded in game (not sure why my code is better than simply selecting what I want in the standard way), however the script runs on a loop until I restart my PC. Here is my code so far, can anyone show me what I am doing wrong?

Code: Select all

function OnEvent(event, arg, family)			//required for the G510 for some reason
	if event == "G_PRESSED" and arg == 9 then	//when G9 is pressed activate
		repeat PressKey("e"); Sleep(100); ReleaseKey("e"); Sleep(100); PressKey("tab"); Sleep(100); ReleaseKey("tab"); Sleep(100); until event=="G_RELEASED" and arg==9		//unending loop
	if event == "G_PRESSED" and arg == 12 then		//when G12 is pressed activate
	state = not state					//toggle function I have used for other games without problem, normally if I press the G-key it holds another key until the G-key is pressed again
	while state do						//loop function 
		PressKey("u"); Sleep(100); ReleaseKey("u"); Sleep(100); PressKey("tab"); Sleep(100); ReleaseKey("tab"); Sleep(100);
From testing if I press G9 it will run the script correctly in game, however it will run the script repeatedly until I can kill it or restart my PC. If I press G12 it does the same thing.

Post Reply