get_string_async help

F

FeNniX

Guest
I wanted to retrieve user input and check it:

code = get_string("enter secret code","");
if (code="1234") do this

This works on pc but not on android. It says I should use get_string_async
How can I achieve same result with get_string_async like I would with above code?

I don't really understood from gamemaker documentation, so direct answer would be helpful.
 
I dunno how to explain it better than the docs. Basically, you call the async function when you want the input popup to happen (so on left click or something, which would be a tap on android) and store it in a variable (the docs use msg as the variable to store it in). Then you have the code in the docs inside the Async - Dialogue event:
Code:
var i_d = ds_map_find_value(async_load, "id");
if i_d == msg // Make sure that here you are using whatever variable you stored the result of string_get_async in instead of msg (unless you actually used msg to store it like the docs have)
   {
   if ds_map_find_value(async_load, "status") // Here it checks to see if the user has clicked OK, if they have, this returns true and the rest of the statement executes, if they clicked cancel, it returns false and the if dies here
      {
      if ds_map_find_value(async_load, "result") != "" // This checks to see if they've entered nothing, if they haven't entered nothing, the if continues...
         {
         global.Name = ds_map_find_value(async_load, "result"); // Finally, it stores the string the user typed into a variable...The docs use global.Name as you can see here, but you can store the returned string in any variable you want...This is the golden goose that actually returns the users input
         }
      }
   }
(if the above code is just confusing because you've never used maps and don't understand how they work, honestly take the time to figure them out. Use a trash test project to test out creating, setting and pulling values from a ds_map. They are -super- useful and once you get the hang of them you'll have a very versatile tool in your coding toolbox).
 
Last edited:
Top