Array Question...

0 favourites
  • 9 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • So, I have an array 10,10 that I want specific numbers to populate in. I have created a text box grid to de-bug this issue. Why are the values all staying at 0?

    I am using the | symbol to act at an OR, (am I doing that right?)

    http://www.box.com/s/zfcovcsvvvvtkx184inv

  • I don't think there is an OR statement.

  • I am using for events to populate x and y of the array. Maybe it doesn't like the choose function...   I am pretty sure the | symbol can be used as an OR function. It says I can in the Manual.

  • Must've been added since the last time I took a look at it. :P

    Sorry I couldn't have been of help.

  • Array at (Loopindex("X")-1, Loopindex("Y")) = 0|4|9|12

    is exactly the same as

    Array at (Loopindex("X")-1, Loopindex("Y")) = 1

    The "0|4|9|12" evaluates down to "1".

    To do what you intended use system compare:

    (Array.at(Loopindex("X")-1, Loopindex("Y"))=0)|(Array.at(Loopindex("X")-1, Loopindex("Y"))=4)|(Array.at(Loopindex("X")-1, Loopindex("Y"))=9)|(Array.at(Loopindex("X")-1, Loopindex("Y"))=12) = 1

  • Array at (Loopindex("X")-1, Loopindex("Y")) = 0|4|9|12

    is exactly the same as

    Array at (Loopindex("X")-1, Loopindex("Y")) = 1

    The "0|4|9|12" evaluates down to "1".

    To do what you intended use system compare:

    (Array.at(Loopindex("X")-1, Loopindex("Y"))=0)|(Array.at(Loopindex("X")-1, Loopindex("Y"))=4)|(Array.at(Loopindex("X")-1, Loopindex("Y"))=9)|(Array.at(Loopindex("X")-1, Loopindex("Y"))=12) = 1

    Thanks ROJOhound, but I am still confused. I am trying to populate the Array at loopindex("x"), loopindex("y") with (0 or 4 or 9 or 12 or whatever numbers I supply) randomly picked.

    So if I understand you, | will give you a 0 or 1 as true or false? Mabey my example is way off base...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Array are 0-based so the for loop should spanned from 0 to width-1 and height-1

    Also it would help to know why you want to use these number and also yeah the | operator is a OR used with a boolean type of variable.

    Any number except 0 returns TRUE when they are read as boolean.

    0 returns FALSE.

    So when you write

    0|4|9|12

    it's as if you were writing

    FALSE or TRUE or TRUE or TRUE

    which returns TRUE and TRUE into an integer is 1.

    But even if I were to read your code thinking as "this value equal 0 or 4 or 9 or 12" I really don't understand the meaning behind it.

    And last, your text wasn't used the right way to display your array values. Each time you were picking all your text objects. And the even wasn't at the proper nesting level.

    Check that out (I made some uneeded changes like using local variable x and y as loopindex 'cause I like shortcuts )

    arrayRandom.capx

  • OK, sorry everyone. After re-reading the thread, I can see how everyone is confused at what I want. I will explain it better:

    Like a few others around here, I am attempting to create a maze of sorts using an array. However in my case each "block" of the maze/array is not solid, but open. Think of them as rooms that will each spawn walls according to their code in the array position.

    But at this point all I need is to populate the array with numbers. Each number is a code for a set of walls that will spawn on the room block.

    So, I will need to know where I am at specific positions in the array, to then be able to suggest the correct random code numbers that will spawn appropriate walls. The theory goes like this:

    Start of Layout

    ->find where you are in Array

    -->If at upper left corner set array.at(current x,y) One of these values (0,5,9)

    -->If at top of Array set array.at(current x,y) One of these values (1,3,8,7,12)

    -->If at right of array set array.at(current x,y) One of these values (2,...)

    -->If at left of array set array.at(current x,y) One of these values (16,...)

    --> if at bottom...

    --> if in middle somewhere...

    The sets of numbers correlate with the position. So with above codes, 0,5,9 are block walls leaving exits east and/or south, (from the top left corner of the map). (codes above are not actual. I am not looking at my code list...)

    That is what I am trying to achieve. So now does my cap make more sense?

    P.S> Thanks Yann and Rojohound for trying.

  • Yann - I got an error while trying to open that cap. Something about the Xtext variable.

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