How do I select a specific instance?

0 favourites
  • 10 posts
From the Asset Store
A set of retro 16-Bit Neon UI elements to make your menus pop!
  • I'm trying to create an animation to explain the TCP 3-way handshake with Packet sprites travelling between two servers.

    I have two instances of a sprite called Server.

    They have instance variables Name which is set to "Alice" for one and "Bob" for the other.

    I need to generate a Packet sprite at the Alice that travels to the Bob server.

    How do I reference a specific instance in order to get its coordinates?

    Tagged:

  • I would have the source instance create a packet object (and possibly record the source in an instance variable in the packet object), then have a separate event on packet created pick the proper destination instance by comparing instance variables ("Name") and apply whatever movement you have implemented based on the picked instance's coordinates.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • How do I select the source though? There are two instances of servers, I want the Alice server to create a packet and bullet it over to the Bob server.

  • Pick by comparison

    Pick the individual instances of an object type that meet a comparison. For example, it is possible to pick all instances where Object.X * 2 is less than Object.Y + 100, which is not possible with either the Compare X or Compare Y conditions.

    So in your case it would be Pick "Server" object by comparison self.Name="Alice" -> Spawn Packet

    Then

    On Packet created

    Pick "Server" object by comparison self.Name="Bob" -> Set Packet Destination to Server.X, Server.Y

  • Thanks, where is Self used though?

    I've got a sample app here:

    https://drive.google.com/file/d/1HVDavPvZL7RqqbPx_pWwbc34ibwN0bm5

    All I'm trying to get it to do is fire a projectile from left to right when 1 is pressed and right to left when 2 is pressed.

    I'm definitely missing some basic concept here.

  • Here you go. Changed the approach slightly, since I realized if you use "On Created", the target hasn't been set yet. Instead, I used a sub event with the "Pick all" system condition to reset the picked instances, then narrowed it down again from there.

    Also you might notice I used a different condition than the System-Pick by Comparison. In the object you can also compare instance variable. I'm actually not sure what the differences between these two methods of picking are.

    The other thing I changed was using the Tween behavior instead of Bullet, since you have a clear start and end point, Tween is probably more suitable.

    Sorry if my answer earlier was confusing, I can make more sense with an example to work with ;)

    dropbox.com/s/4fq7vaumlj9hkb5/example-Instances%20and%20Bullets.c3p

  • Thanks oosyrag,

    Still don't fully understand, but you've given me some things to work with there. Very much appreciated!

  • Why are the projectiles being created above the "Muzzle" image point though?

  • It looks like the Projectile object's origin point is not centered for some reason, so the visible projectile is offset.

    Edit: And if you want the destination to be the muzzle as well, you can change the tween target from Gun.X to Gun.ImagePointX("Muzzle") and the same for Y.

  • That was it, thanks oosyrag

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