How do I store coordinates in array with no repeats?

Get help using Construct 2

Post » Thu Apr 06, 2017 5:27 pm

Hi guys,

So I am spawning objects and setting their coordenates randomly, so far so good, but I don't want them to end up in the same place, therefore if the coordenates repeat, they should be re-rolled untill you find new ones.

Run the project in debug mode, so you can see the coordinates array filling up:

https://mega.nz/#!TBx3CCCR!BYYcxop2zC-Tok1pLwz2QwjBx_DflcYHK8ggFvrvteU

And here is what i am trying that's not working:

Image

Thanks!
B
26
S
8
Posts: 84
Reputation: 1,722

Post » Thu Apr 06, 2017 7:39 pm

I suppose you mean by 'coordinates' floor and room, not x and y.

There are only 4 floors and 2 rooms, total 8 possibility's. Can as well create them all 8 at once, in 2 little nested loops.
Give them an id, floor and room instance variable, and pick them randomly.

I dont understand your code.
Example: '&' means for strings what '+' means for numbers. '&' combines strings (ads a string tot a string). "a"&"b"="ab"
You never stored floor&room in the array, so you will not find it in there too.
You add 1 to guest number, even if that was an illegal combination.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu Apr 06, 2017 8:26 pm

You dont event need an array, you know.

https://www.dropbox.com/s/sxg0khhtic2iq ... .capx?dl=0
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu Apr 06, 2017 9:04 pm

99Instances2Go wrote:You dont event need an array, you know.

https://www.dropbox.com/s/sxg0khhtic2iq ... .capx?dl=0


Hey!,

Thanks for your replies. That's an awesome example, but I cannot set room instances in my game, I have to use floor and room coordenates.

I wil try to create all coordinates at the start as you suggest, and then assign them randomly as guests are created.
B
26
S
8
Posts: 84
Reputation: 1,722

Post » Thu Apr 06, 2017 9:24 pm

You can see the array in the debugger.

https://www.dropbox.com/s/x5xiilz6c6koe ... .capx?dl=0
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 17 guests