Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: [Solved] Decreasing a value over time in GM  (Read 1875 times)

0 Members and 1 Guest are viewing this topic.

Ryuza

That one guy
[Solved] Decreasing a value over time in GM
« on: January 12, 2010, 05:55:32 pm »
  • RyuKage2007
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 290
Well, I'm kinda stuck right now on a project of mine with something really simple. I'm trying to find a way to make a value slowly decrease over time, the value's maximum is six and I want it to decrease slowly to zero over about 30 seconds, so a decrease of one every five seconds.

I'm sure its really simple but for whatever reason I seem to be having trouble with it. Also, I cannot decrease the value by say, .2 per second due to the fact that I have a gauge on my hud that has its image_index set to match the value and if it goes into the decimal range the gauge disappears.

Thanks in advance if anyone can help, all I need is just a bit of code or at least a suggestion of how I might be able to do it.

Edit:
~Solved~
« Last Edit: January 12, 2010, 07:24:21 pm by RyuKage2007 »
Logged
<- Koholint Island - MC Style  <- Link's Awakening Photo Recolors  <- Wind Waker 3D Resources <- Super Mario Bros Crossover
  • RyuKage2007's Youtube
Re: [Request] Decreasing a value over time
« Reply #1 on: January 12, 2010, 06:17:00 pm »
  • Oh.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 579
this.real_value -= .2;
this.displayed_value = int(this.real_value);

Should get you off on the right foot.
Logged
Hm.
Re: [Request] Decreasing a value over time
« Reply #2 on: January 12, 2010, 06:20:17 pm »
  • *
  • Reputation: +2/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1767
Assuming you're working with GM, it's really really simple.

All you really need to do is set an alarm to room_speed * 5 (so that way it'll translate to 5 seconds, not taking lag into consideration) if your variable is greater than zero.

So for your alarm event:
Code: [Select]
if (time_left > 0)
{
 time_left -= 1;
 alarm[0] = room_speed * 5;
}

And that way the count down will stop once it hits zero, and it'll allow for the time_left variable to be any number, rather than just 6. You could also change the room_speed * 5 into a variable to make that so you can have a different amount of time until it decrements. Hope that helps.
« Last Edit: January 12, 2010, 06:23:29 pm by Colbydude »
Logged
  • https://colbydude.com
Re: [Request] Decreasing a value over time
« Reply #3 on: January 12, 2010, 06:21:36 pm »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
I assume you want to know it for GM7. You have a number of options.

1) your game is running at a steady framerate. And you know what this framerate is. Thus after a fixed number of gamecycles you can decrease the value.

Or you can decrease it each cycle and for drawing just use the function "round(x)", "floor(x)" or ceil(x).

2) You use the time variables of game maker.

Quote from: Game Maker 7 help files
room_speed Speed of the game in the current room (in steps per second).
fps* Number of frames that are actually drawn per second.
current_time* Number of milliseconds that have passed since the system was started.
current_year* The current year.
current_month* The current month.
current_day* The current day.
current_weekday* The current day of the week (1=sunday, ..., 7=saturday).
current_hour* The current hour.
current_minute* The current minute.
current_second* The current second.
You save the start time when you start decreasing the value. Each step you can see how much time in milliseconds is passed and base the decrease on that. Note that, if you subtract the decrease each time, you need to store the start time again. You can even use decimals, because for drawing just round the value.
Logged

Ryuza

That one guy
Re: [Request] Decreasing a value over time
« Reply #4 on: January 12, 2010, 07:23:19 pm »
  • RyuKage2007
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 290
Thanks for the help you guys (I'm using GM8 by the way). I ended up adding "round(image_index)" to the step of the gauge and then I just added a subtraction of the variable for the step of the player ('charge' -= .2) I still need to play around with the amount it subtracts but its working now.

Thanks again for the quick help :).

Just in case anyone was curious my character has the ability to change forms and I needed to find a way to make it so it slowly decreases the gauge used to transform (once it empties he goes back to normal) as long as he remains in the form.
Logged
<- Koholint Island - MC Style  <- Link's Awakening Photo Recolors  <- Wind Waker 3D Resources <- Super Mario Bros Crossover
  • RyuKage2007's Youtube
Re: [Solved] Decreasing a value over time in GM
« Reply #5 on: January 12, 2010, 08:21:27 pm »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
goddamnit, you're all making this overly complicated.  Just use the step event, each step is one frame.

Code: [Select]
maincount -= .2/30


simple as that
« Last Edit: January 13, 2010, 01:32:33 am by MG-Zero »
Logged



i love big weenies and i cannot lie

Ryuza

That one guy
Re: [Solved] Decreasing a value over time in GM
« Reply #6 on: January 13, 2010, 06:04:35 am »
  • RyuKage2007
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 290
Thats about what I ended up doing, still needed to add round(image_index) to the gauge object though since its sprite was based off of the counter.
Logged
<- Koholint Island - MC Style  <- Link's Awakening Photo Recolors  <- Wind Waker 3D Resources <- Super Mario Bros Crossover
  • RyuKage2007's Youtube
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.072 seconds with 49 queries.

anything