Legacy GM From string to real

zendraw

Member
Hi,

so im trying to write a text !@#F!@E! and turn that text into real numbers like this
!=5
@=6
#=120
F=12
etc.

this idea came from the fact that the characters in the font are numbers and what i tryed is
stats=chr(5)+chr(1)+chr(12)+chr(42);
and then im not sure how to turn those characters into real values. + for some reason chr(0-4) are non existent or return 0
this is the code for converting which doesnt work properly
Code:
str=string(chr(0))+string(chr(6))+string(chr(2))+string(chr(8))+string(chr(9));
Code:
repeat (string_length(str)) {st[i]=string_byte_at(str, i); i++};
basically what im tryin to achive is to avoid an array of variables and store those variables in single string.
 

zendraw

Member
i mean not to simply switch from one to another, but to use the numbers of the characters, for instance 'F'is a certain number, and i want to use that number, but instead of havin an array of numbers, simply save the characters that are that number in a string.
 

zendraw

Member
okay so i think i solved it myself.
what i found is chr(0)+chr(random)+chr(random); for some reason doesnt work becouse of the 0 infront, it like erases every next chr(). but if i put 1or a bigger value, it works properly
this is the converting part
Code:
str=chr(1+irandom(1023))+chr(1+irandom(1023))+chr(1+irandom(1023))+chr(1+irandom(1023));
Code:
repeat (string_length(str)) {st[i]=ord(string_copy(str, i, 1))-1; i++};
basically you create the string with chr(), and convert it to numbers with ord();
and it works fine from what ive tested
i will leave the topic unsolved
 

sylvain_l

Member
source of problem is surely that chr(0) is special NUL control char in unicode (and also ascii). (often used as end of string delimiter )
 

zendraw

Member
its more straightforeward and convinient for me. plus when saved its like encrypted and people wont be so eager to modify the save files.
 
it will be easier to write and read from a buffer than to parse a string. Plus it will be somewhat faster. Also, when you save a buffer it will be binary, not human readable. You can also use any of the data structures to pretty much the same effect.
 

zendraw

Member
can you give an example? i have poor knowledge of buffers. right now with this way all i do to set as meny as i want stats is add a +chr(n) to the string str=other.str. to pass it around. which is super convinient.
 
Top