SOLVED How can I turn back an image index value to it's default value?

Hello, I have had another problem, you see, when my character shoots and his shot collides with the save object, I did it in such a way that the image index of the save object becomes its second value (which is 1, that is, the default value is 0), giving it a green color, indicating that a save occurred (the default color is red btw as the idle color). The problem is that I want, after a certain amount of time (like one second), the save object goes into is idle state, that is, the image_index index returns to 0. I have an idea to use the alarm state, but I think it is far-fetched. Can anyone help me with the code?

Here it is btw:
Inside oBullet (bullet object) events: On collide with oSave (save object) event:

GML:
with (other)
{
    if (image_index == 0) image_index = 1
    global.numSpawnX = x;
    global.numSpawnY = y;
}
The global values are as if I die or press the restart button, I appeared on the save object, a sort of checkpoint.
 
Why is setting an alarm “far fetched”? Seems like the sensible path, given what you want to do.
Well, how do I do it 🤔? I actually don't know how to use the alarm system, I only drag it to the table just because I heard about it, but I don't really know implement it in the codes.
 
Basically, in the bullet object step event I put:

GML:
if (place_meeting(x,y,oSave))
{
    instance_destroy()
}
So that there were no bugs.

I removed the:
Code:
if (image_index == 0) image_index = 1
From my previous chunk of code because it was messing up the new code.

In the create event of the save object I put:
Code:
alarm [0] = 60;
To set up the alarm.

In the "Alarm 0" event I put:
Code:
if image_index = 1
alarm_set(0, 60);
{
    if alarm_get(0) image_index = 0;
    image_speed = 1;
}
To set up the image index(es) of the save object.
And I added a collision event inside of the save object so that when the bullet hits it the image_index is set to 1, allowing to all the previous code to work.

And how did I manage to realise about all this?! In about 5 mins XD
 
Actually, there was a little bug, managed to fix it, I think.
Instead of:
GML:
if image_index = 1
alarm_set(0, 60);
{
    if alarm_get(0) image_index = 0;
    image_speed = 1;
}
I added the image speed:
Code:
if image_index = 1
image_speed = 1;
alarm_set(0, 60)
{
    if alarm_get(0) image_index = 0;
    image_speed = 1;
}
And I added:
Code:
if (image_index != 1) image_index = 0;
To the collision with the bullet event.
 

Slyddar

Member
if image_index = 1
image_speed = 1;
alarm_set(0, 60)
{
if alarm_get(0) image_index = 0;
image_speed = 1;
}
Glad you worked it out, but fyi this code is a little messy. Is the first 'if' meant to also apply to the alarm_set line, as an if with no curly brackets will only apply to the piece of code directly after it.

Also what do you think the curly brackets that you have are actually doing?
 
Also what do you think the curly brackets that you have are actually doing?
They weren't doing anything, I removed them, and actually the time between indexes looks better now. Sometimes they instantly changed to the default index, sometimes they didn't changed at all, but now it seems to be working fine, thanks for letting me know.
 
Top