0
Answered

Ticker-like Actions / Actions getting triggered periodically?

Phazorknight 2 months ago in Game Creator updated 2 months ago 12

Hey everyone,
I'm almost 100% sure that this is doable with Game Creator as it currently is, but just couldn't figure it out right now.

I'm trying to create a ticker-like action that just runs in the background (ideally with a condition being met before hand, that starts it).

Something like:
Condition: If the player has unlocked a "Goldmine"
Action: Every 5 seconds, 10 gold gets added.

Ideally this would be with variables or a formula, so I can change the speed (every 5 sec. / every 10 sec.) and the amount (10 gold, 20 gold, 10 gold * player level, and so on).
I figured this could be done with either inventory or stats add-on, just couldn't figure out the re-occuring part to have this run in the background. Does anyone have any pointers?

Unity version:
2019.4
Game Creator version:

Maybe use the wait action. At the end of your actions you could 'call the condition' or 'execute the actions' again.

Thanks, I tried this, but it doesn't seem to "stick", the loop doesn't continue.

I'm currently trying to set up a stamina system, giving the player a stamina attributes that automatically replenishes.


Here's my setup. Problem is that it only fires once if i perform an action that changes my stamina attribute.

Trigger: On Attr Change; Target Player; Attribute: stamina

> Triggering Conidtion

Condition: If Attribute stamina of Player is less or equal 0.9 percent; then:

Actions:

- Wait 1 second

- Add attribute stamina to Player (Amount 3)

- Call Condition (the one mentioned above)

+1

Hhhmmm, have you checked the stats module examples? On one of the scenes there is a mana regen example.

I can't remember how Marti did it, is it the same technique?

+1

I'm not sure you even need to call the conditions for this. With your trigger set to stamina attribute on change. Then every time your stamina changes your condition should be called.

Weird. 

Thanks for pointing me to the example.

So I just checked the Mana regeneration example, and there's two differences to my setup:

Trigger is just "On Start"

And there's no Conditions, just Actions.


I've changed my trigger to On Start, but then my Actions won't get called again, as the condition clearly "closes the loop".
I figure my Trigger seems correct, just getting the Actions to loop on a condition seems to be a problem.
Basically I want to create a "while" loop, I figure I just have my order wrong or something.

Figure I post my setup to make it clearer:


A couple of times, to get triggers and actions working correctly with attributes, I have had to start again and build them from scratch on a new character/player.

And then they magically work.

Might be worth trying to build the system again on a fresh scene and player. 

Thanks, tried it from scratch but still doesn't work. Made sure this time that all of the "loop" triggers, conditions and actions are on the Player Object (or child objects), but it still doesn't work. Gets triggered once, that's it.

Would really like to see how to do "while loops" with GC.

Does the player have 'Is Controllable' on the basic parameters?

Yes, isControllable is checked.

Hey everyone,
Just wanted to follow up that I got this working. Not sure how though.
I copied the whole example from the StatsExamples 2 (that has the regenerate mana object), and then modified it to trigger on attribute change, and to check a condition, and now it seems to execute correctly.

Also now that it doesn't have to be on the Player Object or as a child.

+1
Answered

Just as a quick recap. There is no "Update" Trigger because I think it leads to bad practices. I prefer to use more reactive-like programming, instead of checking constantly for values. It's easier, but can be a performance sinkhole.

But if you need to execute an Action over and over again, you can use the "Restart Action" action at the end of an Actions object. This will restart the action.

+1

Hey Marti, thanks for your input.
I see where you're coming from and agree, there shouldn't be Update Triggers.
I think the closest thing I was looking for was subscribing to an event / have event listeners, and then combining that with coroutines. For now the "On Attribute Change" works for what I was trying to do.
If I run into new challenges, I'll create a new topic.

Thanks everyone for chipping in and solving this.