Counting owned villages in capture event.
Moderator: Forum Moderators
Forum rules
- Please use [code] BBCode tags in your posts for embedding WML snippets.
- To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Counting owned villages in capture event.
Each time side 1 captures a village, I want to count how many villages side 1 currently has. I can't keep a running total myself, because I won't get events when side 1's villages are recaptured by other sides. So, the idea is to store locations based on the terrain type "*^V*", count the hexes that are on side 1, and we're done.
Until I try it in a capture event. The capture event only appears to give me access to one village, ie, the village just captured.
Here's the code:
" ownedvillagecnt " is always returned with the value 1, and sure enough, it's only got the village captured. How do I count owned villages in a capture event? Is this designed behavior or a bug or am I doing it wrong?
Until I try it in a capture event. The capture event only appears to give me access to one village, ie, the village just captured.
Here's the code:
Code: Select all
[event]
name=capture
first_time_only=no
[filter]
side=1
[/filter]
{DEBUG "T$turn_number| $unit.name| captured a village!"}
[store_locations]
variable=villages
[filter]
side=1
[/filter]
terrain=*^V*
[/store_locations]
{VARIABLE ownedvillagecnt $villages.length}
:
:
Re: Counting owned villages in capture event.
Topic about counting villages:
viewtopic.php?t=56343
viewtopic.php?t=56343
-
- Developer
- Posts: 17
- Joined: February 12th, 2023, 1:13 pm
Re: Counting owned villages in capture event.
[filter] only checks whether a unit is currently there, and has no relationship to the village ownership (in fact, it's possible a unit rests in village without capturing it.) A better alternative with store_locations is mentioned in the thread linked by Straff. And you may also check the Wiki: https://wiki.wesnoth.org/InternalAction ... illages.5D
- Celtic_Minstrel
- Developer
- Posts: 2222
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Counting owned villages in capture event.
Try replacing
Also, there's
[filter]
with [filter_owner]
. The former is asking for villages that have a side 1 unit on them; the latter is asking for villages that belong to side 1. So, your current filter is wrong even outside of a capture event.Also, there's
gives_income=yes
which is recommended instead of filtering by terrain type. I can't remember if that's available in 1.16.x, though.