• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Problem converting from string to real for seeds

Antikore

Member
I'm trying to make a minecraft-like seed system where you can type some kind of text string and it will be converted to real and afterwards the seed will be set. However, seems I'm doing something wrong with the converter. I didn't follow any tutorials so my code might be completely stupid, I'm aware of that.

The final result is always getting 48 as final seed number, that represents 0 on ascii

This is the converting code in async dialog event
GML:
txt = "";
for (i = 0; i < string_length(input); i++) {
  txt = string(txt)+string(string_ord_at(input, i+1));
}
global.seed = real(txt);
room_goto(rm_playscene);
This is the input code:
GML:
txt = "1";
input = get_string_async("Set a game id (Your friend should use the same id or you may have errors)", "TaterIsAPotato");
I'm using Windows 10
GameMaker: Studio v1.4.1804 (Standard Edition)

Any help will be apreciated :D
 

chamaeleon

Member
I'm trying to make a minecraft-like seed system where you can type some kind of text string and it will be converted to real and afterwards the seed will be set. However, seems I'm doing something wrong with the converter. I didn't follow any tutorials so my code might be completely stupid, I'm aware of that.

The final result is always getting 48 as final seed number, that represents 0 on ascii

This is the converting code in async dialog event
GML:
txt = "";
for (i = 0; i < string_length(input); i++) {
  txt = string(txt)+string(string_ord_at(input, i+1));
}
global.seed = real(txt);
room_goto(rm_playscene);
This is the input code:
GML:
txt = "1";
input = get_string_async("Set a game id (Your friend should use the same id or you may have errors)", "TaterIsAPotato");
I'm using Windows 10
GameMaker: Studio v1.4.1804 (Standard Edition)

Any help will be apreciated :D
"input" does not contain the value typed into the box. get_string_async() returns an id that identifies the input box. You need to use the async_load ds_map in the async event to extract the actual value, when the event is run for this id. See the example for get_string_async() where msg is the id returned by the function and is used to determine whether the event fired for that particular message box.
 
Top