get_integer_async

This function opens a window and displays message as well as a space for the user to input a value (which will contain the supplied default value to start with). This is an asynchronous function, and as such GameMaker does not block the device it is being run on while waiting for an answer, but rather keeps on running events as normal. Once the user has typed out their string and pressed the "Okay" button, an asynchronous Dialog event is triggered which, for the duration of that event only, will have a DS map stored in the variable async_load.

This map will contain the three keys, "id", "status", and "value". "id" is the value that was returned by the function when called, the "status" will be either true for the "Okay" button being pressed, or false if the message was canceled (where applicable as not all target platforms permit messages to be canceled). Finally "value" will return the integer that the user input as a string (an empty string "" will be returned if no input was given).

NOTE This function is for debugging and testing use only and should not be used in released games. For that purpose you should create a custom user interface to receive input from players so that you have complete control over how the dialogs look and behave.

 

Syntax:

get_integer_async(string, default);

ArgumentTypeDescription
stringStringThe message to show in the dialog.
defaultRealThe default value.

 

Returns:

Async Request ID

 

Extended Example:

The left mouse press event (for example) of the object that is showing the message would have the following code:

msg = get_integer_async("How old are you?", 0);

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"))
    {
        global.Age = ds_map_find_value(async_load, "value");
    }
}

The above code checks the "id" key of the returned DS Map against the value stored in the variable "msg". If they are the same, it then checks to see if "Okay" was pressed (rather than the window being closed/cancelled) and if it returns true it then sets a global variable from the integer returned.