if variable changes

Get help using Construct 2

Post » Mon Nov 11, 2013 8:04 pm

How can I set up an event for if instance variable is added to, X happens?
B
61
S
20
G
56
Posts: 1,077
Reputation: 35,991

Post » Mon Nov 11, 2013 11:09 pm

system compare variable1 not equal to variable2:
set variable2 to variable1
do x
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Mon Nov 11, 2013 11:34 pm

@Burvey

There isn't a trigger for this that I've found. (That is, a reactive trigger that will happen whenever the variable changes anywhere. Personally, I want these too, but I can see why they aren't in the software).

I've been able to handle this in two ways:

1) Have two variables instead of one. The old value that only gets set in my checker and a "new value" everywhere else. I can compare to see if it got set Every Tick.

2) Or, I create a function that handles the what I want to do and call it everywhere I change the value.

Neither is truly reactive, but they work.PixelHero2013-11-11 23:36:56
B
15
S
5
G
2
Posts: 24
Reputation: 2,059

Post » Tue Nov 12, 2013 12:20 am

@PixelHero
It doesn't make a big difference. Method number one would most probably be, what a trigger would also do behind the scenes. So it's as reactive as it can be
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Tue Nov 12, 2013 1:00 am

@PixelHero

What I'm trying to do is change the bullet speed each time an enemy is hit. The way I have it now works which is the following:

If enemy hit is > 0 and <= 10 then set bullet speed to 100
If enemy hit is > 10 and <= 20 then set bullet speed to 110
If enemy hit is > 20 and <= 30 then set bullet speed to 120
etc...

It works but it takes a lot of events to do it and is a bit choppy. What I want to do is make it so that each time an enemy is hit, the bullet speed increases by 1. I tried using bullet.Bullet.Speed +1 along with the event that hit's an enemy, but it only works for the specific bullet. I need it to work with all bullets. Any ideas how I can get that to work correctly?

Thank you.
B
61
S
20
G
56
Posts: 1,077
Reputation: 35,991

Post » Tue Nov 12, 2013 1:37 am

Would something like this work?

global number bspeed=100

bullet collides with enemy
pick all bullet
---> add 1 to speed
---> set bullet speed to bspeed


The "pick all" condition can be used so not just the bullet that collided is selected. "bspeed" is a global so when you create new bullets you can set there speed bspeed. Of course that's just an assumption, you could also just omit the global and use bullet.Bullet.Speed +1.
B
94
S
33
G
114
Posts: 5,359
Reputation: 73,779

Post » Tue Nov 12, 2013 1:59 am

Or you could use:
bulletspeed = 100+floor(enemyhit/10)*10
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Tue Nov 12, 2013 2:06 am

@R0J0hound

Using the global like that did work, but unfortunately for some reason it messed up another part of the game. I guess I'll just leave it as I have it. I just wish it didn't take me 30 events to make it work lol

Thanks everyone for your input.
B
61
S
20
G
56
Posts: 1,077
Reputation: 35,991

Post » Tue Nov 12, 2013 2:35 am

Or you could use what I wrote.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Tue Nov 12, 2013 3:35 am

@mindfaQ

Just saw that, I'll give that a try.

EDIT:
After an hour or so of fiddling and changing my code I was able to get a variation of your code to work. Thank you for your help.Burvey2013-11-12 04:19:50
B
61
S
20
G
56
Posts: 1,077
Reputation: 35,991

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 19 guests