What's the difference?

Discussion and feedback on Construct 2

Post » Sat Jan 11, 2014 4:45 am

OK, I'm not that bright but I don't understand why this works:

Set Position to: choose(spawn1.X,spawn2.X,spawn3.X)

But this doesn't:

Set Position to: spawn(choose(1,2,3)).X

In my mind the output should be the same. Can anyone enlighten me, please?
B
60
S
20
G
56
Posts: 1,077
Reputation: 35,941

Post » Sat Jan 11, 2014 6:27 am

"spawn"&choose(1,2,3)&".x"
B
10
S
2
G
1
Posts: 202
Reputation: 1,545

Post » Sat Jan 11, 2014 6:37 am

@Noncentz705 Set Position to doesn't accept strings like that either, unfortunately. Believe me, I've tried. :)
B
60
S
20
G
56
Posts: 1,077
Reputation: 35,941

Post » Sat Jan 11, 2014 7:16 am

Yeah, sorry about that. One solution may be to place the objects inside a family. Then you just pick a random instance in the family and then position your object to the selection.

Noncentz7052014-01-11 07:25:10
B
10
S
2
G
1
Posts: 202
Reputation: 1,545

Post » Sat Jan 11, 2014 11:44 am

"Choose" is a value of either text/number format whereas when using the "Create" action expects/let you spawn an instance of an object type.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
284
S
109
G
91
Posts: 7,317
Reputation: 87,483

Post » Sat Jan 11, 2014 1:44 pm

The second form uses object expressions. See the section on object expressions in the manual.

The expression you gave will pick either 1, 2 or 3, and use that as an index ID (IID) to the 'spawn' object, and return that instance's X co-ordinate. If this is not a syntax error then there must be a different kind of object in your project called 'spawn', so you are using the X co-ordinate of an entirely different object. Your first example uses dfferent object types with different names (spawn1, spawn2 and spawn3) but the second expression will never look at those object types.

In short, it's probably working correctly but you have misunderstood what the expression is supposed to do.
Scirra Founder
B
387
S
230
G
87
Posts: 24,249
Reputation: 192,240

Post » Sat Jan 11, 2014 4:16 pm

Thanks. I probably shouldn't have posted this in the first place since I was able to achieve what I needed to the first way. I was just curious as to the difference. I understand now. Thank you.
B
60
S
20
G
56
Posts: 1,077
Reputation: 35,941


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 9 guests