How do I do this?

  • I want each object (they are sprites in a tile formation) to find the instance variable of another object (next to it) and act according to the value. How would I do this ?(a great example would be how a tile in minesweeper knows if it has a mine next to it.)

  • 'each object' = objectA

    'another object' = objectB

    'next to it' means (i think) from all objects that are some distance away, the most close one

    Add behavior Line-of-sight to objectA

    Give it the range that you want

    System > For each objectA

    (objectA) Has LOS to object (objectB)

    (objectB) pick nearest(objectA.x objectA.y)

    ____ System > compare 2 values ... compare the instance variables

    ______________act

  • This is great, but the object (a) only "looks" at the instance variables of objects (all) that are to the side of it. I also need objectA to "look" at the inst. var. of objects (all) on its diagonals...

    This has straightened me out a lot. Thank you.

  • This would work (I think) assuming that the surrounding objects are of the same type (object):

    Let's assume your objects are in a grid tile formation, with each object being the same dimensions as a tile.

    That means that any one object has neighbours in its 8 surrounding squares, including diagonals.

    We pick instance A, using whatever pick method you want (e.g. touch, a step function, etc)

    Set its x and y coordinates to a pair of local static variables, l_x and l_y,

    Set its width and height to a pair of local static variables, l_w and l_h

    We can now check each for each object in each direction around object A by using a pair of nested "for" loops.

    Add these conditions in the next event below the pick event (not as a sub event):

    System|For: "x" from -1 to 1
    System|For: "y" from -1 to 1
    System |Compare two values: If loopindex("x") does not equal 0
    System |Compare two values: If loopindex("y") does not equal 0
    System |Pick instance of objectX at (l_x+loopindex("x")*l_w,l_y+loopindex("y")*l_h) 
    [/code:2prskup1]
    
    Make sure they are all in the same event.
    The first condition is going to check the tiles to the left and right;
    The second condition is going to  check tiles above and below;
    The next two conditions exclude the tile you initially selected, where instance A is situated;
    The last condition picks the object instance that is a set coordinate distance from instance A by taking its current (x,y) position and either adding or subtracting its height or width .
    
    You can then grab whatever instance variable you want from the selected instance in the action e.g.:
    
    Set global variable checkThis to instance.myCheckThis.
    
    It gets trickier if you have different object types to check, but the same basic principle applies.
    
    Hope that makes sense!
  • Could you please give me a screenshot of [quote:1wb53r53]

    System |Pick instance of objectX at (l_x+loopindex("x")*l_w&,&l_y+loopindex("y")*l_h)[/code:1wb53r53]
     (Is it nth instance, or all instance, or etc?)
    
    I think I have the wrong Pick Instance for this...  Also it won't let me insert a comma, so I stopped. (It's surrounded by &'s.)
    
    I understand everything else, and you will be listed in "special thanks" when my program is done. (with the other person who commented on this post)
    
    Here's what I have so far: 
    [img="http://i65.tinypic.com/16ae2xc.png"]
    
    The tiles [u]are[/u] objects (sprites).
  • Loopindex("x") * 20 = relative to LocalX

    ... means it should be ... LocalX + Loopindex("x")

    The conditon = System > Pick overlapping point > with ... x = LocalX + Loopindex("x") and y = LocalY + Loopindex("y")

  • I dont under stand the 'Pick All',

    currently it picks all and the sets LocalX and Y to the instance with IID=zero

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • PixelByPixel

    Hi there, you need to use Pick Overlapping Point, not Pick by Evaluate.

    And also your local variables should only be referencing the starting object, i.e. the object in the middle - you don't need to pick all.

  • PixelByPixel

    Had to fiddle around with the events a bit (the check for loops not equalling zero was broken, but this works:

    https://www.dropbox.com/s/jim9fwrlhqtbf ... .capx?dl=0

  • 99Instances2Go

    @mekonbekon

    Thank you so much!

    Would you like to beta-test my game (when available, looking at 1-2 weeks)?

    It is a multiplayer version of

     Conway's Game Of Life [/code:z7y7n4i5] ([url=https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life]https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life[/url])
    
    You don't have to, but the choice is yours. Thank you again.
    
    *EDIT*
    In the program that you sent me, what if I wanted the touched object to count how many shapes are around it? Is it a simple addition, or is the code all wrong?
  • PixelByPixel Certainly would, been a fan of Conway's Game of Life since way back - I get why you wanted the grid check now

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