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

string_digits removes decimal!

bsabiston

Member
so stupid! You can't get a floating point number from a string easily because it removes the decimal point between two digits.
 

CloseRange

Member
I mean this isn't quite a question more of a complaint but I'll assume you want a work around:
Code:
var newS = "";
for(var i=1; i<=string_length(string); i++) {
     var c = string_char_at(string, i);
     newS += string_digits(c);
     if(c == '.') newS += '.';
}
number = real(newS);
a lot more work than just using string_digits, but hey, beggars can't be choosers.

oh this also doesn't work if your string has periods in it that aren't meant to be part of the decimal. So if that's a problem you just need to add in a bit to check if the character's before and/or after the period are numbers.
It's not that hard (especially compared to other stuff that games require) if you need to do it a lot just package it into a script and you're done. Sure you can't 'easily' do it but nobody said programming was easy.
 
Top