1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GM:S 1.4 From string to real

Discussion in 'Programming' started by zendraw, Apr 22, 2017.

  1. zendraw

    zendraw Member

    Joined:
    Jun 20, 2016
    Posts:
    1,376
    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.
     
  2. Bingdom

    Bingdom Googledom

    Joined:
    Jul 1, 2016
    Posts:
    1,680
    string_replace
     
  3. zendraw

    zendraw Member

    Joined:
    Jun 20, 2016
    Posts:
    1,376
    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.
     
  4. zendraw

    zendraw Member

    Joined:
    Jun 20, 2016
    Posts:
    1,376
    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
     
  5. sylvain_l

    sylvain_l Member

    Joined:
    Sep 18, 2016
    Posts:
    705
    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 )
     
  6. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    2,213
    would you mind if I asked, why? I'm thinking there might be a better solution than storing within a string.
     
  7. Mick

    Mick Member

    Joined:
    Jun 30, 2016
    Posts:
    726
    I second that, a buffer would be a cleaner solution if you need to save memory for some reason.
     
  8. zendraw

    zendraw Member

    Joined:
    Jun 20, 2016
    Posts:
    1,376
    its more straightforeward and convinient for me. plus when saved its like encrypted and people wont be so eager to modify the save files.
     
  9. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    2,213
    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.
     
  10. zendraw

    zendraw Member

    Joined:
    Jun 20, 2016
    Posts:
    1,376
    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice