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

GameMaker Change image_index based on array position

So I have a basic dialog system. set like...

string[0] = "Hi world";
string[1] = "How are you?";
string[2] = "I am well";

How do I check when "string" is at the position of "string[2]" so I can change a specific sprite index?
I've tried array_equals and that just keeps telling me its not an array. The help in GMS is not helpful on this and I have googled my arse off.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
You need to keep track of the index in some way using a variable, then check if the variable is equal to a value (in this case 2). So something like:

GML:
// CREATE EVENT
pos = 0;
str[0] = "Hi world";
str[1] = "How are you?";
str[2] = "I am well";

// STEP EVENT
if keyboard_check_pressed(vk_space)
{
if pos < array_length_1d(str) - 1
    {
    pos++;
    image_index = pos;
    }
}

// DRAW EVENT
draw_self();
if pos < array_length_1d(str) - 1
{
draw_text(x, y, str[pos]);
}
 
Last edited:
You need to keep track of the index in some way using a variable, then check if the variable is equal to a value (in this case 2). So something like:

GML:
// CREATE EVENT
pos = 0;
str[0] = "Hi world";
str[1] = "How are you?";
str[2] = "I am well";

// STEP EVENT
if keyboard_check_pressed(vk_space)
{
if pos < array_length_1d(str) - 1
    {
    pos++;
    image_index = pos;
    }
}

// DRAW EVENT
draw_self();
if pos < array_length_1d(str) - 1
{
draw_text(x, y, str[pos]);
}

That makes perfect sense. Not sure why I didnt think about it that way. Just relied too much on GMS to have some nifty script set in. Thanks friend.
 
Top