Stopping village income after 10 villages

The place to post your WML questions and answers.

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.
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Stopping village income after 10 villages

Post by Helmet »

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.
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.
User avatar
Ravana
Forum Moderator
Posts: 3314
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Stopping village income after 10 villages

Post by Ravana »

On capture event if number of villages is too high, change current village to neutral.
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: Stopping village income after 10 villages

Post by Helmet »

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]?

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.
User avatar
Ravana
Forum Moderator
Posts: 3314
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Stopping village income after 10 villages

Post by Ravana »

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]?
Yes, store locations and check length.
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?
> 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).
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: Stopping village income after 10 villages

Post by Helmet »

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.

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.
User avatar
beetlenaut
Developer
Posts: 2867
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Stopping village income after 10 villages

Post by beetlenaut »

Helmet wrote: October 25th, 2022, 12:55 am something is not allowing my scenario to load, so I can't test it.
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.
Helmet wrote: October 25th, 2022, 12:55 am I suspect the code is the problem.
It always is! ;)
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: Stopping village income after 10 villages

Post by Helmet »

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.
I had the opening [event] tag. For my forum post, I didn't cut and paste all the code.
The only helpful message I got was "Failed to load scenario."
beetlenaut wrote: October 25th, 2022, 5:55 am
Helmet wrote: October 25th, 2022, 12:55 am I suspect the code is the problem.
It always is! ;)
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.
User avatar
beetlenaut
Developer
Posts: 2867
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Stopping village income after 10 villages

Post by beetlenaut »

Helmet wrote: October 25th, 2022, 3:16 pm The only helpful message I got was "Failed to load scenario."
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.
Helmet wrote: October 25th, 2022, 3:16 pm I had the opening [event] tag. For my forum post, I didn't cut and paste all the code.
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]
With nothing inside. I can't see any way for that to be correct. That looks like an extra opening tag before the closing one.
Helmet wrote: October 25th, 2022, 3:16 pmI'm pretty sure this is inefficient and I need a variable.
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
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: Stopping village income after 10 villages

Post by Helmet »

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 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.
User avatar
beetlenaut
Developer
Posts: 2867
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Stopping village income after 10 villages

Post by beetlenaut »

Do you still have 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
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: Stopping village income after 10 villages

Post by Helmet »

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 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.
User avatar
beetlenaut
Developer
Posts: 2867
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Stopping village income after 10 villages

Post by beetlenaut »

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.
Helmet wrote: October 25th, 2022, 6:36 pm but I really need it to apply to all 3 sides.
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
User avatar
Ravana
Forum Moderator
Posts: 3314
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Stopping village income after 10 villages

Post by Ravana »

[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.
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: Stopping village income after 10 villages

Post by Helmet »

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: 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.
User avatar
beetlenaut
Developer
Posts: 2867
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Stopping village income after 10 villages

Post by beetlenaut »

The $ 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
Post Reply