aymankoo wrote:I have a background which have many collision rectangles (something like isometric game example). now I want randomly yo create object where the object will be created only inside the allowed move area so the player can collect it. How I can achieve this.
You can achieve it this way:
At the beginning of the scene iterate along all the collision rectangles objects with a For Each loop, in the For Each loop create an ID variable for each collision rectangle and put a number in it (you know, serializaed... 1, 2, 3, 4, 5... 98765, etc). When you want to create an object just pick up a random number with the RandomInRange() event and then iterate trough all the collision rectangles again searching for the one with that ID. then create the collectible at the coordinates of the collision rectangle with that specific ID.
First I cannot find a way to iterate for each collision rectangle. Then if I could do that still the how to avoid creating the item outside the collisions.
as you said "create the collectible at the coordinates of the collision rectangle with that specific ID" this will create the item inside the collisions not outside.
Conditions: Conditions to create the Object
Actions: Create Object at Random(800) ; Random(600)
While Object collides with Background:
Conditions: No conditions
Actions: Do = Random(800) ; Random(600) to the position of Object
I.e. keep changing the position to a random one until it doesn't collide
As always, make sure the while condition can fail or you'll end up with an infinite loop. In this case there should be a good range to be in a non-colliding position.
But you can give it a try, if it doesn't work you'll have to rethink it, instead adding obstacles and picking free spaces randomly you can create spawn objects, pick a random spawn object and create your object there