How to replace an event in the middle of a scenario
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.
- pyrophorus
- Posts: 533
- Joined: December 1st, 2010, 12:54 pm
How to replace an event in the middle of a scenario
Hi everyone !
When tuning long and complex scenarios, I would find very handy to replace an event (subroutine) with a new version without restarting the scenario from beginning. Suppose we have an event whose id is LSB_EnableUnitMenu.
I execute first the following code:
The event actually disappear, OK...
Then I try to load the new version from a file containing the new event:
for instance (please note I updated the cache using F5 on the main screen).
As a result, the old version of the event pops out, not the new one. Strange isn't it ? I suspect the event is only disabled, not really removed from the scenario.
Any idea ?
Thanks in advance.
When tuning long and complex scenarios, I would find very handy to replace an event (subroutine) with a new version without restarting the scenario from beginning. Suppose we have an event whose id is LSB_EnableUnitMenu.
I execute first the following code:
Code: Select all
[event]
id=LSB_EnableUnitMenu
remove=yes
[/event]
Then I try to load the new version from a file containing the new event:
Code: Select all
{~add-ons/{BTWFOLDER}/utils/LSB9-MenuEvents.cfg}
As a result, the old version of the event pops out, not the new one. Strange isn't it ? I suspect the event is only disabled, not really removed from the scenario.
Any idea ?
Thanks in advance.
HowTos: WML filtering, WML variables
Re: How to replace an event in the middle of a scenario
You need to modify savefile, not scenario file for that.
It might be possible to use wml.load/utils.handle_event_commands to set up loading and evaluating WML from file during runtime.
It might be possible to use wml.load/utils.handle_event_commands to set up loading and evaluating WML from file during runtime.
- pyrophorus
- Posts: 533
- Joined: December 1st, 2010, 12:54 pm
Re: How to replace an event in the middle of a scenario
Thanks...
You're right. I was wrongly figuring the code:
repeated file loading when triggered by some mean at runtime, but it's a macro and the file is loaded only once when the scenario is started.
I don't know where to find "wml.load/utils.handle_event_commands" but if this doesn't work, I think I can use [get_global_variable] and [insert_tag] to do the job.
Friendly,
You're right. I was wrongly figuring the code:
Code: Select all
{~add-ons/{BTWFOLDER}/utils/LSB9-MenuEvents.cfg}
I don't know where to find "wml.load/utils.handle_event_commands" but if this doesn't work, I think I can use [get_global_variable] and [insert_tag] to do the job.
Friendly,
HowTos: WML filtering, WML variables
- Spannerbag
- Posts: 786
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
Re: How to replace an event in the middle of a scenario
Erm, might've misunderstood this but there's an ugly hack you could try?
If you want to change the event logic on the fly and you could
a) use
b) use a
For multiple values of
use
Once you have the logic tuned, just remove all the test code.
Like I say, an ugly hack but it would allow live logic change during play.
Apologies if you already thought of this and discounted it for some reason.
Just my tuppence worth.
BTW - Re:
As it happens I'm about 70% through a new campaign that uses exactly that for its namespace!
No problem, I'm happy to change my namespace (no rush, I'm taking a break from that project as it was absorbing all my free time but will revisit it soon).
Cheers!
-- Spannerbag
If you want to change the event logic on the fly and you could
a) use
[filter_condition]
or [if]
+ flag variable (e.g. something like $event_logic_select
) to branch the logic then,b) use a
moveto
or enter_hex
event to set $event_logic_select
to <whatever>For multiple values of
$event_logic_select
you could either have multiple moveto
or enter_hex
events, oruse
[message]...[text_input]
to input exactly what you want.Once you have the logic tuned, just remove all the test code.
Like I say, an ugly hack but it would allow live logic change during play.
Apologies if you already thought of this and discounted it for some reason.
Just my tuppence worth.
BTW - Re:
LSB_EnableUnitMenu
, is LSB
your campaign namespace string?As it happens I'm about 70% through a new campaign that uses exactly that for its namespace!
Code: Select all
#textdomain wesnoth-LSB
# Temporal setting
#
# Set in far north west, campaign begins in 7 YW and overlaps with "An Orcish Incursion".
# (1 YW: "Rise of Wesnoth" ends)
Cheers!
-- Spannerbag
- pyrophorus
- Posts: 533
- Joined: December 1st, 2010, 12:54 pm
Re: How to replace an event in the middle of a scenario
Hi Spannerbag...
Thanks for your reply.
Actually, I think you misunderstood my goal. I don't want to test various solutions or flavors of an event, but fix problems or make changes in the scenario code without restarting it from beginning. Suppose my LSB_EnableUnitMenu has a bug I detect only on turn 29, I would like to replace the wrong code and resume at turn 29. For tuning and debugging purpose only of course, because it's very bad practice to modify the code at runtime.
Anyway, thanks for your code tips: they work (I already use most of them
).
Next, don't worry about the LSB string. It's actually the namespace of my WML library, but I have no publication project for now, and, just as you, I suppose, I can modify it in a minute (thanks Eclipse). If ever I use it in a public project, I'll take care about such name conflicts.
Good luck with your campaign !
Friendly,
Thanks for your reply.
Actually, I think you misunderstood my goal. I don't want to test various solutions or flavors of an event, but fix problems or make changes in the scenario code without restarting it from beginning. Suppose my LSB_EnableUnitMenu has a bug I detect only on turn 29, I would like to replace the wrong code and resume at turn 29. For tuning and debugging purpose only of course, because it's very bad practice to modify the code at runtime.
Anyway, thanks for your code tips: they work (I already use most of them

Next, don't worry about the LSB string. It's actually the namespace of my WML library, but I have no publication project for now, and, just as you, I suppose, I can modify it in a minute (thanks Eclipse). If ever I use it in a public project, I'll take care about such name conflicts.
Good luck with your campaign !
Friendly,
HowTos: WML filtering, WML variables
Re: How to replace an event in the middle of a scenario
I tried out my suggestion and it seems to work.
Code: Select all
[modification]
id=Rav_Event_Loader
name=_"Event Loader"
description=_"Example to load event from WML during runtime"
[event]
name=preload
first_time_only=no
[lua]
code=<<
local utils = wesnoth.require "wml-utils"
utils.handle_event_commands(wml.load("~add-ons/EventLoader/event.cfg"))
>>
[/lua]
[/event]
[/modification]
Code: Select all
[remove_event]
id=Rav_EventLoader_Event_1
[/remove_event]
[event]
name=side_turn
first_time_only=no
# id is needed to not load multiple versions of event at once
id=Rav_EventLoader_Event_1
[lua]
code=<<
wesnoth.message("v3")
>>
[/lua]
[/event]
- pyrophorus
- Posts: 533
- Joined: December 1st, 2010, 12:54 pm
Re: How to replace an event in the middle of a scenario
Thanks a lot, I'll try this...
Friendly
Friendly
HowTos: WML filtering, WML variables
- Spannerbag
- Posts: 786
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
Re: How to replace an event in the middle of a scenario
Roger wilco and thanks!pyrophorus wrote: ↑February 7th, 2022, 4:44 pm ... Next, don't worry about the LSB string...Good luck with your campaign !...
EclipseIDE? WML Library? Wow, you're a lot more organised than I am... I just steal stuff

... and code in Notepad

Cheers!
--Spannerbag
- pyrophorus
- Posts: 533
- Joined: December 1st, 2010, 12:54 pm
Re: How to replace an event in the middle of a scenario
Well... Notepad (at least the enhanced version with code highlighting) is certainly fine.Spannerbag wrote: ↑February 10th, 2022, 10:53 pm
EclipseIDE? WML Library? Wow, you're a lot more organised than I am... I just steal stuff
... and code in Notepad![]()
I use Eclipse for other programming too, and find it very handy to manage the 2 800 files of my WML project, including git integration. Maybe you could take a look at it (or Visual Studio or anything of the like), not being scared by it's complexity, since you don't need most of its features. It really save time.
Friendly,
HowTos: WML filtering, WML variables
- Lord-Knightmare
- Discord Moderator
- Posts: 2491
- Joined: May 24th, 2010, 5:26 pm
- Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
- Contact:
Re: How to replace an event in the middle of a scenario
What the...What do you even keep in there? Woah. Is this supposed some repo of WML code examples for use by UMC authors?2 800 files of my WML project
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
- pyrophorus
- Posts: 533
- Joined: December 1st, 2010, 12:54 pm
Re: How to replace an event in the middle of a scenario
Lord-Knightmare wrote: ↑February 11th, 2022, 8:03 amWhat the...What do you even keep in there? Woah. Is this supposed some repo of WML code examples for use by UMC authors?2 800 files of my WML project



Friendly,
HowTos: WML filtering, WML variables
- Lord-Knightmare
- Discord Moderator
- Posts: 2491
- Joined: May 24th, 2010, 5:26 pm
- Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
- Contact:
Re: How to replace an event in the middle of a scenario
Do you have code for some inventory system by any chance? Or, maybe an alchemy system implemented in either WML/Lua? Was looking for one (mostly the latter) for a project.pyrophorus wrote: ↑February 11th, 2022, 10:06 pmLord-Knightmare wrote: ↑February 11th, 2022, 8:03 amWhat the...What do you even keep in there? Woah. Is this supposed some repo of WML code examples for use by UMC authors?2 800 files of my WML project![]()
![]()
No... Actually, 2 500 files are pics. The remaining 300 are utils, scenarios and units. Code examples for use by UMC authors ? I doubt it, because those are mainly rather strange things which would not improve the battle one could find in ordinary campaigns. For instance, I have developed a full module allowing ordinary units to mount horses and then become mounted units, dismount at will, free their horses when killed and so on. No UMC author concerned with balancing will ever get this in his campaign even if it looks cool at first glance.
Friendly,
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
- Spannerbag
- Posts: 786
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
Re: How to replace an event in the middle of a scenario
Me too. Did start designing a "Khemist" (L1, Mage variant, advances to L4) unittype that modified game parameters by enchanting persons or items for various durations (i.e. applied [objects] to single/multiple units). Never really got traction however (too many competing ideas in my head...Lord-Knightmare wrote: ↑February 12th, 2022, 10:16 am Or, maybe an alchemy system implemented in either WML/Lua? Was looking for one (mostly the latter) for a project.

Besides, has kinda already been done in a few campaigns.
E.g. UMC Elvish Dynasty has unity magics which are similar in concept but were "baked in" to the scenario; IIRC the player had no control over what effects were used or when.
I envisaged these as being support units (bit like healers) rather than front-line units.
But I'd also be interested in anything you've thought of?
Cheers!
--Spannerbag
- pyrophorus
- Posts: 533
- Joined: December 1st, 2010, 12:54 pm
Re: How to replace an event in the middle of a scenario
Lord-Knightmare wrote: ↑February 12th, 2022, 10:16 am Do you have code for some inventory system by any chance? Or, maybe an alchemy system implemented in either WML/Lua? Was looking for one (mostly the latter) for a project.
Well... It's difficult to reply in few words !Spannerbag wrote: ↑February 12th, 2022, 12:52 pm But I'd also be interested in anything you've thought of?

I have an inventory system managing [object]s giving to the bearer weapons or special abilities, and the code to deal with: picking items on the battlefield, or getting them from a store (a special unit or a building). Giving some to all units of a team too. Really fantastic to create an invincible army in a few clicks.
If by alchemy you mean creating some stuff from resources you've collected previously, I have none. I have only "crafting" code: special units can be put to work (in other words, they're moveless and attackless for some turns) and create objects/boats and carriages (which can hold units)/modify the field and build things (villages, stores, battle towers and fortifications), dig tunnels, build bridges over water, and other things perfectly suited to totally ruin the map and the balance of any scenario.
For now, there is no other constraint than unit type, but it's easy to add some (money cost or resources for instance).
This to say I have no "ready-to-use" code to share with you, because your needs are not exactly same as mine. More of it, I can't dispatch easily rather complex things like inventories, because they have dependencies with other things you're probably not interested in (units teams, money system for instance). I certainly can adapt my work to your needs, but I need to know more exactly what you want.
Friendly,
HowTos: WML filtering, WML variables
- Spannerbag
- Posts: 786
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
Re: How to replace an event in the middle of a scenario
Liking the "only"pyrophorus wrote: ↑February 12th, 2022, 6:02 pm I have an inventory system ...
I have only "crafting" code...

I'll let you know when I know myselfpyrophorus wrote: ↑February 12th, 2022, 6:02 pm ... I certainly can adapt my work to your needs, but I need to know more exactly what you want.


Cheers!
--Spannerbag