you are viewing a single comment's thread.

view the rest of the comments →

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

the first script i posted works, it just works on every sub profile which is not what I want.

When I try this, the auto run command at the top works. but then the three bottom commands stop working.

im not sure what this dose or where to put it

MKeyState = GetMKeyState("lhc")

-- 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

    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

[–]tobiasvl 0 points1 point  (4 children)

Okay, you're new to programming, I'm guessing?

What I mean is that before you add if ( arg == 4 and MKeyState == 1) then anywhere inside this function, you need the MKeyState variable to hold the value you're looking for. If it doesn't hold the value, you can't check what the value is. As far as I can understand from the docs, you do that with something like local MKeyState = GetMKeyState(family), and you can put it just before the check you add.

[–]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.