How to remove value from loopindex

  • I have created a box using loopindex

    Now i want to remove 1 random box of right side wall

    I could I do this

  • 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.

  • 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)?

  • alextro

    i made this box using below events

    Now how can i remove 1 box from right side or bottom anywhere randomly

  • Do a thing like this for example:

    Oops you don't need stop loop.

  • 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.

  • Do a thing like this for example:

    Oops you don't need stop loop.

    Black screen confusing me on their seperation

    subevent or bottom event or merged event

  • It just 2 separate events, first event consist of 2 conditions, second event consist of 3 conditions

  • I made events in new layout

    it working it made 1 row

    but when i applied same on my layout then its not happening

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

  • thanks tmntppn & 99instances2Go

    thanks for your great help

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)