Make event trigger in a certain time interval

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

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.
Post Reply
Rya
Posts: 350
Joined: September 23rd, 2009, 9:01 am

Make event trigger in a certain time interval

Post by Rya »

How can I make an event trigger once per turn or once every second turn?

I know I can use "turn X" but then I'll need to write one event for each turn. "new turn" will trigger for each side once so that won't work either. "side turn" should work for once per turn, but how do I check against the side number?

I tried this:

Code: Select all

[event] 
  name=side turn
  first_time_only=no
  [filter]
    side_number=4
  [/filter]...
But it seems to never trigger.
Wesnoth
The developer says "no".

Anonymissimus
Inactive Developer
Posts: 2460
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Make event trigger in a certain time interval

Post by Anonymissimus »

read the reference wml what can go inside [filter]

Code: Select all

[event]
    name=side turn
    first_time_only=no
    [if]
        [variable]
            name=side_number
            numerical_equals=4
        [/variable]
        [then]
           ...
        [/then]
    [/if]
[/event]
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign

Rya
Posts: 350
Joined: September 23rd, 2009, 9:01 am

Re: Make event trigger in a certain time interval

Post by Rya »

Ok thanks, and what to do for "every second turn"?
Wesnoth
The developer says "no".

User avatar
solsword
Code Contributor
Posts: 291
Joined: January 12th, 2009, 10:21 pm
Location: Santa Cruz, CA
Contact:

Re: Make event trigger in a certain time interval

Post by solsword »

Something like this (warning: untested code):

Code: Select all

[event]
    name=side turn
    first_time_only=no
    [set_variable]
        name=oddturn
        value="$($turn_number%2)"
    [/set_variable]
    [if]
        [variable]
            name=oddturn
            boolean_equals=yes
        [/variable]
        [then]
            ...
        [/then]
    [/if]
[/event]
If you're not familiar with it, the '%' operator gets the remainder after division, so %2 will be 1 for odd numbers and 0 for even numbers (where 1 evaluates to 'yes' and 0 to 'no' for boolean comparison).
The Knights of the Silver Spire campaign.

http://www.cs.hmc.edu/~pmawhorter - my website.

Teamcolors for everyone! PM me for a teamcolored version of your sprite, or you can do it yourself. If you just happen to like magenta, no hard feelings?

Rya
Posts: 350
Joined: September 23rd, 2009, 9:01 am

Re: Make event trigger in a certain time interval

Post by Rya »

Can I also check on two variables at once? For example to say "Every turn of side 4 if the turn count is higher than 20".



Edit: I just noticed that "new turn" only triggers once too... the documentation however says it triggers each time someone ends his turn.
Wesnoth
The developer says "no".

User avatar
solsword
Code Contributor
Posts: 291
Joined: January 12th, 2009, 10:21 pm
Location: Santa Cruz, CA
Contact:

Re: Make event trigger in a certain time interval

Post by solsword »

You can use [and] tags to check as many things as you want inside the [if] tag.

If you're reading the same documentation I am (the wiki) you'll notice that it says "new turn" triggers when the *last* player ends their turn. The event you want is probably "side turn" which fires at the beginning of each side's turn. It's confusing because there are two concepts of turn: the "side turn" which is one side moving all of their units, and the "turn", in which every side gets its "side turn" and then the time of day advances.
The Knights of the Silver Spire campaign.

http://www.cs.hmc.edu/~pmawhorter - my website.

Teamcolors for everyone! PM me for a teamcolored version of your sprite, or you can do it yourself. If you just happen to like magenta, no hard feelings?

Soliton
Site Administrator
Posts: 1600
Joined: April 5th, 2005, 3:25 pm
Location: #wesnoth-mp

Re: Make event trigger in a certain time interval

Post by Soliton »

solsword wrote:If you're reading the same documentation I am (the wiki) you'll notice that it says "new turn" triggers when the *last* player ends their turn.
All side initialization events fire pretty much the same time. I don't know why it was worded that weird in the wiki but I fixed that now.
"If gameplay requires it, they can be made to live on Venus." -- scott

User avatar
A Guy
Posts: 790
Joined: May 24th, 2008, 1:55 am

Re: Make event trigger in a certain time interval

Post by A Guy »

solsword wrote:Something like this (warning: untested code):

Code: Select all

[event]
    name=side turn
    first_time_only=no
    [set_variable]
        name=oddturn
        value="$($turn_number%2)"
    [/set_variable]
    [if]
        [variable]
            name=oddturn
            boolean_equals=yes
        [/variable]
        [then]
            ...
        [/then]
    [/if]
[/event]
If you're not familiar with it, the '%' operator gets the remainder after division, so %2 will be 1 for odd numbers and 0 for even numbers (where 1 evaluates to 'yes' and 0 to 'no' for boolean comparison).
An alternative would be to add 1 to a variable every turn, and execute the event and set the variable to 0 if the variable is 2.
I'm just... a guy...
I'm back for now, I might get started on some work again.

Post Reply