[Resolved] Advice on random object location

Nishi

  • Posts: 114
Hey there! I'm trying to put 30 random items in each of these boxes. I've sorta started and kinda know what to do.



My idea is for each  actor to be randomly given a number, and then for that number to tell the actor where its location in the scene will be.

I'm mostly just curious how would you set this so that once a number/location is chosen for the actor, you can get that specific number removed from the list?
(I'm not even decided about whether I should go with numbers or lists... It looks like I can only generate random numbers, but I can only remove a number if it's in a list?)

Thank you for any advice!

« Last Edit: May 21, 2012, 01:11:13 am by Nishi »

Ryusui

  • Posts: 827
Well, I'd personally start with two lists, one empty, the other populated with all the actors. Then I'd choose a random entry from the second list, add it to the first, then splice it out of the second. Rinse and repeat until the first list is full and the second list is empty.

Then, if each actor absolutely has to know its place in the list, just run through the list and pass the index value to an actor value or one of the actor's behaviors.
In the event of a firestorm, the salad bar will remain open.

Nishi

  • Posts: 114
Well, I'd personally start with two lists, one empty, the other populated with all the actors. Then I'd choose a random entry from the second list, add it to the first, then splice it out of the second. Rinse and repeat until the first list is full and the second list is empty.

Then, if each actor absolutely has to know its place in the list, just run through the list and pass the index value to an actor value or one of the actor's behaviors.
Hi there thanks for the help! :D

I kinda get what you mean, I think:
So you'd think it would be best to put the actors in one list, have it randomly choose one from the list, determine its location, and then toss it in a second list? Then you repeat for the rest?
That sounds like a great idea. (: I'm just sort of not sure how you get Stencyl to pick a random item from the list...
There's that "Random number between 1 and 30" block I can use - that I guess I would somehow use in conjunction with the list functions?

Ryusui

  • Posts: 827
Right, but you'd choose "random number between 1 and length of [list of your actors]". Or "0 and length of [list of your actors] - 1". I can't recall off the top of my head if Stencyl treats lists as starting at 0 or 1.[/list][/list]
In the event of a firestorm, the salad bar will remain open.

Nishi

  • Posts: 114
Right, but you'd choose "random number between 1 and length of [list of your actors]". Or "0 and length of [list of your actors] - 1". I can't recall off the top of my head if Stencyl treats lists as starting at 0 or 1.[/list][/list]

That sorta thing I can handle, I think it starts at 1 but I'll figure it out either way.



I'm sorta confused on how to tell the program what I want. X3 I got the main sorta pieces around - the positions work when the actor is set to them... but my brain's melting I'm having trouble even describing what it is I want. ;__;

I think I can get an item number from the list like this...
[get item #(Random number between
  • and [3] from {List 2}]

But I still don't know how to link that list number with any actual information, like Setting the position X to __.

And I'm also not sure how I can refer to that number randomly taken from the list later on, like when I want to remove it...
[remove item #__ from {list 2}]
If I insert the same [random number...] part, I think it'll pick another random number. I'm guessing I should instead refer to that value as a number for the actor or... something...

Sorry I'm not sure this really helps explain my side of things at all. X3

Ryusui

  • Posts: 827
Calculate the X and Y coordinates based on the position value - or better still, just the position in the list.

Grid X is position value mod 6; grid Y is the floor of position value divided by 6. Each actor's X is therefore 34 + (100 * Grid X). You'll have to figure out the Y on your own; I don't have enough to go on.
In the event of a firestorm, the salad bar will remain open.

Nishi

  • Posts: 114
Sorry, I'm still struggling with this and feel bad for posting so much since I might not get much help, but I'm wondering if I'm getting closer. X3



I tried to simplify the matter, setting up the X and Y Coordinates of each actor directly works - but then when I try to pull something from the list, it doesn't work. If I'm able to do that, it seems like I should be able to get it to pick one at random, and then get rid of it. (I'm still unsure how to tell it to get rid of the same, specific random number though.)

I'm trying to get it to use the value of each list item as the number for the X and Y position. So like Item 0 is 34, Item 1 is 134, Item 2 is 234...

Does this look any closer? Or does anyone know if I'm not using lists correctly here?

NexusxAlpha

  • Posts: 157
Probably need some sort of algorithm to just get the positions.

Something like

when created
Repeat <number of items to add> times
create <actor> at x: <random number between<0 and number of positions> + gap between each position y: pretty much the same

As you can see, it's confusing, I've got a headache now.

Ryusui

  • Posts: 827
Okay. Did you create the randomized list of actors, like I told you to?

In that case, the code you need will look something like this:
In the event of a firestorm, the salad bar will remain open.

Nishi

  • Posts: 114
Hey there! Thanks again for the help everyone. I think I'll just close this thread.

I couldn't really wrap my head around the ideas written out, and with that last screenshot I'd search through Stencyl but I couldn't find those exact blocks, so I wasn't able to even really try it out myself. X3 I'm sorry!



I went with something more like this. I have a list for the x coordinates and the y coordinates separately. And I set a Number Attribute to a random number, and then take that number from the list before it goes and plucks another thing from the list.

I do have an issue I'm trying to work out with it because there are like 4 of the same for each x and y position on both lists, so it's possible for it to randomly pick the same location for two cards. So currently I've split up the lists into segments, so it won't be possible for it to pick the same location for different cards.
BUT I still want to make it completely random - the way I have it now, the x positions are always going to be the same for these, and only the y positions will be random. So I'll just need to do a bit more to find out how to get them both a bit more random, and I should be able to handle it on my own.

So thanks again for the help! Sorry that I just figured out my own sorta way, but that's a good thing around here too! :D

ShivaFang

  • Posts: 248
Because I love a thought experiment, and I haven't seen a solution I liked I figured I would tackle this in case someone else searches with the same question;

Set Number_Rows to the number of COLUMNS you have (yes, that was a bit of an oversight-oops) in this case 6.

Change the x100s in the 'set positions' at the end to the amount of pixels in between the top left corner of each box and the one next to it.  You may need to add or subtract a set value after multiplying to get things to line up the way you want.

If you need more randomness, change the 'x 2' at the top to 'x 3'

Untested, but should work.
Justin "ShivaFang" White
Aquamentos Games - The origin of challenging Strategy and Role-Playing Flash gaming!
Visit our Developer Blog and Google+ Page!

ShivaFang

  • Posts: 248
Changed the randomization - the first one could case the items near the top to not move at all  (It took a random element and moved it to the end). 

This one more sufficiently randomizes the list, because it takes the top element and puts it somewhere in the middle, then takes the bottom element and moves it somewhere in the middle.
Justin "ShivaFang" White
Aquamentos Games - The origin of challenging Strategy and Role-Playing Flash gaming!
Visit our Developer Blog and Google+ Page!

ShivaFang

  • Posts: 248
The bottom block of each got cut off of the screenshot.  It's "Increment Number_Count by 1"
Justin "ShivaFang" White
Aquamentos Games - The origin of challenging Strategy and Role-Playing Flash gaming!
Visit our Developer Blog and Google+ Page!

Nishi

  • Posts: 114
Haha, I'm glad this got other people randomly curious! Though, I'm confused where you guys are getting lines like this:

repeat [Number items x 2] times -- [current loop count]
I don't see Repeat ___ times -- ___ anywhere - is it just a new stencyl code?
Same for the little icon thing next to current loop count. It's more from the updated version, right?

Cause in that case I can't really try it I guess. X3 Or at least last time it did it wiped a all my behaviors and game stuff and I had to start one all over again. I've heard you can download multiple versions of stencyl on your computer though, but eh... X3
Sorry if that makes me outta the loop with new code!