Array index number into objects

Get help using Construct 2

Post » Fri Jan 10, 2014 11:05 am

Dear Construction-twoians,

Arrays. Awesome stuff. Just started using them and am running into issues left and right. I have a hard time understanding them fully atm, but hopefully some of you can lend a helping hand.

The array:

I am using a 1d array:

"Characters": 6 rows on X. Each X holds the name of a character class:

0: Warrior 1: Knight 2: Thief 3: Hunter 4: Mage 5: Wizard.

The objects:

0: Player spawning point sprite

1: Player collision box (Platformer behaviour)

2: Warrior sprite

3: Knight sprite

4: Thief sprite

5: Hunter sprite

6: Mage sprite

7: Wizard sprite

If the player clicks on one of these sprites, the array will select the relevant value (click warrior and the array will choose 0 etc), the next layout (an actual level) is loaded, the "player collision box" is created on the "player spawn point".

My question is: how can I attach the sprite, chosen by the array, to the "Player collision box"?

In other words: how do you use an array's index number and use it to spawn/create/set position of an actual object?

Thanks in advanced, I am in your hands!

Posts: 51
Reputation: 627

Post » Fri Jan 10, 2014 12:55 pm

Sounds like something you don't necessarily need an array for..
are the characters separate objects or are they separate animations inside one object?

assuming they are separate objects.. you can put them all in a family like 'Character'
and give this family a variable called 'name', and enter the name for each, warrior, knight etc

have a global variable ChosenCharacter

on Character clicked > set ChosenCharacter to Character.Name

and then upon loading the level:

Create Collision box at spawnpoint
if ChosenCharacter = Warrior --> Create Warrior..
if ChosenCharacter = Knight --> Create Knight..
if ChosenCharacter = Thief --> Create Thief..
if ChosenCharacter = etc etc --> Create etc etc..

all these repeated events is okay considering you don't have *too* many classes, but if you decide to add a lot more, there are two things you could try to condense this into just one event..
either have all the characters contained in one animation (it's why i asked earlier) and instead just
--> Create Character
--> set animation to ChosenCharacter
OR.. you could check out the 'nickname' plugin by searching the forums here. It allows you to assign nicknames to objects and create an object by it's nickname. (if your characters have numerous animations, I would recommend using this instead)

anyway, that's all optional

after you've created the Collision and Character, there are ways you can link them, but if you want to keep it simple for now you can just use the 'pin' behaviourkeepee2014-01-10 13:01:35
Posts: 469
Reputation: 4,683

Post » Mon Jan 13, 2014 8:45 am

Awesome! Works a treat! Thanks a bunch.
Posts: 51
Reputation: 627

Post » Tue Jan 28, 2014 4:46 am

Dear Construct 2Woanians,
            i have a problem with my array construction, i have 32
        animation frames, and i can't randomized it, Hope
        u can help me in some other way to make animations
        randomized it... i follow some ways of ms.kittiewan in
        tableau Construction.
Posts: 1
Reputation: 152

Return to How do I....?

Who is online

Users browsing this forum: fbarraza28 and 4 guests