[SOLVED] Need Help With Script Running More Than Once

S

sjschindler

Guest
Hello, I am relatively new to gamemaker, and I was trying to make a dialogue system where if you press a button (E in this case), you would draw both a text box and text which displays dialogue unique to the person. That I can do. My problem lies with when I press E /while/ the dialogue is still displaying.
For example, if I had a message that was to display this:
"Hello!"
"How are you?"
"That's wonderful!"
You would press Z to advance the dialogue to the next section(Press Z to go from "Hello!" to "How are you?".
However, if I were to press E while the dialogue was currently displaying "How are you?", the dialogue would reset itself.
What I am looking for is a way to prevent the E key from doing anything while this dialogue plays so that if someone were to press E again accidentally, it wouldn't just replay the script.

Here is what I have so far:

In obj_player:

Step Event:

if (distance_to_object(obj_thanos) < (32) && keyboard_check(ord("E"))) //obj_thanos is the name of the character I wish to interact with
{
scr_text("",0.5,488,430) //Script that runs both my dialogue and text box, which work perfectly fine
}

Any help would be appreciated!
 

Weird Dragon

Wizard
GMC Elder
You can use a variable. As long as the value of the variable is 0 you can run the script, as soon you press "E" and thereby run the script the variable is set to 1 so that you can not repeat the script. Once you are finished the value can be set back to 0 if you want to be able to run it again.
 
S

sjschindler

Guest
Do you have any way you can show me how that would be executed in code? I know about variables, but I'm a little confused as to where I would implement the variables to equal 1 and 0.
 
W

wantafanta

Guest
This is an example of preventing the "e" key being pressed for "3 seconds after it was pressed."
You could also just remove the "condition" after the script has played out completely.
Remember that the variable "wait_for_dialogue_to_end" would have to be declared in the create event prior to executing this code in a step event.

Code:
// Count down until key can be pressed
if (wait_for_dialogue_to_end > 0) { wait_for_dialogue_to_end -= 1 }

// If "e" is pressed after countdown is complete, it can be reset
if (wait_for_dialogue_to_end <= 0)
         {
         if keyboard_check(ord('e'))
                  {
                  if (distance_to_object(obj_thanos) < 32)
                           {
                           wait_for_dialogue_to_end = 3 * room_speed;
                           scr_text("",0.5,488,430);
                           }
                  }
         }
 

Weird Dragon

Wizard
GMC Elder
Do you have any way you can show me how that would be executed in code? I know about variables, but I'm a little confused as to where I would implement the variables to equal 1 and 0.
Something like this:

Create Event:
Code:
my_variable = 0;
Then include a variable check in your code in the step event which means I have simply copied your code and added the variable check.
Step Event:
Code:
if ((distance_to_object(obj_thanos) < 32) && keyboard_check(ord("E")) && (my_variable == 0 )) //obj_thanos is the name of the character I wish to interact with
    {
        my_variable = 1;
        scr_text("",0.5,488,430) //Script that runs both my dialogue and text box, which work perfectly fine
    }
That way your script will only be executed once. It can not be run again until you set "my_variable" back to 0.
 
S

sjschindler

Guest
Thank you, this problem was fixed and now I can progress with this portion of the game. Thanks!
 
Top