Jump to content

GetButtonPressed problem


bcirno

Recommended Posts

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 exists

dialog is shown in game

 

Link to comment
Share on other sites

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

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 by bcirno
Link to comment
Share on other sites

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 by bcirno
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...