[SOLVED] array of arrays for positions

0 favourites
  • 9 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • I am cautious about posting, because i feel it should be fairly easy to do this, but i just can't figure it out.

    I am spawning a number of sprites (between 1 and 10).

    I want them to spawn at specific locations so i am making an array (or a dictionary) to make a list of possible locations for them.

    The problem i have is how to populate that array.

    The data structure will be ;-

    (60,150),

    (60,265),

    (60,380),

    (180,120),

    (180,235),

    (180,350),

    (180,465),

    (280,150),

    (280,265),

    (280,380)

    I will then pick random items from the main array and delete the index after used.

    It is a fairground shooting gallery type game and i need to have the sprites (ducks) spawn on any of the three rows.

    Can anyone advise on how to do this... the manual goes into multidimensional arrays, but i can't see how to apply that here because the 2 numbers are always values, not keys.

    Any suggestions ? Or a better way to make a number of sprites appear but in pre-defined "allowable" places.

  • Sorry, I still don't understand your question.

    You need to populate this array? Should these locations be predefined on each level? Or are they generated on random?

    If predefined, you can read them from a file, say, using CSV plugin.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yes, they are predefined.

    I thought about loading them via JSON but it doesn't give me the structure i need.

    (the debugger shows 10 values in the array but they are all 0)

    The output should allow me to do the following;-

    index = random number from 1-10

    array[index][0 for x position]

    array[index][1 for y position]

    then i can delete that array index so its not used again.

    [EDIT]

    I have solved my own question with the above reply.

    Set Value at (0,0) to 60

    Set Value at (0,1) to 150

    Set Value at (1,0) to 60

    Set Value at (1,1) to 265

    etc

    I just need to do that for all ten positions.

  • Try this:

    Array Load from JSON   
    Copy/paste this string:
    "{""c2array"":true,""size"":[10,2,1],""data"":[[[60],[150]],[[60],[265]],[[60],[380]],[[0],[0]],[[0],[0]],[[0],[0]],[[0],[0]],[[0],[0]],[[0],[0]],[[0],[0]]]}"
    
    [/code:2ecaytek]
  • Thanks for that, i was trying to do something similar but i couldn't get the syntax right... that removes the need for all the set value statements.

  • You can use Browser.Log -> Array.AsJSON to get the correctly formatted JSON string. All you need to change is to double all quotation marks.

  • This works when i call it from On Start layout, but if i put it in a function eg: populatePositions and then call that from On Start Layout, it doesn't.

    How can i find out why that is?

    It doesn't work in it's own dedicated function, but as part of the 'nextLevel' function it works.

  • Is the function on the same event sheet? If it's on a different event sheet, you need to Include this event sheet.

    If this doesn't help, could you share your capx?

  • Yes, it is in the same event sheet, although i seem to have it working now. I think there must be some issue with saving / caching my browser.

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