Is it possible to set Boolean variable from expression

Get help using Construct 3!

Post » Sun Jul 30, 2017 8:25 pm

Im trying to set an instance Boolean variable based on an expression, i know i can use the expression itself to get the Boolean value but i don't want to have to keep evaluating the Boolean value each tick when its state only changes during a triggered event. so during the triggered event i want to set the Boolean based on some come condition but the set Boolean drop down is prepopulated with true and false and i cannot set it to an expression is this possible currently.
B
58
S
30
G
2
Posts: 37
Reputation: 5,624

Post » Sun Jul 30, 2017 8:37 pm

Conditions are set on the left. (i.e when mouse clicked and variablex = 1) [note you can stack the conditions or even have sub conditions/sub events]

Actions are on the right (i.w set the Boolean true or false)

i dont think you can set a Boolean by expression in an action (you would do it in a separate condition)
If you want set the variable directly in the action then use a normal variable, if it is to be a Boolean type just fill it with a 1 or a 0
then you can evaluate something else to get the return value for the variable in the action.

edit

sorry i just read what I wrote and I cant even understand it.
to simplify

as far as i can see you cant set a Boolean with an expression in an action

but you could set the conditions then just have another event that checks the conditions and sets the boolean
...
B
47
S
24
G
7
Posts: 355
Reputation: 8,314

Post » Sun Jul 30, 2017 9:12 pm

piranha305 wrote: ... i don't want to have to keep evaluating the Boolean value each tick


Yet, that is the way to go.

Unless you eliminate the use of the Boolean and move the actions that belong to its evaluating condition to the trigger.

Assuming, that i understand you correct. This not what you wanna do ...

On collision < a trigger
.............. set Boolean

On Boolean
.............. do stuff

Then just do this ...
On collision
............ do stuff
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sun Jul 30, 2017 11:17 pm

yeah that works for the simple case, but what if the Boolean is used in more than place? like lets take for example isAiming?

rightmouse button down => isAiming = true (so this right here isAiming needs to be a more complicated expression) like isAiming = (WeaponType == 1)

ifAiming => doSomething here

somewhere else like ...

if Aiming => play animation?

i mean i can just use the expression each time, its not too bad, or i can use sub events to get the desired effect, it would be nice to have a system action set boolean by expression or just have set value work on boolean values, but i can deal with it thanks :D
B
58
S
30
G
2
Posts: 37
Reputation: 5,624

Post » Mon Jul 31, 2017 9:35 am

Right mouse button down ?
Sprite > instance Munition > 12 ?
_______________ Sprite > Set boolean true

In the Animations Group
Sprite > Is boolean instance variable set ?
_______________ Sprite > set animation

In some other group
Sprite > Is boolean instance variable set ?
_______________ Sprite > do something else
_______________ UNREFERENCED object > do something

That sort kinda of situation?

Dont understand why you would use the expression. The condition is perfect fine ?
And blazing fast, if not true ... it just skips all the subs and actions.
There is no way that you can do it faster than this.
Unless i dont know where you are going with this.

You (i think) forget two important things.

1/ That boolean needs to be set false again. Setting that boolean false is not always easy. In this case it is easy.

On Right mouse released
_______________ Sprite > Set boolean true

This is a new event. As you notice.

2/ You see (i think) that boolean just as something that true/untrue. But it is way more then that.
Never forget the 'Sprite' that i wrote several times up there.

The condition 'Sprite > Is boolean instance variable set' PICKS all instances for that Sprite with that boolean = true. Its action work on all picked sprites.
As long as that picklist is not empty, actions addressing unreferenced objects will work on all instances of that unreferenced object.

So, if you set a boolean, and use that later to set animations (by instance), the condition also picks the right objects to set the animation to.

That might sound weird because you talk about an object with only 1 instance. Yet, also that 1 instance needs to be picked. And you better pick it intentional, rather than par hazard.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Mon Jul 31, 2017 11:35 pm

okay i see, so..

right mouse button down & sprite.ammo > 12 are together in the same condition which sets the boolean there could be an else after to set it to false which should work.

thanks

i'd need to have an extra event but it works well, :D
B
58
S
30
G
2
Posts: 37
Reputation: 5,624


Return to How do I...?

Who is online

Users browsing this forum: No registered users and 0 guests