What is the best way to analyze three (or more) ranges of values ​​of the same variable? [SOLVED]

Not favoritedFavorited Favorited 0 favourites
  • 14 posts
From the Asset Store
Best car suspension with spring effect and very cool terrain generation.
  • Hi guys!

    I'm a game designer with some knowledge of programming logic, but every now and then I come up against my limitations.

    I'm trying to implement a condition that considers three ranges of values ​​of the same variable, to express something visually in the game, but still without success. I've tried the expressions "Compare two value", "Is between values" and even analyzing each state of the variable individually. But also without success.

    What is the best way to do this?

    Thank you once again for your attention and collaboration!

    Tagged:

  • I would try using the Evaluate expression condition.

    In the value of the condition you can do something like:

    (your_variable > min_value) & (your_variable < max_value)
    

    That translates to your_variable GREATER THAN min_value AND your_variable LOWER THAN max_value. If that that is true then your_variable is within that range.

    If you want to test for different ranges you would have different condition and do different actions for each condition.

  • I would try using the Evaluate expression condition.

    In the value of the condition you can do something like:

    > (your_variable > min_value) & (your_variable < max_value)
    

    That translates to your_variable GREATER THAN min_value AND your_variable LOWER THAN max_value. If that that is true then your_variable is within that range.

    If you want to test for different ranges you would have different condition and do different actions for each condition.

    Thanks, dude! Where is this expression in Construct 2?

  • It should be part of the System.

  • It should be part of the System.

    Unfortunately, he doesn't appear in C2. :(

    Do you have an alternative?

    (I swear I tried solutions with IA, but it only returned errors this time)

  • I thought it was, sorry about that. Then you should use the Is Between Values condition, which will do what you are describing. You just need to provide the value you are testing and the lower and upper bounds of the check.

    Add conditions for each range you want to check and you should be good.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I thought it was, sorry about that. Then you should use the Is Between Values condition, which will do what you are describing. You just need to provide the value you are testing and the lower and upper bounds of the check.

    Add conditions for each range you want to check and you should be good.

    I already tried it. :(

    I really need a project example or something like that to understand how this works.

  • Maybe I understand this wrong, but do you want a three 'between values' condition as an or-block?

  • you can also do this in one expression (system evaluate), i.e.: (value >= 5 & value <= 10) | (value >= 15 & value <= 20) | (value >= 25 & value <= 30)

  • Maybe I understand this wrong, but do you want a three 'between values' condition as an or-block?

    Each condition (value range) of the same variable will get his own result.

    For example:

    If the COUNT variable is between 0 and 5, the HUD expresses X.

    If the COUNT variable is between 6 and 15, the HUD expresses Y.

    And so on.

  • you can also do this in one expression (system evaluate), i.e.: (value >= 5 & value <= 10) | (value >= 15 & value <= 20) | (value >= 25 & value <= 30)

    Thanks, dude, but the C2 doesn't have this expression. :(

  • It's working!

    I had forgotten to declare one condition and that was the whole cause of the problem! Sorry for the inconvenience!

    It workd with the "In between values" expression! :D

  • It exists in Construct 2, you can read about it here under operators. https://www.construct.net/en/construct-2/manuals/construct-2/project-primitives/events/expressions

  • Each condition (value range) of the same variable will get his own result.

    If the COUNT variable is between 0 and 5, the HUD expresses X.

    If the COUNT variable is between 6 and 15, the HUD expresses Y.

    Another way to do this is with ternary operator:

    TextHUD set text to ((count>=0 & count<=5) ? "X" : (count>=6 & count<=15) ? "Y" : "Z")

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