How do I add a variable to a Instance only once?

Get help using Construct 2

Post » Wed Mar 04, 2015 9:59 pm

Hi!

I'm having a big problem here, mabey someone can help me:

I want to add a number to an instance variable but only once, so here's what I mean.

For example: Player is overlapping "Tree" -> subtract 50 from the Player's Instance Variable called "InView"
and when he is not under a "Tree" he will lose the Bonus of -50 "InView"

So what I'm trying to do is, giving the Player a Bonus of -50 on "InView" which will make him more difficult to find by the enemies. So "InView" stays for the visibility of the player.


Now my Problem is, that as long as the Player is overlapping the "Tree" construct2 is subtracting -50 constantly in place of just once every time he walks over.

I tried it with "Trigger once" but that only works for one time, so when the Player moves out of the "Tree" and after a while walks back in, he won't get -50 from "InView" again.

And I tried something with the Behavior Timer but i can't figure out how it really works.

Can somebody help me with this?
Thanks
B
16
S
8
G
6
Posts: 34
Reputation: 4,674

Post » Wed Mar 04, 2015 10:14 pm

Why not use an 'on collision' event instead?
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Mar 04, 2015 10:17 pm

'Trigger Once' is the way to go... regardless of your values you don't want to keep executing the same code over and over while the player is just standing there behind the tree you only want to set it once.

Use a boolean and make the player's 'state' to 'isHiding' and you can check that variable.
B
88
S
29
G
14
Posts: 1,145
Reputation: 14,985

Post » Wed Mar 04, 2015 10:55 pm

Ok, well that's a simple and nice tip. This should work fine for me.

@codah: the collision doesn't worked properly. The Player is not getting back the -50 if he's walking out of the Object:"Tree" again. anyway I'm going to try it with the boolean.

Thank you guys!
B
16
S
8
G
6
Posts: 34
Reputation: 4,674

Post » Wed Mar 04, 2015 11:39 pm

Oh right. Sometimes I store the previous value of a variable and compare the current value against the previous value (with a trigger once). That works as well because it keeps triggering as the value changes back and forth. Many ways to do it, but sounds like you've got it sorted.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596


Return to How do I....?

Who is online

Users browsing this forum: AkbarAsgharMG, giorgio1982, PreacH and 1 guest