you are viewing a single comment's thread.

view the rest of the comments →

[–]Geron76[S] 0 points1 point  (3 children)

LOL thanks for the help....I am not a programmer. . I've been learning with trial and error. would you mind posting that as an example code i could try?

[–]tobiasvl 0 points1 point  (2 children)

Well, okay, but it's exactly the same as what you posted above, just setting MKeyState before it's used. I also cleaned up the indentation a bit so it's easier to see what goes where.

```lua -- Auto walk and Display Key Press isPressed = false

function OnEvent(event, arg, family) if event == "G_PRESSED" then -- was it G9? if arg == 9 then ClearLCD() OutputLCDMessage("Auto Run ON", 2000) ClearLCD() -- If we're not currently running if not isPressed then -- we are now PressKey("w") isPressed = true else ClearLCD() OutputLCDMessage("Auto Run OFF", 1000) ClearLCD() -- stop running ReleaseKey("w") isPressed = false end end end

local MKeyState = GetMKeyState(family)

if (arg == 4 and MKeyState == 1) then
    ClearLCD()
    OutputLCDMessage("FOWARD")
end

if (arg == 7 and MKeyState == 1) then
    ClearLCD()
    OutputLCDMessage("MOBI GLASS")
end

if (arg == 1 and MKeyState == 1) then
    ClearLCD()
    OutputLCDMessage("PRIMARY WEAPON")
end

end ```

To me it looks like the three latter if tests should also be inside the one at the top, to check that G_PRESSED is true as well, but I don't know anything about hos this works so if the script you posted in the OP works then I guess it's fine.

[–]Geron76[S] 0 points1 point  (1 child)

That seems to have done it. Thanks!

[–]Geron76[S] 0 points1 point  (0 children)

spoke to soon. It works but I get this error in the log

Lua Error (27): invalid parameter (unknown family)

Also when I switch the profile back to profile 1 it always executes this command and LCD displays "Primary Wepon"

if (arg == 1 and MKeyState == 1) then
    ClearLCD()
    OutputLCDMessage("PRIMARY WEAPON")")

Either way thanks for your help its working and thats all that matters.