"Pick another instance" or something like that

0 favourites
  • 7 posts
  • Hi. I'm at a loss with this.

    Suppose I want the player to click a Sprite1. When they do, a line is drawn from this clicked Spirte1 to another instance of Sprite1 (provided there is one), and if there are any more instances then the line is further drawn to them.

    The drawing of the line itself is not the problem, the problem is determining where to draw it.

    What i need is something like "pick another instance" or "pick random instance excluding the currently picked one", so the logic would go like this:

    Sprite1 clicked --> save coordinates of Sprite1 into a variable --> pick another instance of Sprite1 --> draw a line between the variable coordinates and the Sprite1 --> repeat for as long as tere any more instances.

    The order doesn't matter, as long as the first instance is the clicked one.

    So I would like to end up with something like in the picture:

    <img src="http://i39.tinypic.com/mr3a89.png" border="0" />

    Any ideas appreciated.

  • instance variable drawn=0

    on click: save x and y in 2 variables, set drawn=1, call function "draw"

    function "draw":

    pick object drawn=0; pick random instance: draw line from saved x and y to sprite.x and y; save x and y coordinates in the variables again, call function "draw"

    you can also do that in a while loop ofc, stop condition could be related to sprite.pickedcount = 0 after picking drawn=0 or you pick drawn=0 and repeat it pickedcount times.

  • Great! Both answers work like a charm. I wasn't aware you could combine different instance picking options. Also, I didn't think to use recursion.

    Thanks a lot!

  • I don't really know WHAT recursion IS. LOL I'm about to find out... *CLICK*

  • blackhornet - I think I'm following the logic in your capx...

    1. Bee object instance is clicked

    2. For EACH Bee in the Family, set the NextUID family instance variable to -1

    3. Call the Connect function with a parameter that plugs in the UID of the Bee that was clicked.

    4. On call of the Connect function...

    5. Pick the object that has a UID that equals 0 and set the NextUID value to UID of the object instance that was picked.

    6. Pick all instances of the Family whose NextUID value is equal to -1.

    7. From those selections, pick a random instance of the Family and set the UID of the Family to the Next instance variable of the Bee that was picked.

    8. Draw the line between the two objects.

    9. Call on the Function again and run it for all other instances of the Family whose UIDs are 0.

    How'd I do? I'm still not sure I fully understand the whole thing.

  • Try Construct 3

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

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

    5) Pick the object that has a UID passed into the function at index 0 and set the NextUID value to UID of the object instance that was picked. (Consider this the draw-from object).

    7) ... (Consider this the draw-to object).

    9) Call on the Function again, passing in the draw-from UID, and run it for all other instances of the Family whose NextUIDs are -1 (not used yet).

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