Picking between instances

Get help using Construct 2

Post » Wed Feb 27, 2013 10:01 pm

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?
B
3
Posts: 3
Reputation: 306

Post » Wed Feb 27, 2013 10:26 pm

( 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.
B
7
S
2
G
3
Posts: 58
Reputation: 2,284

Post » Thu Feb 28, 2013 12:04 am

With a function maybe:
[code]
+CONDITION
   -> UnitSprite: Set TargetX to Function.Call("getUnitX", Self.TargetUnitSpriteUID)


+Function: On "getUnitX"
+UnitSprite: Pick by UID Function.Param(0)
   -> Function: Set return value to UnitSprite.X
[/code]
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,000

Post » Thu Feb 28, 2013 3:19 am

Cheers ramones! That worked a treat, and that method will make a tonne of other things easier too. Much appreciated.
B
3
Posts: 3
Reputation: 306

Post » Thu Feb 28, 2013 3:22 am

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.
B
3
Posts: 3
Reputation: 306


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 23 guests