Array index number into objects

0 favourites
  • 4 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • 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!

  • 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' behaviour

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Awesome! Works a treat! Thanks a bunch.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)