Expressions in Construct 2

Discussion and feedback on Construct 2

Post » Sat Feb 19, 2011 4:12 pm

It works like this:

<some condition> ? <what to return if condition true> : <what to return if condition false>

So you can put conditions directly in expressions. For example:

+ Sprite X < 100
> Set text to "Left"

+ Sprite X >= 100
> Set text to "Right"

is equivalent to

+ Every tick
> Set text to Sprite.X < 100 ? "Left" : "Right"
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Sat Feb 19, 2011 4:53 pm

Woah!! That's just brilliant!
B
8
S
2
G
5
Posts: 744
Reputation: 3,288

Post » Mon Feb 21, 2011 5:04 am

Hi.. I'm currently experimenting with adding signposts within a platformer..
When the player object is overlapping a signpost sprite, a text object appears above and displays the text contained within the signpost variable.

player on collision with Signpost ---> Signposttext set text to signpost.signtext

However it always displays the text from the *first* instance of the signpost object, rather than the one the player has collided with.

I tried it with a number based instance variable, simply called "id" with '0' for the first signpost and '1' for the second signpost... that too, also displayed "0" no matter which instance was collided with.

I tested it to see if it was because it was a variable at all.... I set it to display the signpost.x instead of the signpost.signtext variable, and it works, it picked the instance that had been collided with.

So have I found a bug or am I missing something? D:
thanks in advance! I'll post the full cap into the C2 Tests thread when i've got it working :D (It's a very smooth inertia based platform movement with a ton of settings you can change whilst it's running :D)
B
1
G
2
Posts: 5
Reputation: 635

Post » Mon Feb 21, 2011 6:32 am

That is a bug.
Its somehow not being saved in the editor.
Testing shows you can set the variable instances at runtime using pick "nth", so that part works correctly.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Mon Feb 21, 2011 2:36 pm

Can you post a .cap of that not working properly on the tracker?
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Mon Feb 21, 2011 9:44 pm

Bug added.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Sun Jul 29, 2012 2:34 pm

how to find the modulus

say 25 mod 5 = 0
     25 mod 3 = 1

i am sorry I couldn't search much in the forum
B
6
Posts: 30
Reputation: 585

Post » Sun Jul 29, 2012 2:45 pm

This is a very old topic.

The modulus operator is %.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Sun Jul 29, 2012 5:55 pm

Closing as most of the information in this thread is now out of date. Look up expressions in the manual for the latest information.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Previous

Return to Construct 2 General

Who is online

Users browsing this forum: erandi1984 and 14 guests