Trigger once while true

0 favourites
  • 7 posts
From the Asset Store
Change the size and position of everything without calculating anything!
  • 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?

  • It basically means "Is true this time and was false last time", or in other words, "is the first time this is true".

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • Thanks, I think I understand how it's implemented.

  • 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.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)