How to create a timer for "Power Ups" to wear off?

Morning all.

I am finally seeing the end of my dark dork tunnel. My lives are working, my Enemy ships, BG, Music, etc etc. But I have still having a problem with the Power ups.

All power ups are now spawning on the correct timers, but power ups like Invulnerability(Which is supposed to give a 10 second bubble around the player ship where it takes zero dmg) and Doublecanon(Which gives the player two extra firing points on the player ship for 30 second), are not working.

The first problem is, I created them in Sketchbook Pro, Saved them and opened them in APSE9 and resized them to 100x/50y. When they spawn, they are still showing up at 1920x/1200y. I have resized them several times using my Photo programs and in GD as well putting them on the scene off a bit from the actual screen. I resize then to 100/50 and lock them in place. But no matter what I do, when they respawn they are 1920/1200. Any thoughts?

Second, the timer thing.

I cannot get the timers to work. I am using the following code for each, adjusted for the object of course.(I’ll leave out the creation code as they are actually working…)

(Double Canon 10 sec timer then reset.)
Condition

Variable PlayerHP is >=1 Doublecanon is in collision with P1Bullet Do +1 to Variable Doublecanon Reset timer CanonTimer Delete object DoubleCanon

Variable PlayerHP is >=1 The Timer "CanonTimer" is greater to 30 seconds

Do =Variable(PlayershipdefaultDoublecanon) to Variable Doublecanon

Is this correct? I have searched for the answer in the Equation tool, but I just cannot seem to find how to make this work. Any thoughts or advice will be greatly appreciated!

:slight_smile:

If you save the new image over the last one, GD will continue to use the original file (I’m not sure why?). You can solve this by saving your new re-sized file as “filename1.png” where the old image was “filename.png” and then import filename1.png into your game and use that one.

For future reference: It is best to screenshot the events you’re having trouble with if you can (or upload a game file), as the error may be something we cannot see just by you quoting text. You can upload attachments to posts.
As for the problem itself…

…these are not the same variable…

GD doesn’t save any kind of external data in the file (.gdg files are XML or something like that).
I think that GD, as any program, load the images in the memory, and refresh them some times (under certain events) to ensure a good performance. When you edit an image externally GD has no way to know you edited the image, so do nothing :neutral_face:
To refresh every image, close and open the project (there are events to refresh some images without closing the project, but re-open it take no time) :slight_smile:

Thank you mats and Lizard :slight_smile:

Here is SS of code for the two Timed Ppower ups I am fighting with.

Oh. I just finished the first Boss level last night and need what I think might be a simple fix. When the Scene loads for the first time, the Boss ship spawns and functions perfectly, until the player ship is destroyed. After the first player death, the Boss ship will not spawn, but I can hear it still firing off the screen.


And as always, I very much appreciate all of the help and advice you all have given me. I’ve never had this sense of community of the web before.

The problem with the power up is what I originally said. You need to ensure the variables have the same name. I take it the invulnerability is working?

For the boss function: What is the point in having a timer that resets after such a long long time? Just remove it. The same for the variable check. The variable is never going to be that high, so why have the check for <=999999999999999999999 in there? Btw, the timer is probably why the boss is not spawning. Since it’s never going to be > 10000000000 seconds. However, if you’re not resetting that timer at the start of scene, it will pass the test the first time. It’s bad practice to use timers that are not set, just so you know. It’s wise to avoid doing this in future. If you use a timer, make sure it’s reset someplace BEFORE you check its time.

Are you going to release this game once it’s finished?

Neither are working.

** I have that variable in there for the normal enamy spawn. I forgot to remove it for the boss. I have it set that high for normal enemy creation because (for example) I found that when I did <=30, after I killed 30 enemy ships, they would stop spawning. So by adding 1 to the creation variable, enemy ships will continue to spawn until the Player ship has been destroyed, or the seperate level Goal has been reached ***

**I had set that timer to such a large numberbecause it seems if I set it any lower, the boss ship would continue to chain spawn and my systems would freeze

Yes. If I can get these simple stupid little flaws figured out, I would be ready for release. I already have all the SFX, BG Music, 99 more levels(10 of which are Boss Battles), and Art done.

If you have a condition that is always true, you don’t need it in there. Remove this variable.

To stop a boss (or anything else you want just one of) chain spawning:

Add to conditions: Variable(bossexists) = 0

Add to actions (when creating the boss): Do =1 to Variable(bossexists)

Remember to set bossexists back to zero if the boss is destroyed for any reason (if you want another one to spawn). :wink:

hmm… That is a problem. Are Variable(playershipdefaultDoublecanon) and Variable(PlayerdefaultInvulngerability) definitely initialized to zero?
Also, what does the code look like that makes your player have a double shot or invincibility?

Timed Power Ups.jpg

The top SS is the code for the creation and gain of the bonus Doublecanon and Invuln. the Bottom SS is the Playership Weapon controls with a sub event for the Condition of gaining Doublecanon

Your problem is this.

Variable(variablename) - This is a scene variable.

Variable(playershipvariablename) - This is also a scene variable, just with a very long name.

playership.Variable(variablename) - This is the variable, called variablename, of the object playership.

i.e. Variable(playershipvariablename) is NOT the same as playership.Variable(variablename). Where you have put Variable(Playershipdefaultdoublecanon) you want the variable of the object playership, which you should find in all objects → Variables → Change the variable of an object.

By only reading your events I’m really can’t find the problem. :blush:
Would be great if we could experience the problem, this way we could start working on the solution instead of
giving you tips and tricks that doesn’t work.

Anyway, my tip for you is this:

For the value of the power up, you have to store the value in a variable, and you have to use that
variable everywhere to make sure if you change the value, the new value is in use in all cases.
For example, if you want extra damage for 5 sec, first you have to make a variable that store
the value of damage. and use that variable like so:

At the beginning of the scene : do =10 to Variable(player_damage)
If player_bullet is in collision with enemy : do -Variable(player_damage) to enemy.Variable(enemy_health)

POWER UP
If player is in collision with power_up : do =20 to Variable(player_damage) and reset timer
If Variable(player_damage) > 10, after 5 sec : do =10 to Variable(player_damage)

In case of enemies, don’t forget to use object variables to make sure the values are individual for each enemy and I would use an object variable as timer to make sure the timer is also individual for each enemy, like so:

when enemy is created : do =10 to enemy.Variable(enemy_damage) and do =0 to enemy.Variable(enemy_timer)
(or this can be a default value for each enemy object in settings)
If enemy_bullet is in collision with player : do -enemy.Variable(enemy_damage) to Variable(player_health)

POWER UP
If enemy is in collision with power_up : do =20 to enemy.Variable(enemy_damage)
If enemy.Variable(enemy_damage) > 10 : do +1 to enemy.Variable(enemy_timer)
If enemy.Variable(enemy_timer) > 5000: do =10 to enemy.Variable(enemy_damage) and do =0 to enemy.Variable(enemy_timer)

Of course it not perfect, only a quick train of thought but I would do something like this in case of values.

In case of visual objects, effects like shield, bigger fire for firing weapon, different looking bullet…etc
I would go with animations. I recommend to simply change the animation. Make a player animation with no shield, and
make a player animation with shield, when the shield power up is picked up, simply change the animation and reset after 5 sec.
Don’t make connection between values and animations, simply change value and animation in same condition for same amount of time.

I hope it helps to find the right way to do it.

Ok. I think I understand now. I was using a Scene veriable. Not the Variable I put on the Playership itself. So I f I change the Condition Variable from Scene to the Object(Playership) variable it should work?

Just consistently use EITHER:

Variable(variablename) [scene variable]

OR

playership.Variable(variablename) [object variable]

And be sure in future to not mix scene and object variables. :wink:

Ok. I have finally got the Doublecanon Powerup to actually create the extra two firing spots on the player ship. (Which mind you has cost me what was left of my hair). The only problem is the Timer. I just cannot figure it out. I have tried to type exactly what you all are typing. I don’t either understand or know how to use the Expression tool I will manually type in what I have been told to:

POWER UP
If player is in collision with power_up : do =20 to Variable(player_damage) and reset timer
[size=150]If Variable(player_damage) > 10, after 5 sec [/size]: do =10 to Variable(player_damage)

I out in what I needed to:(Adding two more firong points on the player ship. Reducing Player Power by the proper amount, etc) But the part in Red,…I have tried several different ways to input that. Since I am using the Expression tool, and manually typing in the expresssion It will either tell me there is no error and allow me to contniue and hit OK. Or I will get the Inevitable Error Box “You’re a dumb ass. Are you sure you want to do this?” I will rewrite the expression until it reads no errors and click ok. I load the game, Gain the Doublecanon Power up, fire off a couple of bullets to make sure I actually have the power up, and wait for 60 seconds(I know it’s only a 30 second timer, just making sure) and fire again to see if the Power up has faded.

It never fades.

You need to make a normal timer. Get rid of the Variable(DoubleCanon) > 1 + TimeDelta() * 30. In place of this, check for timer(sometimername) > 30 seconds. In the function in which you set Variable(DoubleCanon) to 1, reset the timer(sometimername).

You might find this short tutorial on shooters helpful. It covers some of these topics you have had problems with. Part 1: youtube.com/watch?v=0ZW57s2WT1o