. . . Posted June 6, 2016 Share Posted June 6, 2016 (edited) Hello, I just found out I have a big problem ! So I wanted to have multiple keyhandler actions so I had code like this before (in my character prefab) local function OnKeyPressed(inst, data) if data.inst == ThePlayer then if data.key == KEY_LEFTBRACKET then if TheWorld.ismastersim then BufferedAction(inst, inst, ACTIONS.SACRIFICE):Do() else SendRPCToServer(RPC.DoWidgetButtonAction, ACTIONS.SACRIFICE.code, inst, ACTIONS.SACRIFICE.mod_name) end end end end local function OnKeyPressed(inst, data) if data.inst == ThePlayer then if data.key == KEY_RIGHTBRACKET then if TheWorld.ismastersim then BufferedAction(inst, inst, ACTIONS.STEALTH):Do() else SendRPCToServer(RPC.DoWidgetButtonAction, ACTIONS.STEALTH.code, inst, ACTIONS.STEALTH.mod_name) end end end end but then I realized that the top action gets ignored when there's two of them ! So I tried doing something like this local function OnKeyPressed(inst, data) if data.inst == ThePlayer then if data.key == KEY_LEFTBRACKET then if TheWorld.ismastersim then BufferedAction(inst, inst, ACTIONS.SACRIFICE):Do() else SendRPCToServer(RPC.DoWidgetButtonAction, ACTIONS.SACRIFICE.code, inst, ACTIONS.SACRIFICE.mod_name) elseif data.key == KEY_RIGHTBRACKET then if TheWorld.ismastersim then BufferedAction(inst, inst, ACTIONS.STEALTH):Do() else SendRPCToServer(RPC.DoWidgetButtonAction, ACTIONS.STEALTH.code, inst, ACTIONS.STEALTH.mod_name) end end end end end but it just crashes the game instantly and doesn't give any errors, can someone please help because I really wanted to have multiple keyhandler actions for my character... It really would suck if I could only have one .... Any help would make me super happy !!! Edited June 6, 2016 by SuperDavid Link to comment Share on other sites More sharing options...
Aquaterion Posted June 6, 2016 Share Posted June 6, 2016 Put them both in 1 function, something like this: local function OnKeyPressed(inst, data) if data.inst == ThePlayer then if data.key == KEY_LEFTBRACKET then --code elseif data.key == KEY_RIGHTBRACKET then --other ocde end end end Link to comment Share on other sites More sharing options...
. . . Posted June 6, 2016 Author Share Posted June 6, 2016 8 hours ago, Aquaterion said: Put them both in 1 function, something like this: local function OnKeyPressed(inst, data) if data.inst == ThePlayer then if data.key == KEY_LEFTBRACKET then --code elseif data.key == KEY_RIGHTBRACKET then --other ocde end end end I did this local function OnKeyPressed(inst, data) if data.inst == ThePlayer then if data.key == KEY_LEFTBRACKET and TheWorld.ismastersim then BufferedAction(inst, inst, ACTIONS.SACRIFICE):Do() else --If I remove this the game doesn't instantly crash SendRPCToServer(RPC.DoWidgetButtonAction, ACTIONS.SACRIFICE.code, inst, ACTIONS.SACRIFICE.mod_name) elseif data.key == KEY_RIGHTBRACKET and TheWorld.ismastersim then BufferedAction(inst, inst, ACTIONS.STEALTH):Do() else --If I remove this the game doesn't instantly crash SendRPCToServer(RPC.DoWidgetButtonAction, ACTIONS.STEALTH.code, inst, ACTIONS.STEALTH.mod_name) end end end but the game instantly crashes unless I remove those two "else" and when I remove them the actions can't be triggered ... Thanks so much for your help Aquaterion !!! Link to comment Share on other sites More sharing options...
Aquaterion Posted June 6, 2016 Share Posted June 6, 2016 (edited) local function OnKeyPressed(inst, data) if data.inst == ThePlayer then if data.key == KEY_LEFTBRACKET then if TheWorld.ismastersim then BufferedAction(inst, inst, ACTIONS.SACRIFICE):Do() else SendRPCToServer(RPC.DoWidgetButtonAction, ACTIONS.SACRIFICE.code, inst, ACTIONS.SACRIFICE.mod_name) end elseif data.key == KEY_RIGHTBRACKET then if TheWorld.ismastersim then BufferedAction(inst, inst, ACTIONS.STEALTH):Do() else SendRPCToServer(RPC.DoWidgetButtonAction, ACTIONS.STEALTH.code, inst, ACTIONS.STEALTH.mod_name) end end end end Edited June 6, 2016 by Aquaterion Link to comment Share on other sites More sharing options...
. . . Posted June 6, 2016 Author Share Posted June 6, 2016 Thank you so much Aquaterion now I can have multiple keyhandler actions, thanks so, so, so much !!!!! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now