Trigger once while true

Discussion and feedback on Construct 2

Post » Wed Nov 19, 2014 1:37 pm

Hello fellas,

Does anybody know how condition "trigger once while true" works in terms of "classical" code. I'm trying to achieve the same effect in Unity with C# using booeans, but I think the way I'm doing it is not abstract enough, so that I have to create different booleans for different conditions and set them on/off all the time. Should it be a separate object/class or something like that?
B
45
S
11
G
4
Posts: 517
Reputation: 7,393

Post » Wed Nov 19, 2014 2:09 pm

It basically means "Is true this time and was false last time", or in other words, "is the first time this is true".
Scirra Founder
B
398
S
236
G
88
Posts: 24,441
Reputation: 194,681

Post » Wed Nov 19, 2014 2:34 pm

I think I get that, but it is interesting how is it implemented in code: is it some sort of temporary boolean or a "class/method" which is taking care of that and how?

Currently i'm just setteing a boolean true/false - (condition && bolean==true) is triggered, I set boolean to false. Than I have to set it back to true on other condition. It works, but it means I have to create separate booleans for different conditions, which I want to check "on trigger once true". C2 is really joy to work with all its helper functions.
B
45
S
11
G
4
Posts: 517
Reputation: 7,393

Post » Wed Nov 19, 2014 6:38 pm

Well I don't see how you'd even accomplish it with a class or method? You basically just want a boolean for "was true last time". Also in many programming languages you'd actually explicitly fire an event when something happens and allow callers to register for that event, instead of testing a condition regularly and triggering something when the state changes. It's a case of where typical C2 style is different to traditional programming.

In C2's case, it stores a separate boolean per condition, since each condition needs to track its state independently. Actually the specific C2 implementation is based on tick counts, but if you're just learning to program, that's not really important.
Scirra Founder
B
398
S
236
G
88
Posts: 24,441
Reputation: 194,681

Post » Wed Nov 19, 2014 9:48 pm

Thanks, I think I understand how it's implemented.
B
45
S
11
G
4
Posts: 517
Reputation: 7,393

Post » Wed Nov 19, 2014 11:37 pm

Could you give us a sample of your code, or some idea of the kind of the logic you're trying to do? You might want to use a finite state machine to keep track of states. Or as @Ashley has mentioned, you could do something event/trigger based to more closely mimic what C2 does, maybe publisher-subscriber. But, just like you don't want to write prodecural (classical) code in C2, you don't want to think in terms of C2 when programming classical languages.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Thu Nov 20, 2014 12:03 am

It's an interesting subject. I'm planning on learning 'real' programming fairly soon, and I'm a little worried I'll have some habits left over from C2 that don't translate well to classical programming. I'd *love* to see a guide or tutorial that would list helpful tips about what I'll need to look out for and change when I start exploring classical programming. I reckon C2 is a great stepping stone to programming for beginners and something like this would really help.
Maybe it's not really feasible though since there's a big amount of variation in programming languages, and styles, like OOP etc.
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,689


Return to Construct 2 General

Who is online

Users browsing this forum: JesusJ and 17 guests