SOLVED Highscore only displays Numbers as names

R

Rugensoft

Guest
Hey Guys,
iam new to the forum and kinda new to GM developing.

I often use the Forum when i need help by searching up some questions of mine and always find an answser... but not this time :D

My Problem is that the build in draw_highscore only shows a number as the playername, even when i get and write the player name to it by:

global.name = get_string_async("Please enter your name :",""); //input works (dev. for android)
highscore_add(global.name,score); //global var is set in first room as global.name = "";

I havent written the highscore to a file, yet.
Is it cause of that?

I hope you can help me, ive been racking my brain on this since a couple of days now.

If you need futher information, please tell me that.

Thanks Guys
Rugensoft
 

TsukaYuriko

☄️
Forum Staff
Moderator
You are using an asynchronous function (hence the async in the name), which means your code continues running after you call this function rather than waiting for it to complete. global.name will therefore still be an empty string by the time the next line executes, unless you have otherworldly typing speed and can enter and confirm your name in less than a few nanoseconds. ;)

The way you are using get_string_async is also not valid; the value returned by the function is not the entered value, but the handle to be used to identify the asynchronous callback in the Async event. Check the manual entry of get_string_async for a valid usage example that involves the Async event.

Move the adding of the highscore to the Async event where you retrieve the entered value, as it is only at this point that global.name can have been assigned the correct value.
 

curato

Member
it looks like you somewhat looked at the manual with variable name. The trick is you have to make the call to get_string_async then you can't process it on the next like you need an asynchronous dialog event to put the handling of the results. As mentioned, there is a nice example in the manual.
 
R

Rugensoft

Guest
Thanks for the quick response.

I think i got it now... i need to grab the information from the async event, it will not store itself.

I will test it and give feedback, if i got it working.

Thanks

Well ok, i now tested it.

I now have the Problem that the error occurs: "Data Structure with index does not exist" in the Line: var tempid = ds_map_find_value(async_load, "id");

It cant find "id" in the ds_map ?

I dunno whats wrong there.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
It cant find "id" in the ds_map ?
No the error means it can't find the DS map you are referencing. In this case, that can only happen if you are referencing the DS map "async_load" outside of an async event.

What you need to do is:

1) Call the get_string_async function, and store the ID of the call in a variable.
2) Create a DIALOG Async event
3) In this event, check the async_load "id" and see if ti matches the variable that stored the call ID.
4) If it does, then check the "status" in the async_load map
5) If the "status" is true, then assign the "result" key from the async_load map to your highscore

Basically, the code here is exactly what you want: https://docs2.yoyogames.com/index.h.../asynchronous functions/get_string_async.html
 
R

Rugensoft

Guest
No the error means it can't find the DS map you are referencing. In this case, that can only happen if you are referencing the DS map "async_load" outside of an async event.
Thanks for the quick answer.

I call the input in one obj by:

GML:
if lives = 0 {
    msg = get_string_async("Please enter your name :","Anon");
    room_goto(gameover);
    };
and try getting the input written to global.name in other room and obj.

Code:
var tempid = ds_map_find_value(async_load, "id");
    if tempid == 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");
         }
      }
   }

highscore_add(global.name,score);
not working tho...

Edit:
I also tried with global.msg
 
Last edited by a moderator:
R

Rugensoft

Guest
Pretty sure your async code needs to be in the same room and same object to work.
also done that..not working:
GML:
global.msg = get_string_async("Please enter your name :","Anon");
var tempid = ds_map_find_value(async_load, "id");
    if tempid == global.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");
         }
      }
   };

highscore_add(global.name,score
 
The get_string_async() command should still be in a different event, e.g. Step Event. And don't change rooms straight after, or you will not get the async event triggering in time.

You could change rooms after you have saved the string in the dialog async event.
 
R

Rugensoft

Guest
I just dont understand it.
I allways getting the Error Data structure with index does not exist. on this Line :
var tempid = ds_map_find_value(async_load, "id");

I tryed in same Objekt, same room, step, create and so on.
I dont change rooms now, i tried triggering it differend, i read the manual for dialogues event...

I dont know what iam doing wrong. :(
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Do you even have an Async Dialog Event? You don't mention it at all and your code seems to indicate you don't.
 
R

Rugensoft

Guest
Do you even have an Async Dialog Event? You don't mention it at all and your code seems to indicate you don't.
Iam not shure what you mean by that.

You mean putting the "msg = get_string_async("What's your name?","Anon");" in a stepevent?
 

FrostyCat

Redemption Seeker
Iam not shure what you mean by that.

You mean putting the "msg = get_string_async("What's your name?","Anon");" in a stepevent?
This has gone on enough. 4 separate responders thus far have told you to use the Dialog Async event, and here you are still asking whether the lines containing async_load belongs in the Step event.

For the last time, this is an Asynchronous event:

Go to your object editor, open the event selector, select Asynchronous > Async - Dialog as shown above, and put all the code involving async_load or are dependent on finished get_string_async() input in there. Here's an example:

Create:
GML:
msg = -1;
Step:
GML:
if (lives == 0 && msg < 0) {
    msg = get_string_async("Please enter your name :", "Anon");
}
Async - Dialog:
GML:
if (async_load[? "id"] == msg) {
    if (async_load[? "status"] && async_load[? "result"] != "") {
        highscore_add(async_load[? "result"], score);
        room_goto(gameover);
    } else {
        msg = -1;
    }
}
 
R

Rugensoft

Guest
This has gone on enough. 4 separate responders thus far have told you to use the Dialog Async event, and here you are still asking whether the lines containing async_load belongs in the Step event.
I will just thank you, cause now i got it and ignore the rude statment.

By the way.. no other of them told it to me like that.
 
Top