Picking between instances

0 favourites
  • 5 posts
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • I'm making an RTS. UnitSprites need to check and modify each others variables to attack and track each other. My problem is that with the picking system, once I have picked one UnitSprite it excludes all other UnitSprites from the event, so I am unable to access or modify them.

    For example, I want UnitSprites to track each other by setting UnitSprite.TargetX to the current X position of the UnitSprite designated by UnitSprite.TargetUnitSpriteUID.

    But, when I loop through all UnitSprites, I can't pick TargetUnitSpriteUID because picking is inherited, and TargetUnitSpriteUID has already been excluded.

    What would be the least cumbersome way to set UnitSprite.TargetX to UnitSprite.TargetUnitSpriteUID.X?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • ( im a noob too) Sound like we need an option in the sprite part to when spawn unit have its own sprite name such as unitsprite 0 and so on number per unit on map. As i understand it C2 does not add in that part and automatically assume one for all. Im wondering if there is a code to randomize name between like say ten different name and ten different sprite unique name. as i understand RTS it is a battle of armys. You could do something like create your own grid mesh sprite and snap sprite via origin and image point in it and make it invisible. This is my best guess.

  • With a function maybe:

    +CONDITION
       -> UnitSprite: Set [b]TargetX[/b] to [i]Function.Call("getUnitX", Self.TargetUnitSpriteUID)[/i]
    
    +Function: On [b]"getUnitX"[/b]
    +UnitSprite: Pick by UID [b]Function.Param(0)[/b]
       -> Function: Set return value to [i]UnitSprite.X[/i]
    
  • Cheers ramones! That worked a treat, and that method will make a tonne of other things easier too. Much appreciated.

  • Dragoonblade, Construct 2 does give each object a unique name on startup, kinda. It gives a unique identifier (UID) number to each object that can be used to pick it.

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