help with get_string_async

  • Thread starter skullandbonesband
  • Start date
S

skullandbonesband

Guest
Hello.
I need to input a name for the record table in my game.
All was going fine, I used get_string to enter and it was ok on pc.
But when I compiled to android and tested it, it became ugly because it says that the function is deprecated (why don't shut it and let us use it?... ).
Anyway, I been trying to use get_string_async but it returns a number and not the name I entered.

Can you help me with a piece of code to get the name of the player with get_string_async and retrieve this string whatever it went, simply?

The "explanation" below didn't solve it, I didn't get it, is too complicated for my beginner level of understanding (but I was good in basic and pascal in the 80s...).
ARTICLE LINK:
Example
in the var name, I will store the string inputted and later add to var global.name which stores the name of the player with a current high score which is used to exhibit in the start screen (and later will be integrated into an array soon I understand how).

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

How I take out the string inputted from the system?

Thank you in advance.
Happy new year!
 
S

skullandbonesband

Guest
Do it like the Manual entry for get_string_async says --- save the handle, check it in the Asynchronous Dialog event later.

Create:
GML:
ih_name = get_string_async("What's your name?", "Anon");
Async - Dialog:
GML:
if (async_load[? "id"] == ih_name) {
    if (async_load[? "status"]) {
        global.name = async_load[? "result"];
    } else {
        global.name = "Anon";
    }
}
Ok, now I get this error message :
"Data structure with index does not exist.
at gml_Object_obj_restart_game_Create_0 (line 76) - if (async_load[? "id"] == ih_name) {
"

How I create the data structure?
 
S

skullandbonesband

Guest
I told you to use the Async - Dialog event for the second piece of code, not the Create event. async_load is automatically available in Asynchronous events.
Can you or someone else elaborate on it?
I don't understand what you are saying, I copied the code you posted there adapting to my variables, and that error came. Gamemaker studio last version.
 

FrostyCat

Redemption Seeker
This is the third time I'm saying this: Use the Async - Dialog event for part of the code involving async_load.

Cut this code out of your Create Event. It does not belong there.
GML:
if (async_load[? "id"] == ih_name) {
    if (async_load[? "status"]) {
        global.name = async_load[? "result"];
    } else {
        global.name = "Anon";
    }
}
Now go to the event selector, select Asynchronous > Async - Dialog, and paste the code there.

This is as simple as I can make it. Take it or leave it.
 

Yal

🐧 *penguin noises*
GMC Elder
if (async_load[? "id"] == ih_name)
So the whole idea with asynchronous functions is that you don't get the result now, you get it later. That's what "async" means. They don't return the result like the old get_ functions.

You want to always have the following procedure when using async functions:
  1. Run the function, creating a dialogue box. Save the handle for later.
  2. Enter a state where you wait for the response. (This is the easiest if every control object that runs an async function is a state machine). This state should disable all other interactions, so e.g. pressing Z when typing in a name won't make the character jump.
  3. In the Async Event, you check the response. If you got a valid response to the message you sent off (the handle can be used to identify it), store it in variables and return to the normal control flow, else do error handling (e.g. if the player cancelled the dialog, you don't want to overwrite the thing they were supposed to fill in).
 
S

skullandbonesband

Guest
So the whole idea with asynchronous functions is that you don't get the result now, you get it later. That's what "async" means. They don't return the result like the old get_ functions.

You want to always have the following procedure when using async functions:
  1. Run the function, creating a dialogue box. Save the handle for later.
  2. Enter a state where you wait for the response. (This is the easiest if every control object that runs an async function is a state machine). This state should disable all other interactions, so e.g. pressing Z when typing in a name won't make the character jump.
  3. In the Async Event, you check the response. If you got a valid response to the message you sent off (the handle can be used to identify it), store it in variables and return to the normal control flow, else do error handling (e.g. if the player cancelled the dialog, you don't want to overwrite the thing they were supposed to fill in).
Thank you.
 
S

skullandbonesband

Guest
This is the third time I'm saying this: Use the Async - Dialog event for part of the code involving async_load.

Cut this code out of your Create Event. It does not belong there.
GML:
if (async_load[? "id"] == ih_name) {
    if (async_load[? "status"]) {
        global.name = async_load[? "result"];
    } else {
        global.name = "Anon";
    }
}
Now go to the event selector, select Asynchronous > Async - Dialog, and paste the code there.

This is as simple as I can make it. Take it or leave it.
I'm not used to how gamemaker 2 works and the documentation is not that clear. I seen manuals explain better than the official manual for other stuff. But thank you. Its a hobby to me, not a way of living, so I use the little amount of time between work and life to learn it.
 
Top