How do I populate randomly generated array?

Just started using Construct 2? Post your questions here

Post » Tue Jan 05, 2016 1:11 pm

Could someone please assist, either with guidance or a code sample?

If I generate an array with the code

Code: Select all
Set size to (random(4,11), random(4,11),1)


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

Image

with the "1"'s around the edges, and the "0"'s filling the rest ?
B
6
S
2
Posts: 34
Reputation: 512

Post » Tue Jan 05, 2016 8:37 pm

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)
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Jan 11, 2016 1:37 am

Trent123 wrote:Image
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
Code: Select all
Array.CurX=0|Array.CurY=0|Array.CurX=Array.Width-1|Array.CurY=Array.Height-1
=1

Action.....Array set value at XY ...X(Array.CurX);Y(Array.CurY);Value(1)
Image
B
64
S
23
G
7
Posts: 1,482
Reputation: 10,825


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 4 guests