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

Legacy GM Problem populating a list in a for loop

W

Waylander

Guest
I am trying to convert C# code from an algorithm from a program I made some time ago into the Game Maker scripting language and am coming up against a few obstacles. I think I have them all hammered out except for this part which is causing some strange output.

For whatever reason, this code below isn't working correctly. When I input a number, say 50, it coverts it to a string "50" and then it is supposed to put each character from that string into a separate string and add it to the list "strNumbers" as two separate entries. So "strNumbers" SHOULD end up with "5" and "0" as its list items. But for whatever reason it is giving me "5" and "5" as the list items and I can't figure out why.

Of course I'm still getting used to the GM scripting language LOL. Any help would be greatly appreciated :).

var strNumber = string(number);

var strNumbers = ds_list_create();

for (var i = 0; i < string_length(strNumber); i++)
{
var tempChar = string_char_at(strNumber, i);
ds_list_add(strNumbers, tempChar);
}
 

FrostyCat

Redemption Seeker
Here's the quirk with GML strings: It, and it alone, is one-indexed.
Code:
for (var i = 1; i <= string_length(strNumber); i++) {
  ds_list_add(strNumbers, string_char_at(strNumber, i));
}
 
Top