Problems with array

Discussion and feedback on Construct 2

Post » Sun Jun 21, 2015 8:11 pm

I intend to generate numbers randomly using array without repetition but sometimes I find a duplicate. I attached the script that I use to create aleatory numbers.

Thanks in advance

Image
B
74
S
13
G
3
Posts: 995
Reputation: 7,531

Post » Mon Jun 22, 2015 5:29 am

Maybe use int() instead of round() in round(random(0,arrayFrame.width)).
Using round() can cause frameArray to equal arrayFrame.width and trying to delete that index will have no effect.
B
91
S
31
G
103
Posts: 5,238
Reputation: 67,762

Post » Mon Jun 22, 2015 1:35 pm

Thank you, @R0J0hound

Living and learning (with the best). I made changes and I think that now everything is okay.

I've just one more doubt: Why when I use:

System >Set indexArray to int(random(0, arrayNumbers.Width))
numbers > Set text to arrayNumbers.At(indexArray)

I only get zeros (0)?

Only works if I use:

numbers > Set text to int(random(0, arrayNumbers.Width))

Edited: PS - @R0J0hound

I got a duplicate number again. So, it's not working. Do you have another suggestion?
B
74
S
13
G
3
Posts: 995
Reputation: 7,531

Post » Mon Jun 22, 2015 4:57 pm

If that's giving you zeros then the array may still be all zeros. Did you fill numbers into the array? The other way you used just gives a random number so you could get repeated numbers.
B
91
S
31
G
103
Posts: 5,238
Reputation: 67,762

Post » Mon Jun 22, 2015 5:03 pm

Hi @R0J0hound

I didn't fill the array. I've stipulated the width only. I need to fill the array with the 99 numbers before (Set value at 0 to "0", Set value at 1 to "1", ..., Set value at 99 to "99")?
B
74
S
13
G
3
Posts: 995
Reputation: 7,531

Post » Mon Jun 22, 2015 5:10 pm

No use a loop. ex:
Code: Select all
+--------------------+
|Start of layout     | set array size to (100,1,1)
+--------------------+
   |array: for each x| set array at array.curX to array.curX
   +-----------------+
B
91
S
31
G
103
Posts: 5,238
Reputation: 67,762

Post » Mon Jun 22, 2015 5:38 pm

R0J0hound wrote:No use a loop. ex:
Code: Select all
+--------------------+
|Start of layout     | set array size to (100,1,1)
+--------------------+
   |array: for each x| set array at array.curX to array.curX
   +-----------------+



Is this the correct way? "set value at array.curX to array.curX"

Now the event "numbers > Set text to arrayNumbers.At(indexArray)" is working! And now I can delete the array's number correctly.

Thank you so much, @R0J0hound
B
74
S
13
G
3
Posts: 995
Reputation: 7,531


Return to Construct 2 General

Who is online

Users browsing this forum: mekonbekon, RoboticPhoenix and 6 guests