Legacy GM [SOLVED] How do I give and receive a number? (get_string_async)

Dr_Nomz

Member
I tried using get_string_async to return a variable but it wouldn't work, it would just throw an error about a map not existing even though the manual says that's how it works.

Code:
msg = get_string_async("What's your name?","Anon");


The above will show a message requesting that the user input a string and press "Okay". The function id is stored in the variable "msg" and will be used in the asynchronous Dialogs event as shown below:

var i_d = ds_map_find_value(async_load, "id");
 if i_d == msg
    {
    if ds_map_find_value(async_load, "status")
       {
       if ds_map_find_value(async_load, "result") != ""
          {
          global.Name = ds_map_find_value(async_load, "result");
          }
       }
    }
And my code looked something like this:
Code:
if(point_in_rectangle(mouse_x,mouse_y,xx+50,yy+50,xx+200,yy+200)){
  draw_set_color(rectangle_color);
  draw_rectangle(xx+50,yy+50,xx+200,yy+200,false);
  if(mouse_check_button_pressed(mb_left)){
    msg = get_string_async("Enter page number.","1");
    var i_d = ds_map_find_value(async_load, "id");
    if i_d == msg{
      if ds_map_find_value(async_load, "status"){
        if ds_map_find_value(async_load, "result") != ""  {
          page = ds_map_find_value(async_load, "result");
          }
       }
    }
  }
}
Basically what I want is for it to take the player's input (a number) and return that value, making the local value of "page" equal to whatever the string was. Also could I make it ONLY accept numbers? That would be great. Especially if I could only have it accept numbers to a certain point, so it doesn't go over or under the page limit.
 

Homunculus

Member
get_string_async, as the name suggests, is an asynchronous function, meaning that your game does not stop and wait while the user inputs the number. This in turn means that it can't be used in a sequential routine like you did in your code, you'll need to rely on the appropriate async event instead.

Read about async events in the manual, it provides a few clear examples.
 

Dr_Nomz

Member
Okay but then where would I put that? It doesn't say where code like this should go. (End Step, Draw, other?)
 

FrostyCat

Member
Okay but then where would I put that? It doesn't say where code like this should go. (End Step, Draw, other?)
Sometimes I can't help but wonder if you're an act this whole time and ignoring/misreading written instructions on purpose just to troll us. The Manual entry clearly indicates which event each piece goes in, particularly the piece that checks async_load:
The Manual entry on get_integer_async() said:
The function id is stored in the variable "msg" and will be used in the asynchronous Dialogs event as shown below:
Code:
var i_d = ds_map_find_value(async_load, "id");
if i_d == msg
   {
   if ds_map_find_value(async_load, "status")
      {
      global.Age = ds_map_find_value(async_load, "value");
      }
   }
Do as it says and put the part checking async_load in the Async - Dialog event, not in the Step event or the Draw event.
 

Dr_Nomz

Member
Damn, didn't notice that was an option when selecting events in an object, sorry about that. :/

Thanks for the help again. And no, I'm just blind. >_<
 
Top