Overwriting events
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.
- orcish_orc
- Posts: 44
- Joined: April 11th, 2007, 12:43 pm
- Location: Singapore
Overwriting events
Hi!
In my scenario I have a [event] name=die ... [/event] block. If the player triggers it, he wins. Some time later, I spawn another [event] name=die ... [/event] block, different from the first one.
I thought that by spawning another event, the first event would be overwritten, however this is not the case. If, after both events have been spawned, I trigger the event, it seems that the first event gets triggered. I want the second event to be triggered instead.
It could be done using variables and making the event check where it is being triggered, but I can't help thinking there must be a better way.
I've included the relevant code.
In my scenario I have a [event] name=die ... [/event] block. If the player triggers it, he wins. Some time later, I spawn another [event] name=die ... [/event] block, different from the first one.
I thought that by spawning another event, the first event would be overwritten, however this is not the case. If, after both events have been spawned, I trigger the event, it seems that the first event gets triggered. I want the second event to be triggered instead.
It could be done using variables and making the event check where it is being triggered, but I can't help thinking there must be a better way.
I've included the relevant code.
Code: Select all
[objectives]
[objective]
description= _ "Retrieve the Apocalypse Orb"
condition=win
[/objective]
[objective]
description= _ "OR"
condition=win
[/objective]
[objective]
description= _ "Kill all non-peasant enemies"
condition=win
[/objective]
[/objectives]
[item]
x=18
y=11
image=halo/undead/dark-magic-5.png
[/item]
[event]
#all enemy units die
name=die
first_time_only=no
[filter]
side=4
[/filter]
[if]
[have_unit]
side=4
[/have_unit]
[then]
[/then]
[else]
#u've killed everyone.
[message]
speaker=Mal Festo
message= _ "The path is clear. I must take the orb and return."
[/message]
[endlevel]
result=victory
bonus=yes
next_scenario=Death_March
[/endlevel]
[/else]
[/if]
[/event]
[event]
name=moveto
first_time_only=no
[filter]
description=Mal Festo
x=18
y=11
[/filter]
[removeitem]
x=18
y=11
[/removeitem]
[objectives]
[objective]
description= _ "Retreat to the Green Swamps"
condition=win
[/objective]
[objective]
description= _ "OR"
condition=win
[/objective]
[objective]
description= _ "Kill all non-peasant enemies"
condition=win
[/objective]
[/objectives]
[item]
x=8
y=19
image=scenery/signpost.png
[/item]
[event]
#all enemy units die
name=die
first_time_only=no
[filter]
side=4
[/filter]
[if]
[have_unit]
side=4
[/have_unit]
[then]
[/then]
[else]
#u've killed everyone.
[message]
speaker=Mal Festo
message= _ "You asked for it."
[/message]
[endlevel]
result=victory
bonus=yes
next_scenario=Death_March
[/endlevel]
[/else]
[/if]
[/event]
[event]
name=moveto
first_time_only=no
[filter]
description=Mal Festo
x=8
y=19
[/filter]
[message]
speaker=Mal Festo
message= _ "Fools. All fools."
image=portraits/mal_festo.jpg
[/message]
[endlevel]
result=victory
next_scenario=Death_March
[/endlevel]
[/event]
[/event]
- beetlenaut
- Developer
- Posts: 2867
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: Overwriting events
All events of the same name are triggered, but they are triggered in the order that they appear in the source file. If you put the new event in front of the first one, it will trigger first. If you want the old event not to trigger at all, remove the unit during the new one (using [kill], as redundant as that seems to be during a die event).
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: Overwriting events
In MOST cases, using a single variable is simpler than spawning an event. Some people love to spawn events but I think it's a bad habit. Variables are pretty straightforward to understand, even if they are a pain to set, check, and clear. 
The only thing I see different about the two events is the message displayed.
So, why don't you just store the message in a variable, and just set the variable instead of spawning a new event?

The only thing I see different about the two events is the message displayed.
So, why don't you just store the message in a variable, and just set the variable instead of spawning a new event?
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."