GMS 2 [SOLVED] How do you make a wait timer between each line of code?

R

Ryan Blaney

Guest
I am working on an RPG with a rhythm type battle system. It would be very useful if someone knew how to write a script that would add a wait timer between a line of code without unnecessary if statements.

For example: I want to be able to write something like this.

show_debug_message("Hello,");
wait(1);
show_debug_message("My name is...");
 

chamaeleon

Member
I am working on an RPG with a rhythm type battle system. It would be very useful if someone knew how to write a script that would add a wait timer between a line of code without unnecessary if statements.

For example: I want to be able to write something like this.

show_debug_message("Hello,");
wait(1);
show_debug_message("My name is...");
That's not how GMS2 works at all. Go back and study how to use events, in particular the step and alarm events. If you want time to pass, you let some number of steps run until the number of steps divided by room_speed equals the time in seconds you wish to "wait". You then utilize flags, time variables, if statements, etc., to determine whether something should happen during a particular step.
 
Last edited:
R

Ryan Blaney

Guest
That's not how GMS2 works at all. Go back and study how to use events, in particular the step and alarm events. If you want time to pass, you let some number of steps run until the number of steps divided by room_speed equals the time in seconds you wish to "wait". You then utilize flags, time variables, if statements, etc., to determine whether something should happen during a particular step.
I'm aware of how alarms work. It just gets redundant because I don't want to have to make thousands of alarms for one battle. I'm pretty sure I can do something like this though:

timer = 0;

show_debug_message("Hello,");
if (timer >= 30) {
show_debug_message("My name is...");
} else {
timer++;
}
 

Ludorverr

Member
Code:
//Create event
state_code = 0
wait = 0

//Step event
if wait = 0 {
      state_code += 1
      switch state_code {
            case 1: show_debug_message("Hello,") break
            case 2: wait = 60 break
            case 3: show_debug_message("My name is...") break
      }
} else {
      wait -= 1
}

Alternative if you want a cleaner looking step event:
Code:
//Create event
state_code = 0
wait = 0

//Step event
switch wait_script() {
      case 1: show_debug_message("Hello,") break
      case 2: wait = 60 break
      case 3: show_debug_message("My name is...") break
}

//Put this in a script called "wait_script":
if wait > 0 {
      wait -= 1
      return -1
} else {
      state_code += 1
      return state_code
}
 
Last edited:

chamaeleon

Member
I'm aware of how alarms work. It just gets redundant because I don't want to have to make thousands of alarms for one battle.
What you probably want to look at implementing is some kind of event system that allows to control the sequence of events at a higher level than hard-coding it.
 

TheouAegis

Member
You could have a state machine where you reserve every odd state for the timer.

Code:
if state & 1 {
   timer--;
   if !timer state++;
}
else switch state {
   case 0: do something; state++; break;
   case 2: do something; state++; break;
   case 4: do something; state+=2; break; //skip timer part
   case 6: do something; state = 1; break; 
}
 
R

Ryan Blaney

Guest
Code:
//Create event
state_code = 0
wait = 0

//Step event
if wait = 0 {
      state_code += 1
      switch state_code {
            case 1: show_debug_message("Hello,") break
            case 2: wait = 60 break
            case 3: show_debug_message("My name is...") break
      }
} else {
      wait -= 1
}

Alternative if you want a cleaner looking step event:
Code:
//Create event
state_code = 0
wait = 0

//Step event
switch wait_script() {
      case 1: show_debug_message("Hello,") break
      case 2: wait = 60 break
      case 3: show_debug_message("My name is...") break
}

//Put this in a script called "wait_script":
if wait > 0 {
      wait -= 1
      return -1
} else {
      state_code += 1
      return state_code
}
Thanks. It works perfectly.
 
Top