How do I create array depended objects

Get help using Construct 2

Post » Sat Mar 18, 2017 3:13 pm

Hello
How can i create or assign existing objects accordingly to array.
For example i have an array which has 3 cells called red and 3 cells called green and accordingly i want to create 3 red sprites and 3 green sprites or assign existing red and green sprites.
How can I do it?
B
5
Posts: 6
Reputation: 237

Post » Sat Mar 18, 2017 7:40 pm

please clarify what you are trying to do.

seems like you need to do a For Each on the objects, if they don't exist then Create sprite.

what are you assigning to the sprites?

when you say you have an array that has 3 cells called 'red'.. I don't understand.

do you have an array like this?

X(0) = "red"
X(1) = "red"
X(2) = "red"
X(3) = "green"
X(4) = "green"
X(5) = "green"

or is your array like this?

X(0) (0) = "red"
X(0) (1) = "green"
X(1) (0) = "red"
X(1) (1) = "green"
X(2) (0) = "red"
X(2) (1) = "green"
B
88
S
29
G
14
Posts: 1,158
Reputation: 15,011

Post » Sun Mar 19, 2017 7:46 pm

Hej jobel doesn't matter what array do a have
the question is how can I assign cells in array to create objects?
B
5
Posts: 6
Reputation: 237

Post » Sun Mar 19, 2017 8:37 pm

well it matters what information is in your array.
ediman wrote:how can I assign cells in array

assign cells? do you mean, add to the array?

use Push or Insert

https://www.scirra.com/manual/108/array

and I would highly recommend doing this tutorial

https://www.scirra.com/tutorials/307/ar ... -beginners
B
88
S
29
G
14
Posts: 1,158
Reputation: 15,011

Post » Tue Mar 21, 2017 7:44 am

I know these tutorials and i know how to create cells. My question is how to create objects based on array.
B
5
Posts: 6
Reputation: 237

Post » Tue Mar 21, 2017 10:01 am

When creating an object, you can set its UID as value of a cell.
This way, if you know what your cell is supposed to be (for example X2 is supposed to be red) the UID contained at Array.at(2) will be of a red sprite.
(in the event where you Create object Sprite, you set Array X 2 to Sprite.UID)

Your sprite can be red by either being an instance of a Sprite that only contain an animation frame Red, or the instance of a Sprite that is set to animation frame Red and whose animation is 0.
Depending on what you are attempting to do with your Sprite later on, one or the other solution may be more appropriate.
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,319
Reputation: 87,487


Return to How do I....?

Who is online

Users browsing this forum: RetrocadeMedia, sebrosen, Yahoo [Bot] and 31 guests