Bool / Flags - And range of numbers

This forum is currently in read-only mode.
From the Asset Store
Flags
$2.50 USD
50% off
An educational memory game about countries’ names and their flags!
  • Hi there

    So what i'm trying to do is basicly..

    +If Global "stuff" = 0

    • Do stuff
    • Toggle global "stuff"

    When "stuff" is 0 something happens and "stuff" will be 1 end vice versa...

    I cant seem to find any booleans or flags in construct, only variables that cant be toggled this way.

    I started off by using Fusion and i used the flags there alot...

    And another thing. When comparing values, can i tell construct to compare value to a range of numbers ? Like if Velocity of sprite is within range of (-1 - 1) ?

  • You can use the System object's "Number is between..." condition to see if a value is within a given range.

    There are no actual booleans in Construct, but you can use regular values to represent them. A simple way to toggle one of these values between 0 and 1 would be to use the conditional operator("?"). Just set the value to this:

    global('stuff') = 0 ? 1 : 0[/code:2ud6rw4m]
    This basically means:
    
    if "stuff" equals 0 [b]then(?)[/b] return 1 [b]else(:)[/b] return 0
    
    Hope this helps.
  • Thanks for your help, this was excetly what i was looking for but it didn't work though.. prob my fault..

    First thing:

    Basicly i am using the toggle thing to see which player is suppose to act.. i start out having a global variable "turn" = 0. Then when team 0 (red) acts it toggles the "turn" variable to 1 (blue). Then it goes like this back and forth.. Anyway when i used 0 ? 1 : 0 it always game me 1.. dont understand why.. tried to have it the other way 1 ? 0 : 1, then it went the other way.. always 0..

    The other thing:

    The number is between thing worked out fine. But the way i'm trying to use it doesnt work.

    I am using the physic behaviour and when the velocity is between -1 and 1 i want the velocity to be 0, just stopped. I'm trying to do this because the round is over when all the items are stopped but it takes soooo long for it to reach from 1 to 0.. or -1 to 0.. I cant figure out any other way.. but if i try to force it this way the items dont move but few pixels..

    [edit]

    I just another way to deal with the first thing but there must be a easier way..

    I set a variable Enemy on the items and set it to the enemys number.

    So red items(0) and the enemey variable 1 and blue(1) had the enemy varable 0.

    So when the turn was over i set the global variable "turn" to the items enemys variable.

    That worked but rather bad fix, i want to use the toggle thing

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I imagine you're probably not using the whole expression I mentioned. The "global('stuff') = " part is actually part of the expression, since the conditional operator checks that value and decides what value to return based on whether it meets the condition or not. Here's an example, just press space to toggle the value:

    Boolean Toggling

    I hope this clears things up.

    On the issue of the number is between thing, would you mind posting a CAP with the problem? It's hard to understand exactly what's wrong without one.

  • in some cases you could use *-1 as a toggle if your number starts by being 1 or -1, like so:

    Set value 'boolean' to "('boolean') * -1"

    And treat 1 as ON and -1 as OFF.

  • I imagine you're probably not using the whole expression I mentioned. The "global('stuff') = " part is actually part of the expression, since the conditional operator checks that value and decides what value to return based on whether it meets the condition or not. Here's an example, just press space to toggle the value:

    Boolean Toggling

    I hope this clears things up.

    On the issue of the number is between thing, would you mind posting a CAP with the problem? It's hard to understand exactly what's wrong without one.

    Yep.. Now its working right.

    Are there more regualar expressions in construct ?

    [quote:2lu2t9vl]in some cases you could use *-1 as a toggle if your number starts by being 1 or -1, like so:

    Set value 'boolean' to "('boolean') * -1"

    And treat 1 as ON and -1 as OFF.

    This is also a good way, i will be using it also thank you.

    The physic stuff that i'm talking about is toggled off in the bottom. I know this way will not work but i think you will understand what i am trying to do.

    http://internet.is/eski/shuffleboardThing.cap

    Next agenda is to have red player controlled by the computer.

    Any tips on how i should randomly choose a puck and launch it over to the blue side ?

  • 1 - value will toggle between 0 and 1. 0/1 are the standard boolean values, rather than -1/1.

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