T
The Last Random
Guest
Hey everyone,
I have run into a problem due to lack of knowledge.
I am trying to make a little prototype to test an idea I have for a proficiency system (Irrelevant info)
The Main functionality is that you start with 0XP, you click a button and you get +1XP, a small timer prevents you from spamming button. That is straight-forward enough, it is just the same code you use for a shoot mechanic, but this is where it gets tricky.
I want to have, after a certain amount of time, if the button has not been pressed the total XP starts to decay by -1xp, but if the button is pressed again the timer is reset.
So far the code mostly works, but the decay timer keeps happening, I want to turn it off when the button has been clicked and when the delay timer has finished I want the decay timer to start on a repeated loop until the button is pressed again or XP reaches 0.
Hopefully that makes sense, and thank you in advance for any help.
I have run into a problem due to lack of knowledge.
I am trying to make a little prototype to test an idea I have for a proficiency system (Irrelevant info)
The Main functionality is that you start with 0XP, you click a button and you get +1XP, a small timer prevents you from spamming button. That is straight-forward enough, it is just the same code you use for a shoot mechanic, but this is where it gets tricky.
I want to have, after a certain amount of time, if the button has not been pressed the total XP starts to decay by -1xp, but if the button is pressed again the timer is reset.
obj_commander
Here is the Relevant code from the obj_button
Code:
///Create Event
global.XP = 0;
global.decay_timer = room_speed*2;
global.decay_start = 0;
global.button_pressed = 0;
///Step Event
while (!global.decay_start = 1)
{
alarm[0] = global.decay_timer;
}
if (global.button_pressed = 1)
{
alarm[1] = global.decay_timer;
global.decay_start = 1;
alarm_set(0,-1);
}
if (global.XP < 0) global.XP = 0;
///Alarm[0]
global.XP -= 1;
global.decay_start = 0;
///Alarm[1]
global.button_pressed = 0;
global.decay_start = 0;
Code:
///Step Event
if (mouse_check_button_pressed(mb_left)) && (can_click = 1)
{
global.XP += 1;
global.decay_start = 1;
global.button_pressed = 1;
can_click = 0;
alarm[0] = 30;
}
So far the code mostly works, but the decay timer keeps happening, I want to turn it off when the button has been clicked and when the delay timer has finished I want the decay timer to start on a repeated loop until the button is pressed again or XP reaches 0.
Hopefully that makes sense, and thank you in advance for any help.