bcirno Posted October 27, 2016 Share Posted October 27, 2016 Hello i have code in gamemode section: ShowMessage xxxMenu Set SubButton to GetButtonPressed PrintC "SubButton = %g" SubButton any tips why it's always return -1 regardless menu option which i pressed? message is existsdialog is shown in game Link to comment Share on other sites More sharing options...
Ladez Posted October 27, 2016 Share Posted October 27, 2016 Because you have everything running simultaneously, GetButtonPressed is called before any button can actually be pressed, resulting in the default value of -1. You need some conditionals to differentiate showing the message and getting the button, preventing them from running in the same frame (and the message from showing every frame.) Here is an example: if message_state == 1 ; It's time to show a message, but don't check for a button press yet showMessage xxxMenu set message_state to 2 ; Start checking for button presses next frame elseif message_state == 2 set sub_button to getButtonPressed if sub_button != -1 ; If sub_button contains a non-default value, a button was pressed printC "%g" sub_button set message_state to 0 ; No need to check for button presses anymore endif endif Set message_state variable to 1 from somewhere when you want to show the message. Link to comment Share on other sites More sharing options...
bcirno Posted October 27, 2016 Author Share Posted October 27, 2016 (edited) oh i got it, i see in console, first time when menu activated it's returns -1 (probably before i pressed anything)but then it's show proper number. my mistake was about assumption that script is waiting for result before doing anything else. thx for answer anyway :smile: Edited October 27, 2016 by bcirno Link to comment Share on other sites More sharing options...
bcirno Posted October 27, 2016 Author Share Posted October 27, 2016 (edited) can i ask something more? is it possible situation when few script copies running at same time? It's "quest script".if they do, are variables inside "if" statement have their own scope? or it's shared like variables before "begin" sections? i am talking about : ... SHORT var1 ... BEGIN gamemode .... if something SHORT var2 ..... endif .... END Edited October 27, 2016 by bcirno Link to comment Share on other sites More sharing options...
PushTheWinButton Posted October 27, 2016 Share Posted October 27, 2016 GetButtonPressed also works in MenuMode 1001 in Fallout 3 and NV, just FYI. Link to comment Share on other sites More sharing options...
Recommended Posts