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

GML [SOLVED] Help with Walking Tile Aging

C

CheeseTyme

Guest
I need help with coding the steps for aging a tile when the player object moves out of the space of the tile instead of while it is inside. The tile uses 3 images to determine it's age. The player can only move through the tile twice before it flags a level failure and resets the whole room. Any ideas on how to do this?

I thought about setting a flag in the instance to change the image_index when there's no longer a collision but all of my efforts have instantly progressed through the entire aging process of the tile instead of holding the action until the next time the player object passes through it.
 

Simon Gust

Member
Sounds like you need a state machine.
CREATE
Code:
age = 0;
state = "free";
STEP
Code:
switch (state)
{
    case "free": 
        if (place_meeting(x, y, obj_player)) 
        {
            state = "occupied";
        }
    break;
    case "occupied": 
        if (!place_meeting(x, y, obj_player)) 
        {
            state = "free";
            age += 1;
        }
    break;
}
 
C

CheeseTyme

Guest
I've been spending too much time in Lua. Forgot about GML's switch.. Thanks Simon! That worked!
 
Top