|username||The default user name|
|password||The default password|
This function opens a window that asks the user to input a
username and password. These arguments can be set as an empty
string or you can store previously entered values to use if you
wish. This is an asynchronous function, and as such GameMaker:
Studio 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 input the details and pressed the "Okay"
button, an asynchronous User Interaction 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 two keys, "username" and "password", with the corresponding user input stored in each. As it is a ds_map that has been created, this can then be used, for example, by the json_encode function ready to be sent to a server or written to a file on the chosen device.
It is worth noting that this function will return an index number for the ds_map created which can then be checked in the corresponding event so that you can "target" a specific ds_map should you be expecting more than one async map to be returned (perhaps from some other function). Outside of the asynchronous events, the async_load ds_map will return an "id" value of -1.
The create event (for example) of the object that is controlling the login of our user would have the following code:
u = ini_read_string("User","0","");
p = ini_read_string("User","1","");
login = get_login_async(u,p);
The above code opens an ini file (or creates one if it doesn't
exist) and gets the name and password stored in that file. If they
do not exist, then the default of an empty string ("") is returned.
These values are then used in get_login_async() to ask the
user for their username and password details, with the request
index being stored in the variable "login". Note that while waiting
for the user to give the necessary information the game and its
events will continue to run as normal.
Now that the asynchronous code has been fired off, we need to check for the return value in the asynchronous event for Dialogs in the following way:
if ds_map_find_value(async_load, "id") == login
u = ds_map_find_value(async_load, "username");
p = ds_map_find_value(async_load, "password");
The above code checks the "id" key of the async_load ds_map and if it holds the same value as that stored in the "login" variable, the map details are then read into the corresponding variables which you can then store or use to check against database values etc...