1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

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

Discussion in 'Programming' started by Dr_Nomz, May 27, 2019.

  1. Dr_Nomz

    Dr_Nomz Member

    Joined:
    Oct 31, 2016
    Posts:
    581
    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.
     
  2. Catan

    Catan Member

    Joined:
    Jun 20, 2016
    Posts:
    651
    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.
     
  3. Dr_Nomz

    Dr_Nomz Member

    Joined:
    Oct 31, 2016
    Posts:
    581
    Okay but then where would I put that? It doesn't say where code like this should go. (End Step, Draw, other?)
     
  4. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,327
    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:
    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.
     
  5. Dr_Nomz

    Dr_Nomz Member

    Joined:
    Oct 31, 2016
    Posts:
    581
    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. >_<
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice