• 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!

Need some string help

J

Joey

Guest
good evening everyone, i am working on a personal project, a unique calculator for a gaming work place that is needed and i was told to help with it (Game maker is amazing) lol the software is completed, however there is just this ONE thing I don't like.

the strings come out as 123456789

when i would like them to look like 123,456,789

i used the String&thausand extension but it did not worm.

i was looking into string_format function but i would like to hear from the pros as to hoh to use it correctly.

any ideas? many many many thanks :)
 
J

Joey

Guest
It doesn't seem to be any function that can do that directly. You can add this script to your account and import it into your project:

https://marketplace.yoyogames.com/assets/155/string-thousands

It's a simple script that, literally, inserts the commas each 3 chars in your string.
yeah i tried that, but it did not work for me :/ i did everything exactly like it mentios. just on a side note

string_format is useless right? like to set it up is not worth it? i genuinely jaha no idea on that

ive been using real() and string() but it only adds 1 comma

thank you for you help :)
 

Sergio

Member
Why didn't it work? I've just tried and it works fine on last version of GMS2

writing this:
Code:
show_debug_message(string_thousands_scripts(20000000));
I have this in the output:
Code:
20,000,000
How are you trying to use it and what happens when you do?


According to the manual, string_format doesn't do what you want, it only sets the number of decimals and positions to be filled with 0 or spaces before the number.
 
J

Joey

Guest
it just wont show any digits, and it loops to a version error, which is odd because i have the latest from the market :(

what version do you have?

and thank you foe your time :)
 

Sergio

Member
My GM version is 2.1.3.273. The script only has one version.

Anyway, you can do it by yourself, new script and paste this code

Code:
/// @description string_thousands(real)
/// @function string_thousands
/// @param real
///Returns argument0 as a string with commas at every thousand digit
///eg 1234567890 becomes 1,234,567,890
///Created by Andrew McCluskey

var str,stl,rtn,place;

str=string(floor(real(argument0))) //String to be passed
stl=string_length(str) //Char length of that string
rtn="" //What to return (ignored if string is under four digits long)

if stl<=3
{
    return str;
}

else
{
    place=((stl-1) mod 3)+1;
   
    rtn+=string_copy(str,1,place)
   
    while(place<string_length(str))
    {
        rtn+=","
        rtn+=string_copy(str,place+1,3)
        place+=3
    }
   
    return rtn;
}
if this still not working, please, copy here how you are doing the call, and the output error you are having.
 
J

Joey

Guest
okay i just tried it. it should work but still gives me a error message, just to be clear, his goes in the Step event, correct?

thank you-
 
J

Joey

Guest
sorry im so stupid for this, i know its something super simple for you to explain but injust cant express it xD
 
J

Joey

Guest
My GM version is 2.1.3.273. The script only has one version.

Anyway, you can do it by yourself, new script and paste this code

Code:
/// @description string_thousands(real)
/// @function string_thousands
/// @param real
///Returns argument0 as a string with commas at every thousand digit
///eg 1234567890 becomes 1,234,567,890
///Created by Andrew McCluskey

var str,stl,rtn,place;

str=string(floor(real(argument0))) //String to be passed
stl=string_length(str) //Char length of that string
rtn="" //What to return (ignored if string is under four digits long)

if stl<=3
{
    return str;
}

else
{
    place=((stl-1) mod 3)+1;
  
    rtn+=string_copy(str,1,place)
  
    while(place<string_length(str))
    {
        rtn+=","
        rtn+=string_copy(str,place+1,3)
        place+=3
    }
  
    return rtn;
}
if this still not working, please, copy here how you are doing the call, and the output error you are having.
okay so i made it a script! it works fine on the debuger but womt show commas, im so close i can smell it lol
 
Top