I use the Timer Behavior as a 'in-object function'.

Discussion and feedback on Construct 2

Post » Sat Jul 15, 2017 2:05 am

I basically use the Timer for actions that I want to be preformed consistently. Like for example I will have a timer for "Damage Taken" so that whenever the object takes damage, it will react in a consistent way. No matter how it takes damage.

I was just wondering if there was a better way to do this. Like maybe I could use variables. (e.i. Set "Damage Taken" to true) Or maybe I should try something completely different. I just want the least CPU intensive way possible.
B
21
S
3
Posts: 53
Reputation: 1,100

Post » Sat Jul 15, 2017 5:46 am

Why not use a regular function to the same effect? Am I understanding this incorrectly?

[Object takes damage] --> run function "Damage Taken"

[Function "Damage Taken] --> play animation, subtract health, build more pylons, etc.
B
54
S
24
G
18
Posts: 295
Reputation: 13,140

Post » Sat Jul 15, 2017 3:12 pm

@Sup with that? The problem with using normal functions, is that you cannot use it with multiple objects. Say you have a bunch of enemys, and you attack one. If you use normal functions, every single enemy takes damage.
B
21
S
3
Posts: 53
Reputation: 1,100

Post » Sat Jul 15, 2017 3:42 pm

You pass in the UID of the enemy as a parameter, then Pick by UID first. Then it only affects the one enemy.
ImageImageImage
B
71
S
22
G
259
Posts: 3,793
Reputation: 143,702

Post » Mon Jul 17, 2017 9:58 am

The problem with the timer is that if your object takes damage again before the end of the first timer (unless you use a timer of 0?), the timer will only reset and the effect will not be applied.

blackhornet solution feels more natural to me, but I believe you could also use timers of 0 seconds for that.
If I'm correct though, functions are triggered immediately, while a "on timer" will not trigger before the end of the current tick (for a 0 second timer), so the function is probably superior.
B
33
S
6
G
1
Posts: 355
Reputation: 2,850

Post » Mon Jul 17, 2017 11:18 am

angryscientist wrote:@Sup with that? The problem with using normal functions, is that you cannot use it with multiple objects. Say you have a bunch of enemys, and you attack one. If you use normal functions, every single enemy takes damage.


You can, you just need to use pick by uid in subevents of the function. Here's an example where I pass the attacker's uid and the defenders uid in separate parameters of the function (my function object is called f):

http://imgur.com/a/qSRqc

Of course if I need something from the attacker (a variable value) in a sub-event where the defender is picked I use pick all to reset picks and pick by UID attacker again. Although I prefer to just store everything I need in variables local to the function.
B
15
S
6
Posts: 85
Reputation: 1,195

Post » Sat Jul 22, 2017 4:11 pm

@Rable I do actually set the time to 0. But I think I am going to start using functions, now.
B
21
S
3
Posts: 53
Reputation: 1,100

Post » Sat Jul 22, 2017 4:12 pm

@Rable I do actually set the time to 0. But I think I am going to start using functions, now.
B
21
S
3
Posts: 53
Reputation: 1,100


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 5 guests