# Bool / Flags - And range of numbers

For questions about using Classic.

### » Fri Jan 01, 2010 10:58 pm

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) ?
B
7
S
1
G
3
Posts: 66
Reputation: 1,651

### » Sat Jan 02, 2010 12:31 am

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:

[code:2ud6rw4m]global('stuff') = 0 ? 1 : 0[/code:2ud6rw4m]
This basically means:

if "stuff" equals 0 then(?) return 1 else(:) return 0

Hope this helps.
Moderator
B
98
S
36
G
19
Posts: 1,584
Reputation: 17,717

### » Sat Jan 02, 2010 1:28 am

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

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
B
7
S
1
G
3
Posts: 66
Reputation: 1,651

### » Sat Jan 02, 2010 1:48 am

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.
Moderator
B
98
S
36
G
19
Posts: 1,584
Reputation: 17,717

### » Sat Jan 02, 2010 11:27 am

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.
B
5
S
2
G
3
Posts: 234
Reputation: 1,818

### » Sat Jan 02, 2010 11:46 am

[quote="linkman2004":2lu2t9vl]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.[/quote:2lu2t9vl]

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.[/quote:2lu2t9vl]

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.

[url:2lu2t9vl]http://internet.is/eski/shuffleboardThing.cap[/url:2lu2t9vl]

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 ?
B
7
S
1
G
3
Posts: 66
Reputation: 1,651

### » Sat Jan 02, 2010 4:20 pm

1 - value will toggle between 0 and 1. 0/1 are the standard boolean values, rather than -1/1.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,518

Return to Help & Support using Construct Classic

### Who is online

Users browsing this forum: No registered users and 3 guests