How to remove value from loopindex

Get help using Construct 2

Post » Tue Apr 18, 2017 6:17 am

I have created a box using loopindex
Now i want to remove 1 random box of right side wall
I could I do this
Image
Image
B
64
S
39
G
46
Posts: 656
Reputation: 32,728

Post » Tue Apr 18, 2017 6:39 am

What so hard about it, you can execute that using trigger once within loop for. Add sub event or separate event. Once box amount reached the last loop index, pick random box then destroy it.
ImageImage
B
108
S
49
G
23
Posts: 783
Reputation: 22,611

Post » Tue Apr 18, 2017 6:39 am

LOL, I'm sorry but your questions are at times looks more like a quiz.

Does the boxes have any variable (like position)? How do you draw the boxes? Does the width and height pre-determined? Could you just pick boxes with X coordinate and select random(5)?
B
33
S
10
G
2
Posts: 46
Reputation: 3,063

Post » Tue Apr 18, 2017 8:18 am

@alextro
i made this box using below events
Image
Now how can i remove 1 box from right side or bottom anywhere randomly
Image
B
64
S
39
G
46
Posts: 656
Reputation: 32,728

Post » Tue Apr 18, 2017 9:04 am

Do a thing like this for example:
Image

Oops you don't need stop loop.
ImageImage
B
108
S
49
G
23
Posts: 783
Reputation: 22,611

Post » Tue Apr 18, 2017 9:26 am

This is what I think the easiest way:
- add instance var to the boxes to indicate its position
- pick boxes at position of your choice
- pick random(boxes.pickedcount) nth box
- destroy box

Demo: https://www.dropbox.com/s/fmusqnu88io24il/boxes.capx?dl=1

There another way that I was thinking without instance variable, but I think it will require significantly longer code (using array, sorting, etc).

Note that in the way you are creating the boxes, the 4 corner boxes are actually double (2 boxes on top of each other), each belong to one side.
B
33
S
10
G
2
Posts: 46
Reputation: 3,063

Post » Tue Apr 18, 2017 9:53 am

alextro wrote:Do a thing like this for example:
Image

Oops you don't need stop loop.


Black screen confusing me on their seperation

subevent or bottom event or merged event
Image
B
64
S
39
G
46
Posts: 656
Reputation: 32,728

Post » Tue Apr 18, 2017 10:06 am

It just 2 separate events, first event consist of 2 conditions, second event consist of 3 conditions
ImageImage
B
108
S
49
G
23
Posts: 783
Reputation: 22,611

Post » Tue Apr 18, 2017 10:25 am

I made events in new layout
it working it made 1 row
but when i applied same on my layout then its not happening
Image
B
64
S
39
G
46
Posts: 656
Reputation: 32,728

Post » Tue Apr 18, 2017 11:54 am

Not sure how you exactly create/destroy them.

tmntppn's example works perfect because event 9 is actual a new 'root event'
If you create and destroy in the same event, and if you 'pick' those that you want to destroy in that same event, then you might suffer from that 'unable to pick newly created objects before the next 'root event' thingy.

You have 2 options.
1/ Or, do not create the one that you initially want to destroy.
2/ Or. Destroy in a new root level.

For method 1, you need 2 local variables. Initiate them before the loop that creates things.
1 local that you give a random variable in the range 0 to 3. 0 = top ... and so on.
1 local variable that gets a random index, in the range depending on if you make a horizontal or a vertical row.

Now, if loop index it matching the random index and if that first random is matching top,left,right or left ... do not create that block.


For method 2, you can do exactly what tmntppn suggested. A new root event.
Pick all blocks with 'pos' = choose("left","right","top","bottom")
Pick a random from that picklist, destroy it.

Another problem that i see is this. You might be using a loop to create more then 1 of those 'rooms'. (also a gamble). So you have ...

Loop for x rooms
__Loop for up
__Loop for down
__Loop for right
__Loop for left

Now you cant escape the 'room loop' to a new root level to destroy as you want. I can imagine.
Then i suggest to just not create them.

Here is an updated version of tmntppn's example for method 2 (destroy in new root level event)
https://www.dropbox.com/s/quj1lilua3ve4 ... .capx?dl=0
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Next

Return to How do I....?

Who is online

Users browsing this forum: AllanR, Artcadev and 13 guests