Array Question...

Get help using Construct 2

Post » Fri Mar 02, 2012 10:06 pm

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
B
192
S
6
G
7
Posts: 213
Reputation: 10,178

Post » Fri Mar 02, 2012 10:09 pm

I don't think there is an OR statement.
B
11
S
3
G
2
Posts: 110
Reputation: 2,410

Post » Fri Mar 02, 2012 10:18 pm

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.
B
192
S
6
G
7
Posts: 213
Reputation: 10,178

Post » Fri Mar 02, 2012 10:22 pm

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

Sorry I couldn't have been of help.
B
11
S
3
G
2
Posts: 110
Reputation: 2,410

Post » Fri Mar 02, 2012 10:40 pm

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
B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755

Post » Fri Mar 02, 2012 10:48 pm

[QUOTE=R0J0hound] 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[/QUOTE]

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...Zetar2012-03-02 22:49:20
B
192
S
6
G
7
Posts: 213
Reputation: 10,178

Post » Fri Mar 02, 2012 11:56 pm

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 :D)

arrayRandom.capx
Last edited by Yann on Sun Sep 14, 2014 9:27 pm, edited 1 time in total.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Sat Mar 03, 2012 12:55 am

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.

Zetar2012-03-03 01:10:15
B
192
S
6
G
7
Posts: 213
Reputation: 10,178

Post » Sat Mar 03, 2012 12:58 am

Yann - I got an error while trying to open that cap. Something about the Xtext variable.
B
192
S
6
G
7
Posts: 213
Reputation: 10,178


Return to How do I....?

Who is online

Users browsing this forum: ETgirl79, semaso and 22 guests