Stopping village income after 10 villages
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.
Stopping village income after 10 villages
I'm working on a scenario with 3 opposing sides and 30 villages. I'd like to change the rules a little so that each of the three opposing leaders can only collect income from a maximum of 10 villages.
Note: there is no limit to the number of villages a side may flag; however, any flagged villages above 10 serve only to deprive an opposing army of gold (which is still plenty of an incentive to keep flagging).
I don't know how to code this event. Any help would be appreciated.
Thanks.
Note: there is no limit to the number of villages a side may flag; however, any flagged villages above 10 serve only to deprive an opposing army of gold (which is still plenty of an incentive to keep flagging).
I don't know how to code this event. Any help would be appreciated.
Thanks.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Re: Stopping village income after 10 villages
On capture event if number of villages is too high, change current village to neutral.
Re: Stopping village income after 10 villages
Okay, thanks. That helped me see what direction my code should focus on.
Evidently I need to make a variable/counter to keep track of each side's number of captured villages. But first I need to make an event that monitors when villages are captured, and which side did it. And the solution would probably involve
Regarding making a captured village neutral, do I create a 4th side with no leader and assign it to that side? Or is there a more direct way to make a village neutral?
Evidently I need to make a variable/counter to keep track of each side's number of captured villages. But first I need to make an event that monitors when villages are captured, and which side did it. And the solution would probably involve
[filter_owner]
?Regarding making a captured village neutral, do I create a 4th side with no leader and assign it to that side? Or is there a more direct way to make a village neutral?
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Re: Stopping village income after 10 villages
Yes, store locations and check length.Helmet wrote: ↑October 24th, 2022, 4:14 pm Okay, thanks. That helped me see what direction my code should focus on.
Evidently I need to make a variable/counter to keep track of each side's number of captured villages. But first I need to make an event that monitors when villages are captured, and which side did it. And the solution would probably involve[filter_owner]
?
> If the side key is not given, the village will become neutral (unless [filter_side] is present, in which case that side fiter decides, see below).Regarding making a captured village neutral, do I create a 4th side with no leader and assign it to that side? Or is there a more direct way to make a village neutral?
Re: Stopping village income after 10 villages
I wrote the code, but something is not allowing my scenario to load, so I can't test it. I suspect the code is the problem.
I have not yet taken into account that an enemy unit might re-capture a village and thereby lower the total number of villages for side 1.
I have not yet taken into account that an enemy unit might re-capture a village and thereby lower the total number of villages for side 1.
Code: Select all
[set_variable]
name=side_1_villages
value=0
[/set_variable]
[event]
[/event] # E N D S T A R T
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[event]
name=capture_village
first_time_only=no
[filter]
side=1
[/filter]
[set_variable]
name=side_1_villages
add=1
[/set_variable]
[if]
[variable]
name=side_1_villages
greater_than=10
[/variable]
[then]
side=
[/then]
[/if]
[/event]
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
- beetlenaut
- Developer
- Posts: 2867
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: Stopping village income after 10 villages
That "something" almost certainly gives an error message. Did it say something like "invalid closing tag for [event]?" It looks like you have an extra [event] starting tag without an ending tag.
It always is!

Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
Re: Stopping village income after 10 villages
I had the opening [event] tag. For my forum post, I didn't cut and paste all the code.beetlenaut wrote: ↑October 25th, 2022, 5:55 am...Did it say something like "invalid closing tag for [event]?" It looks like you have an extra [event] starting tag without an ending tag.
The only helpful message I got was "Failed to load scenario."
Ha.
There's another problem. If my code was working, I was intending to copy and paste it two more times, and change two of the
side=1
to side=2
and side=3
, so the village limit would apply to all sides. I'm pretty sure this is inefficient and I need a variable.The more I work on it, the more complicated this idea seems.
In many games, there's a point where one player has most of the villages, and that's when the eventual victor becomes obvious, as the player with the most villages recruits more units. My solution would put a cap on the gold per turn for my particular scenario. I was wondering what difference it would make with overall strategy. For example, presently when you capture a village from your enemy, you get more gold, and you take gold away from your opponent. If my code worked, if you already have 10 villages, you would only be taking gold away from your opponent.
Has anybody ever done this before in a scenario that I can reference?
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
- beetlenaut
- Developer
- Posts: 2867
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: Stopping village income after 10 villages
You only get the helpful message the first time you try to run it. After that, you only get the "Failed..." message. You need to change the .cfg file (adding extra white space will do), save it again, reload the cache or restart BfW, and try to load the scenario again. Then you will be back to the more-helpful error message.
I'm sure the opening tag is up there somewhere where we can't see it, but that's not what I said. You seem to be missing the closing tag for it. You have the code
Code: Select all
[event]
[/event]
There is an automatically stored variable called side_number. That's what you need.
(Edit: Accidentally posted before I was done.)
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
Re: Stopping village income after 10 villages
Thank you, beetlenaut; that helped. My scenario is loading now.
I've found and solved a few code problems. (And probably created some new ones.)
New question.
When a person plays BfW, at the top of the window is displayed a "fraction of total number of villages that your side has captured." Is there a way I can access that number? That might help me figure-out what I'm doing wrong with my village variable. Presently it doesn't
I've found and solved a few code problems. (And probably created some new ones.)
New question.
When a person plays BfW, at the top of the window is displayed a "fraction of total number of villages that your side has captured." Is there a way I can access that number? That might help me figure-out what I'm doing wrong with my village variable. Presently it doesn't
add=1
when I capture a new village.Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
- beetlenaut
- Developer
- Posts: 2867
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: Stopping village income after 10 villages
Do you still have
Or maybe you still have
To answer your question: Sort of. You could get the village number by using [store_villages] then [foreach] to count the ones with a particular owner, but that's enough code that it would be likely to introduce even more errors.
If none of this isn't helpful, you could post the code you have now.
name=capture_village
? That isn't a valid event name.Or maybe you still have
side
inside of [then], where it is not valid.To answer your question: Sort of. You could get the village number by using [store_villages] then [foreach] to count the ones with a particular owner, but that's enough code that it would be likely to introduce even more errors.
If none of this isn't helpful, you could post the code you have now.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
Re: Stopping village income after 10 villages
That helped. I improved the code a little, but not enough to make it work.
I commented-out some code, trying to tackle one thing at a time.
Right now, my variable
The number of villages flagged should also appear in a note under "Objectives."
Once that works, the next big step would be to make a village neutral if it is captured by a side that already has 10 or more villages.
Here's the code. I left out the top 90 lines, which contains the usual necessities, like the sides.
Thanks.
I commented-out some code, trying to tackle one thing at a time.
Right now, my variable
side_1_villages
doesn't count the villages when they are flagged. For now, I limited it to side 1, but I really need it to apply to all 3 sides.The number of villages flagged should also appear in a note under "Objectives."
Once that works, the next big step would be to make a village neutral if it is captured by a side that already has 10 or more villages.
Here's the code. I left out the top 90 lines, which contains the usual necessities, like the sides.
Thanks.
Code: Select all
[event] # <--- pre-start
name=prestart # "prestart" events are fired automatically before the scenario appears on screen.
[set_variable]
name=side_1_villages
value=0
[/set_variable]
[objectives] # - - - - - - - - - - - - - - - - - - - - - - - - - objectives
side=1
summary= _ "<small>""$difficulty|"" difficulty</small>"
[objective]
description= _ "Defeat enemy leaders"
condition=win
[/objective]
[objective]
description= _ "Your leader is defeated"
condition=lose
[/objective]
{NOTE ( _ "A maximum of 10 villages can be flagged for each side.") ()}
[note]
description= _ "Villages flagged by the Swamp Alliance: $|side_1_villages"
[/note]
[/objectives]
[/event] # <--- end pre-start
[event] # <--- S T A R T
name=start
[label]
color="160,200,200"
text= _ "Castle Frog"
x,y=21,24
[/label]
[/event] # E N D S T A R T
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[event]
name=capture
first_time_only=no
[filter]
side=1
[/filter]
[capture_village]
[filter]
side=1
[/filter]
[set_variable]
name=side_1_villages
add=1
[/set_variable]
side=1
[/capture_village]
# [if]
# [variable]
# name=side_1_villages
# greater_than=10
# [/variable]
# [/if]
[/event]
[event]
name=enemies defeated
[endlevel]
result=victory
carryover_report=no
[/endlevel]
[/event]
[/scenario]
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
- beetlenaut
- Developer
- Posts: 2867
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: Stopping village income after 10 villages
Neither [filter] nor [set_variable] is allowed inside [capture_village]. Everything that is allowed is mentioned in the wiki. You need to check that! I wouldn't know this without checking, myself. I think everything will work if you move the [set_variable] out and get rid of the [filter] (it doesn't matter because the event already has a filter). I pasted it into my test scenario, and it worked fine.
You can use the variable I mentioned to get the correct side. You can even use it as part of the variable's name in [set_variable] like:
name=side_$side_number|_villages
.Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
Re: Stopping village income after 10 villages
[capture_village] captures a village. In capture event the village was just captured by side 1, so [capture_village] with side=1 does not do anything.
Re: Stopping village income after 10 villages
Thanks for all the help. I got the code to work...briefly.
This is what worked: the number of flagged villages for side 1 was successfully tracked in a variable, and the newly captured villages were made neutral if side 1 already had the maximum number of villages allowed.
But further coding make it stop working. I kinda know why, but not how to fix it. It's about a variable, I think.
The code worked when I used a simple variable to contain the quantity of side 1 villages:
But I wanted to use a more powerful variable, one that could handle all 3 sides:
When I swapped the simple variable for the powerful variable, the code stopped working. Various efforts, mostly revolving around adding and subtract the
This is what I tried to do: make one single event that will know which side captured the village, and depending on the side and depending on how many villages that side has already has captured, will either allow the village to be flagged or will make make it neutral.
I probably could make one event for each side and it would work, but there must be a way to combine those three events.
This is what worked: the number of flagged villages for side 1 was successfully tracked in a variable, and the newly captured villages were made neutral if side 1 already had the maximum number of villages allowed.
But further coding make it stop working. I kinda know why, but not how to fix it. It's about a variable, I think.
The code worked when I used a simple variable to contain the quantity of side 1 villages:
side_1_villages
.But I wanted to use a more powerful variable, one that could handle all 3 sides:
$|side_$side_number|_villages
.When I swapped the simple variable for the powerful variable, the code stopped working. Various efforts, mostly revolving around adding and subtract the
$
, did not help.This is what I tried to do: make one single event that will know which side captured the village, and depending on the side and depending on how many villages that side has already has captured, will either allow the village to be flagged or will make make it neutral.
I probably could make one event for each side and it would work, but there must be a way to combine those three events.
Code: Select all
[set_variable]
name=side_$side_number|_villages
value=0
[/set_variable]
[objectives] # - - - - - - - - - - - - - - - - - - - - - - - - - objectives
side=1
summary= _ "<small>""$difficulty|"" difficulty</small>"
# summary= _ "<small>Scenario 1 ($difficulty| difficulty mode)</small>"
[objective]
description= _ "Defeat enemy leaders"
condition=win
[/objective]
[objective]
description= _ "Your leader is defeated"
condition=lose
[/objective]
{NOTE ( _ "A maximum of 3 villages can be flagged for each side.") ()}
[note]
# description= _ "Villages flagged by the Swamp Alliance: $|side_1_villages"
description= _ "Villages flagged: $|side_$side_number|_villages"
[/note]
[/objectives]
[/event] # <--- end pre-start
[event] # <--- S T A R T
name=start
[label]
color="160,200,200"
text= _ "Castle Frog"
x,y=21,24
[/label]
[/event] # E N D S T A R T
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[event]
name=capture
first_time_only=no
[filter]
side=1
[/filter]
[set_variable]
name=$side_$side_number|_villages
add=1
[/set_variable]
[if]
[variable]
name=side_$side_number|_villages
greater_than=3
[/variable]
[then]
[capture_village]
x=$x1
y=$y1
[filter_side]
side=99 # no valid side means village will become neutral
[/filter_side]
[/capture_village]
[variable]
name=side_$side_number|_villages
equals=3
[/variable]
[/then]
[/if]
[/event]
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
- beetlenaut
- Developer
- Posts: 2867
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: Stopping village income after 10 villages
The
Don't use
$
should be read as "contents of." The |
can be used to mark the end of the variable's name if it won't be obvious to the game engine. Don't use them together ($|
) unless you know exactly why you are doing it! It is rarely necessary. So, in your [variable] and [set_variable] name lines, you should have name=side_$side_number|_villages. The variable part is marked in bold. (The |
is optional in this case, but I included it for clarity.) If everything is working right, you will end up with variables called "side_1_villages," "side_2_villages," and "side_3_villages." I suggest removing the [filter] from the capture event and using :inspect to make sure those variables are getting created. You should be comfortable with this part out before going farther. Randomly adding and subtracting $
almost never works.$side_1_villages
should work in the [note] description because it is only for side 1.Don't use
side=99
to refer to no side. The wiki says that if a side is not given at all, the village will become neutral. Using "99" might work at the moment, but that is unexpected behavior, and could change at any time without warning.Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide