Problem with Timer (Every) and Variable (Frequency)
Hello,
I am stumped with something which looks quite simple. I have a timer which spawns enemy actors every x seconds or fractions thereof. I have a variable (real, not integer) which changes upon certain conditions occurring in the game, hence the frequency at which the actors spawn should accelerate. I have the "run to completion" box checked.
Sounds logical, right? Well, I know the frequency variable changes (I have it in a display text actor), but the frequency at which the actors are really spawning is unchanged. A validation test is to manually assign a value to the timer to the speed at which I've seen the variable go down to in the display text actor, and the difference is certainly obvious. Just for reference, the spawn frequency assigned at the beginning of the game is 1.0, and the display text actor has gone down to as los as 0.1, but the spawn frequency still is 1.0.
Any thoughts on this? Thanks, regards.
Comments
Update: Constraining a second variable made the actual spawning frequency change, but only after the player lost his life. It seems I may need to find the proper place to put the "Constrain Attribute"?
My Blog / App Store / Google Play
@mhedges, when you invoke a "timer every X seconds" then it is set to that X value for its lifetime.
To have a variable frequency trigger you need to make your own loop.
e.g.
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
@Hopscotch,
Thanks. This could get messy (unless I misinterpreted). This is what I have:
Actor: "Spawn Handler" (event handler) has the timer.
Timer: Every x units (where x is the spawn frequency), Spawn Actor: "Enemy"
Actor: "Enemy" carries out its behaviours (does its thing). There are about ten different types of enemies, randomly selected and spawned.
Does the loop you suggested go in actor "Spawn Handler", or does it go in actor "Enemy"? The reason I created the "Spawn Handler" is to simplify how events occur (object-orientedish?).
Thanks, regards.
My Blog / App Store / Google Play
@mhedges, absolutely (no, not messy at all). Your "object-orientated" or "event-based" thinking is vital to good structure in GS.
Yes my loop goes into the "Spawn Handler". You can add conditions deciding which type of enemy to spawn inside it.
The enemy only has its own behaviours in it.
You can go as far as setting a game.EnemyType attribute before you spawn the enemy. Once you spawn the enemy, the newly spawned enemy checks this game.EnemyType attribute to know what it should be and act out rules accordingly. This can also include changing to the appropriate enemy image.
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
Another approach would be the AmazingDisapearingAndReappearingSpawner™©
It works like this. Make a game.attribute, let's call it X. In your 'Spawn Handler' actor place the following rule:
. . . . .
After X seconds.
• Change X to new X time
• Spawn enemy actor
• Destroy
• Spawn 'Spawn Handler'
. . . . .
Obviously this 'new X time' will be defined by whatever method you are using to speed up the time between spawns, so if you wanted X to start life as 10 seconds and then decrease (to make the spawning get faster and faster), you might use 'Change X to X-1', or as you say the timer is changed by certain conditions occurring in the game, so there might be an attribute (let's call it Y) that is being increased over time that speeds up the spawning, like this Change X to X-Y . . . . etc etc.
The only other thing you might want to include is a limit, so that the spawning doesn't get too fast, let's say we want the spawning to start out at once every 4 seconds, then when the event happens (whatever it may be) we reduce the time between spawns by 0.2 seconds, but we don't ever want to spawn faster than once every 1.4 seconds, to do this simply wrap the above code in a rule like this . . . .
. . . . .
While X is larger than 1.4
• After X seconds.
•• Change X to X - 0.2
•• Spawn enemy actor
•• Destroy
•• Spawn 'Spawn Handler'
. . . . .
Thanks gents, problem solved. I used several timers (for within x and xx values) and a boolean (on each timer). This is something the dev team should consider including in their agenda. Regards.
My Blog / App Store / Google Play