Has [Variable] Changed?

New releases and general discussions.

Post » Sun Apr 17, 2011 11:36 pm

I know it's sorta late in 0.x's development for a feature request, but...

It might clean up a lot of coding if there was an event to check if a sprite's variable has changed.

That's it really.

If someone could implement this it would be awesome!
Follow me on Twitter @evgLabs
B
33
S
14
G
4
Posts: 251
Reputation: 4,049

Post » Sun Apr 17, 2011 11:39 pm

at the beginning of each tick set a pv ChangeFlag to 0
everytime you make a variable change, also change ChangeFlag to 1

the condition pv ChangeFlag ==1

would be what you're asking for
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Sun Apr 17, 2011 11:47 pm

I mean I would need to check specifically, if [Health] or [Speed] or [xxx] or [yyy] has changed. Not just [any variable]
Follow me on Twitter @evgLabs
B
33
S
14
G
4
Posts: 251
Reputation: 4,049

Post » Mon Apr 18, 2011 12:30 am

right
you'd just have to make a second variable for each

that's what would happen in the pv code to implement what you're saying, and it's just not in demand enough to be practical I think, especially at this point
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Mon Apr 18, 2011 8:51 am

There could be a built-in trigger - 'on variable changed' - but Construct would try to fire it every time you set the variable. I'm not sure because obviously it hasn't been measured, but this could end up being a significant performance drain on some projects. For example, if 5 fairly complex events fire every time you set a variable, that's a lot of overhead for a very simple action which is probably used a lot. Lucid's workarounds are probably a better idea, so we don't have to make everyone pay for a feature they might not use.

My favourite trick is a second variable which is the 'old' value - for example, 'Health' and 'OldHealth'. Then you can do something like:

+ Every tick
-> Set some value to 'Health' - 'OldHealth' (the "health difference")
-> Set 'OldHealth' to 'Health'
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600


Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 0 guests