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 Studio 2 does not block the device it is being run on while waiting for 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).
参数 描述 字符串 The message to show in the dialog. default The default value.
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?",
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.