need help in loop

0 favourites
  • 14 posts
From the Asset Store
For Adventure, Action, Heroes, Sci-fi and Action-RPG games.
  • on start of the layout i have created 5x5 grid by using for loop

    later ON ANY KEY PRESSED i want to add values inside the instance variable using loop

    I know i can add this "On created". But i want to add numbers in variables using for loop. please see screenshot to see what i want to do

    0,1,2,3,4

    0,1,2,3,4

    0,1,2,3,4

    0,1,2,3,4

    0,1,2,3,4

    i want to put these values in 5x5 instance variable

    Tagged:

  • In your case instead of the for each you could use:

    + System: Pick Box instance (LoopIndex("y")-1)+(LoopIndex("x")-1)×5

    It would be easier if you would use zero-based numbering an the x and y loop in the correct order.

    + System: On start of layout
    -> Box: Destroy
    ----+ System: For "y" from 0 to 4
    ----+ System: For "x" from 0 to 4
    -----> System: Create object Box on layer 0 at (LoopIndex("x")×100+200, LoopIndex("y")×100+200)
    
    + Keyboard: On Space pressed
    + System: For "y" from 0 to 4
    + System: For "x" from 0 to 4
    ----+ System: Pick Box instance LoopIndex("x")+LoopIndex("y")×5
    -----> Box: Set values to LoopIndex("x")
    
  • hi Asmodean

    can please explain me how this line works

    System: Pick Box instance (LoopIndex("y")-1)+(LoopIndex("x")-1)×5

  • One more thing i want to do

    On 5x5 grid i put variable values

    0,1,2,3,4

    0,1,2,3,4

    0,1,2,3,4

    0,1,2,3,4

    0,1,2,3,4

    Now i added another object "x" (8 copies) over the grid randomly

    (see x position over grid)

    0,x,x,x,4

    0,1,2,3,4

    0,1,x,x,4

    X,1,2,3,4

    0,1,2,x,x

    Now i want to add values to instance variable of object "x"

    0,0,1,2,4

    0,1,2,3,4

    0,1,0,1,4

    0,1,2,3,4

    0,1,2,0,1

    I hope you understand

  • Now i added another object "x" (8 copies) over the grid randomly

    (see x position over grid)

    0,x,x,x,4

    0,1,2,3,4

    0,1,x,x,4

    X,1,2,3,4

    0,1,2,x,x

    Do you mean 8 new instances of the boxes or only change the values in the boxes?

    Otherwise it would be easier you store all your values in an array.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • create new object "Box2"

    All instance variable of "Box2" who are over the first row of "Box" will be value like 0,1,2,3

    same for "Box2" over second row of "Box"

  • Can you describe what you exactly want to archive? I think there is no easy way, at least for me. It may be easier with arrays and fill the values of the boxes from this arrays.

  • Let me explain you what i want to do. I have 2 Sprites "redBox" & "greenBox" and both have variable "value"

    I created redBox on 5x5 grid and set their variable to

    0,1,2,3,4

    0,1,2,3,4

    0,1,2,3,4

    0,1,2,3,4

    0,1,2,3,4

    after that i create "greenBox" randomly over the "redBox" i.e. 8 times

    see this image

    Now I want to set values to "greenBox' according to number of "greenBox" are over the each row of "redBox" for example: in above image 3 "greenBox" are in first row then value needs to be 0,1,2 and in third row there are 2 "greeBox" so value will be 0,1 and so on.

    this is what i am trying to do.

  • Do you want add the green boxes only once or several times? If it's several times, should the green boxes renumbered or the new one like the first ones?

  • green boxes be add several times

    yes they will be renumbered

  • Please have a look if that is what you want:

    drive.google.com/file/d/1me1cwmrzDtnOM-FAE5GoibfISsDD_l8F/view

    I can make a version with comments if needed.

  • oh! yes

    that's it

    I want to learn this code, So please I'll need your comments.

    Thanks

  • Take a look if this is helpful for you:

    drive.google.com/file/d/1RdgFdcvTxbylAMbEhIoASx7QPaRkD_ov/view

  • Thanks I'll start learning it

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