Jump to content


Photo

Changing the time span of an alarm? [SOLVED]


  • Please log in to reply
8 replies to this topic

#1 bowlda

bowlda

    GMC Member

  • GMC Member
  • 21 posts

Posted 12 July 2012 - 04:32 AM

Hello, I was wondering if its possible to chang, or in this case, shorten an alarm after it has already started. in my game i have an object which an egg. I made an alarm which hatches it after, say, a minute. but if the player warms the egg (or clicks it....same thing) i want it to lessen the time until it hatches. Can anyone help me out? Thanks
  • 0

#2 GMKn00b

GMKn00b

    GMC Member

  • GMC Member
  • 150 posts
  • Version:Unknown

Posted 12 July 2012 - 04:45 AM

DO set alarm :GM040:

So in the click event of the egg have set alarm
SETTINGS:
Spoiler


That's it :thumbsup:

Edited by GMKn00b, 12 July 2012 - 04:47 AM.

  • 1

#3 hi cooper123

hi cooper123

    GMC Member

  • GMC Member
  • 29 posts
  • Version:GM8

Posted 12 July 2012 - 04:45 AM

Instead of having the
alarm[0] = 600
, or something make the 600 (or whatever it is) a variable. Such as
alarm[0]=hatchtime
and you can just set the default hatchtime, and reduce the hatchtime when the player warms the egg
  • 0

#4 bowlda

bowlda

    GMC Member

  • GMC Member
  • 21 posts

Posted 12 July 2012 - 05:40 AM

DO set alarm :GM040:

So in the click event of the egg have set alarm
SETTINGS:

Spoiler


That's it :thumbsup:

So, let me get this right, is the alarm already started with the default time when the egg instance is created, and then start alarm again with a value of of -30 and making it relative under the click event?

Instead of having the

alarm[0] = 600
, or something make the 600 (or whatever it is) a variable. Such as
alarm[0]=hatchtime
and you can just set the default hatchtime, and reduce the hatchtime when the player warms the egg


wouldnt this just start the alarm back over at the difference between the original hatchtime and the amount of reduction, rather than the difference between the CURRENT time and the reduction amount. But I might be wrong, please tell me.

Thanks to both of you for speedy answers!
  • 0

#5 Oracizan

Oracizan

    Mutant Dreamer

  • GMC Member
  • 338 posts
  • Version:GM:Studio

Posted 12 July 2012 - 06:00 AM

You can treat alarms just like any other variable. If the player is warming the egg, subtract a number such as 30 from the alarm and it will decrease the time. The only thing you need to make sure of is that the alarm does not drop below 1, or it won't go off.

alarm[0]=max(alarm[0]-30,1)

  • 2

#6 bowlda

bowlda

    GMC Member

  • GMC Member
  • 21 posts

Posted 12 July 2012 - 06:54 AM

You can treat alarms just like any other variable. If the player is warming the egg, subtract a number such as 30 from the alarm and it will decrease the time. The only thing you need to make sure of is that the alarm does not drop below 1, or it won't go off.

alarm[0]=max(alarm[0]-30,1)


Okay thank you for the explanation. I did a test run and put the default hatching time to 300 for the alarm (or about 10 seconds) upon creation. I then used the code that you gave me on the click event. When i run the game, it correctly hatches after about 10 seconds, but after running the game again and immediately clicking the egg only twice, it hatches prematurely and almost immediately after clicking rather than shaving the supposed 2 seconds off of the 10 second time. Could someone please explain why?
  • 0

#7 Jack Indie Box

Jack Indie Box

    GMC Member

  • GMC Member
  • 1460 posts
  • Version:GM:Studio

Posted 12 July 2012 - 08:38 AM

you probably used the wrong mouse event. you need to use local left button PRESSED(or released, not just held as it will run multiple time if you use that one, and use global if you just want to click anywhere on the screen not just the object the code is in)
  • 1

#8 GMKn00b

GMKn00b

    GMC Member

  • GMC Member
  • 150 posts
  • Version:Unknown

Posted 12 July 2012 - 09:50 AM

So, let me get this right, is the alarm already started with the default time when the egg instance is created, and then start alarm again with a value of of -30 and making it relative under the click event?

It doesn't start again with -30, because you ticked the relative box :sweat:
That's what it does, if you tick it it adds it instead of setting it to -30.
Spoiler

It's relative to the Alarm that you picked not the click event(sorry for the confusion)
So the method above should work :tongue:

EDIT: Let's just say relative simply means adding it to the current value

Edited by GMKn00b, 12 July 2012 - 10:19 AM.

  • 1

#9 bowlda

bowlda

    GMC Member

  • GMC Member
  • 21 posts

Posted 12 July 2012 - 02:53 PM

you probably used the wrong mouse event. you need to use local left button PRESSED(or released, not just held as it will run multiple time if you use that one, and use global if you just want to click anywhere on the screen not just the object the code is in)




So, let me get this right, is the alarm already started with the default time when the egg instance is created, and then start alarm again with a value of of -30 and making it relative under the click event?

It doesn't start again with -30, because you ticked the relative box :sweat:
That's what it does, if you tick it it adds it instead of setting it to -30.
Spoiler

It's relative to the Alarm that you picked not the click event(sorry for the confusion)
So the method above should work :tongue:

EDIT: Let's just say relative simply means adding it to the current value


Thank you so much for the help. It works!

Edited by bowlda, 12 July 2012 - 02:53 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users