ArrowFX Posted September 14, 2020 Share Posted September 14, 2020 Hello everyone, I am currently making a mod and everything was going great until recently, You see I need to use OnKeyDown but it doesn't seem to be working and I can't for the life of me figure out why. Please take a look at my code and tell me if you know why. Int godMode_KInt TAI_KInt TCL_KInt TM_KInt godModeKeyCodeInt TAIKeyInt TCLKeyInt TMKeyFunction RegisterForKey(Int KeyCode) Native/Code for things\ ElseIf (page == "Hotkeys") SetCursorFillMode(LEFT_TO_RIGHT) SetCursorPosition(0) AddHeaderOption("God Mode Hotkey") SetCursorPosition(2) godMode_K = AddKeyMapOption("God Mode Hotkey", godModeKeyCode) SetCursorPosition(1) AddHeaderOption("Toggle Collision Hotkey") SetCursorPosition(3) TCL_K = AddKeyMapOption("Toggle Collision Hotkey", TCLKey) SetCursorPosition(4) AddHeaderOption("Toggle AI Hotkey") SetCursorPosition(6) TAI_K = AddKeyMapOption("Toggle AI Hotkey", TAIKey) SetCursorPosition(5) AddHeaderOption("Toggle Menus Hotkey") SetCursorPosition(7) TM_K = AddKeyMapOption("Toggle Menus Hotkey", TMKey) Event OnOptionKeyMapChange(int option, int keyCode, string conflictControl, string conflictName) if(option == godMode_K) bool continue = True if(conflictControl != "") string msg if(conflictName != "") msg = "This key is already mapped to:\n\"" + conflictControl + "\"\n(" + conflictName + ")\n\nAre you sure you want to continue?" Else msg = "This key is already mapped to:\n\"" + conflictControl + "\"\n\nAre you sure you want to continue?" EndIf continue = ShowMessage(msg, true, "$Yes", "$No") EndIf if(continue) godModeKeyCode = keyCode SetKeyMapOptionValue(godMode_K, godModeKeyCode) EndIf ElseIf (option == TAI_K) bool continue = True if(conflictControl != "") string msg if(conflictName != "") msg = "This key is already mapped to:\n\"" + conflictControl + "\"\n(" + conflictName + ")\n\nAre you sure you want to continue?" Else msg = "This key is already mapped to:\n\"" + conflictControl + "\"\n\nAre you sure you want to continue?" EndIf continue = ShowMessage(msg, true, "$Yes", "$No") EndIf if(continue) TAIKey = keyCode SetKeyMapOptionValue(TAI_K, TAIKey) EndIf ElseIf (option == TCL_K) bool continue = True if(conflictControl != "") string msg if(conflictName != "") msg = "This key is already mapped to:\n\"" + conflictControl + "\"\n(" + conflictName + ")\n\nAre you sure you want to continue?" Else msg = "This key is already mapped to:\n\"" + conflictControl + "\"\n\nAre you sure you want to continue?" EndIf continue = ShowMessage(msg, true, "$Yes", "$No") EndIf if(continue) TCLKey = keyCode SetKeyMapOptionValue(TCL_K, TCLKey) EndIf ElseIf (option == TM_K) bool continue = True if(conflictControl != "") string msg if(conflictName != "") msg = "This key is already mapped to:\n\"" + conflictControl + "\"\n(" + conflictName + ")\n\nAre you sure you want to continue?" Else msg = "This key is already mapped to:\n\"" + conflictControl + "\"\n\nAre you sure you want to continue?" EndIf continue = ShowMessage(msg, true, "$Yes", "$No") EndIf if(continue) TMKey = keyCode SetKeyMapOptionValue(TM_K, TMKey) EndIf EndIf RegisterForKey(godModeKeyCode) RegisterForKey(TAIKey) RegisterForKey(TCLKey) RegisterForKey(TMKey)EndEventEvent OnKeyDown(Int KeyCode) If (keycode == godModeKeyCode) godmodeToggle = !godmodeToggle Debug.SetGodMode(godmodeToggle) EndIf If(keycode == TCLKey) debug.ToggleCollisions() EndIf If(keycode == TMKey) debug.ToggleMenus() EndIf If(keycode == TAIKey) debug.ToggleAI() EndIfEndEventstring function GetCustomControl(int keyCode) if (keyCode == godModeKeyCode) return "Toggles God Mode" else return "" EndIf if (keycode == TCLKey) return "Toggles Collision" else return "" EndIf If (keycode == TAIKey) return "Toggles AI" else return "" EndIf If (keycode == TMKey) return "Toggles Menus" else return "" endIfendFunction Link to comment Share on other sites More sharing options...
lofgren Posted September 14, 2020 Share Posted September 14, 2020 Why do you have Function RegisterForKey(Int KeyCode) Native in your script? Link to comment Share on other sites More sharing options...
ArrowFX Posted September 14, 2020 Author Share Posted September 14, 2020 Why do you have Function RegisterForKey(Int KeyCode) Native in your script?It doesn't work without it. At least when I remove it, it throws me errors. Link to comment Share on other sites More sharing options...
lofgren Posted September 14, 2020 Share Posted September 14, 2020 Well what kind of errors? There's no reason you should have to declare a native function in your script. Link to comment Share on other sites More sharing options...
ArrowFX Posted September 14, 2020 Author Share Posted September 14, 2020 Well what kind of errors? There's no reason you should have to declare a native function in your script.Error on line 1770: 'RegisterForKey' is not a function/eevent that exists in this scope Link to comment Share on other sites More sharing options...
lofgren Posted September 14, 2020 Share Posted September 14, 2020 Actually, looking more at your script, I see a number of odd things, but it's a bit hard to tell because you are using some nonstandard coding practices. (Which is fine! Just makes it a little harder for an outsider to parse.) Link to comment Share on other sites More sharing options...
lofgren Posted September 14, 2020 Share Posted September 14, 2020 Which line is 1770? Link to comment Share on other sites More sharing options...
ArrowFX Posted September 14, 2020 Author Share Posted September 14, 2020 RegisterForKey(godModeKeyCode) Link to comment Share on other sites More sharing options...
lofgren Posted September 14, 2020 Share Posted September 14, 2020 I don't see where you unregister for keys. That's going to be an issue. If you look at Form.psc, is RegisterForKey there? Link to comment Share on other sites More sharing options...
ArrowFX Posted September 14, 2020 Author Share Posted September 14, 2020 I don't see where you unregister for keys. That's going to be an issue. If you look at Form.psc, is RegisterForKey there?Well, guess that's the problem, Form.psc didn't have RegisterForKey in it Link to comment Share on other sites More sharing options...
Recommended Posts