Checking available space
sevek
Member, PRO Posts: 30
Hi guys.
So, I need a suggestion from you guys.
Imagine, a rectangular block(Master block) that stretches from top to bottom.
A smaller block is spawned at a random height inside of the master block.
Then I would like to spawn another smaller block if there is an avaiable space in the master block.
(For example, if the first block is spawned too close to the top, then there is no space avaialble, thus the second block is only spawned below the first one).
How could I check if there is an available space ?
Thank bunch!
Comments
Hi @sevek
With a table. Basically, say you can fit 10 spawn blocks into your master block, make a table with 10 rows. Make the column integer, fill up the column cell values with all 10 possible y coordinates of your little blocks.
Then make an game integer attribute, call it Count, set it to the same number as the rows, in this case, 10. Another game integer attribute, called Rand.
In the button that initiates a new spawn, put:
Remember that if you want to keep on repeating the whole thing, you need to make a 2nd table, and before you start each time, use the Copy Table behaviour to copy into the second table, then reference this second table in the above rules.
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
Thanks gyroscope!
I will implement this! You are awesome!!
Cheers!
You're very welcome.
I've made a small adjustment ('cos I made a small oversight... ) Thought it best to point it out in case you miss it - with the Change Attribute Rand, you'll see it's now:
Change Attribute Rand to random(1,Count)
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
Thanks!
I am working on it now and will let you know how I did it!
Thanks!
Just quick questions.
what would be the purpose of the following rules?
Add/Remove Row YourTable
Action: Remove Row At Index Rand
Change Attribute Count to Count-1
Just quick questions.
what would be the purpose of the following rules?
Add/Remove Row YourTable
Action: Remove Row At Index Rand
Change Attribute Count to Count-1
Hi, first to say, for your info, I've now added When touch is pressed to the rules for the button.
The system is as follows:
First time, a random number between 1 and Count(10) is chosen, let's say it's 6.
Now the y coordinate in row 6 of the table for the spawned actor is used.
Next, that row 6 is removed (using the Add/Remove Row behaviour), and the rows below it all move up one.
Count is made to be Count - 1, so Count is now 9
2nd time, a a random number between 1 and Count(9) is chosen, let's say it's 3.
Now the y coordinate in row 3 of the table for the spawned actor is used.
Next, that row 3 is removed (using the Add/Remove Row behaviour), and the rows below it all move up one.
Count is made to be Count - 1, so Count is now 8
etc.... until Count is zero.
Because the rows are deleted one by one, that's why I suggest deleting these rows in a copy of the "master" table; that way, when you reset all the attributes to their start values, you copy the table again and use that copy, leaving the master table intact for the next time.
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
Oh I see.
It is to avoid overlapping.
For the game that I am designing, a new master block is spawned every 0.8 second and the old one is destroyed, which I have the codes.
Thank you so much for spending time to explain it thoroughly.
Really appreciate it! =D
Hope you are enjoying the weather!
Cheers!
That's right!
Glad it helped; and yes, it's been lovely here today though I must mention I'm not a great "sun worshipper"! Cheers.
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps