Turret behavior and priority levels

For questions about using Classic.

Post » Tue Apr 19, 2011 1:31 am

I'm making a tower defense game and i'm using the turret behavior for it. It works just fine, but I want to add some more to it.
There's going to be some buildings that the player may build towers nearby to destroy, but I want the towers to give priority to walking enemies, so they will only shoot the buildings if there is no walking enemy in range


Black: building that is being shot by blue turret
Blue: will switch targets if red walks in range
Red: is higher priority than black

This is the "get target" event

Both walking enemy and building are in the "Enemy" family
"Items" family is the turret family

I tryed giving each enemy a "priority" variable, and tell turret to "pick Enemy with highest 'priority'", but that did nothing. It just locks on the building untill it's destroyed
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,129

Post » Tue Apr 19, 2011 4:24 am

It seems that the "Add target" action selects from all the "enemy" type not just the currently selected enemy.

A solution would be to add the object type of the selected object as a target instead of the family.
Edit the "Add Target" action and right click "object to target" and select use expression. Now you can choose an object by their OID (object id), which is different for each object type. Next type in "Enemy.OID". The "OID" expression with families returns the OID of of the actual object, not the family.
B
79
S
24
G
52
Posts: 4,724
Reputation: 39,711

Post » Tue Apr 19, 2011 5:10 pm

You say like this?


Still doesn't work (with and without the "pick with highest priority" event)

---

And I have another question. Why can't I create an object and set it's variables right after it's creation? (btw, i'm using families for this too)
If I have something like
[code:3kqhidbd]Every 1000 miliseconds > Create object by name "object"
> Set "family" "health" to 100[/code:3kqhidbd]
Then it will set the health of all "object" at once, not only the one just created
I have to set the health of the object's family because I don't know which object is being created, all I know is that it belongs to the family
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,129

Post » Mon Apr 25, 2011 3:05 am

bump
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,129

Post » Mon Apr 25, 2011 4:03 am

To your first issue: The 'Else'-event is not working. This is because it is a subevent of for each. 'Else' needs to be on the same level than the event you want to branch. That means, the targets never get cleared, just new targets added. You can't work with 'else' here. I would show you an alternative, but I am not sure, under what condition exactly you want to clear the targets.

To the second issue: Creating an object puts it on the SOL, instead of
Set "family" "health" to 100
just do
Set object('health') to 100
and the correct object will automatically be used. If the object is a sprite, then you're out of luck. Sprites are created at the end of a tick, you can't access a pv until the next tick. One way would be to store Sprite.OID or UID in a variable after having created it and do a check for that variable holding a value before that variable was filled with OID or UID. If it contains a value, select the object based on the OID or UID and set its pv. Just make sure those events are all placed before creating the object and storing its OID. The variable may be a pv or a global, but it must not be a pv of the newly created object.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Mon Apr 25, 2011 4:54 pm

I want to check for higher priority every time. So if the turret is shoting a low priority object and a high priority object comes in range, it should switch targets to the one with higher priority

2nd issue: well that sucks, but i've found a workaround for that, thx
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,129


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest