How do I populate randomly generated array?

0 favourites
  • 3 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Could someone please assist, either with guidance or a code sample?

    If I generate an array with the code

    Set size to (random(4,11), random(4,11),1)[/code:3fo36ddv]
    
    how can I ensure that, regardless of array size, the array is always populated as follows:
    
    [img="http://s17.postimg.org/9yjw9oz3z/array.jpg"]
    
    with the "1"'s around the edges, and the "0"'s filling the rest ?
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I guess what you'd do is first set a (local) variable to the random number (you should use floor(random(4,12), because you don't want floating numbers..

    You could then use those variables to get the last lines in the x and y direction (the first is ofcourse always 0)

  • how can I ensure that, regardless of array size, the array is always populated as follows:

    with the "1"'s around the edges, and the "0"'s filling the rest ?

    If I understand correctly...

    Array For each XY element

    ....System:Compare two values

    Array.CurX=0|Array.CurY=0|Array.CurX=Array.Width-1|Array.CurY=Array.Height-1
    =1[/code:yaw5a9i8]
    Action.....Array set value at XY ...[b]X[/b](Array.CurX);[b]Y[/b](Array.CurY);[b]Value[/b](1)
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)