Testing WML actions more often without reloading cache

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

Testing WML actions more often without reloading cache

Post by Ravana »

WML development feedback loop is quite slow - you need to use F5, build new cache, start scenario again. When only looking to test one specific event or tag there is faster way.

Many WML tags are implemented in Lua now, and because of that Lua has all the tools needed to read and run WML. Note that macros or in general preprocessing of any kind is not supported with this way.

To make use of it create cfg file somewhere in your addon files. Fill it with for example

Code: Select all

[message]
	message="message loaded during runtime"
[/message]
Then enable debug with :debug and either in Lua console run wesnoth.require("wml-utils").handle_event_commands(wml.load("~add-ons/EventLoader/action.cfg")) or run it as :lua wesnoth.require("wml-utils").handle_event_commands(wml.load("~add-ons/EventLoader/action.cfg")) after updating path to refer to your file. You can also set it as alias: :alias e=lua wesnoth.require("wml-utils").handle_event_commands(wml.load("~add-ons/EventLoader/event.cfg")) to then run it as :e

You can also test events. When testing event it is useful to remove previous version of event before loading new version.

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 and to be able to remove it
	id=Rav_EventLoader_Event_1
	[lua]
		code=<<
wesnoth.message("event 2 loaded")
>>
	[/lua]
[/event]
I hope you find this design useful.
Tags: hotpatching, wml injection, eventloader
lea
Posts: 300
Joined: October 1st, 2016, 7:25 pm

Re: Testing WML actions more often without reloading cache

Post by lea »

Ravana wrote: November 22nd, 2022, 8:34 pm... ... ...
Many WML tags are implemented in Lua now, and because of that Lua has all the tools needed to read and run WML.
... ... ...
is it limited to WML tags which are already (re/)implemented in lua?

if so then will it ignore tags which are not implemented in lua? will these tags cause runtime error when running in this way or some other visible result?

also in which version of Wesnoth this was added?
author of: Altered Era/Ruleset (AKA "Altera"), latest version is on add-ons servers for BfW 1.16 and 1.14, latest version also still supports BfW 1.12 and 1.10, 1.10 server is stuck with older buggy version)
User avatar
Ravana
Forum Moderator
Posts: 2933
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Testing WML actions more often without reloading cache

Post by Ravana »

This post was created with 1.16.0. It might work with earlier. I expect all ActionWML tags work. It does not matter if they are implemented in Lua or not.

But for example you cant load full [scenario] with this way.
User avatar
Celtic_Minstrel
Developer
Posts: 2158
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Testing WML actions more often without reloading cache

Post by Celtic_Minstrel »

lea wrote: November 20th, 2023, 10:40 am is it limited to WML tags which are already (re/)implemented in lua?
No. It's limited to ActionWML tags, but it doesn't matter whether they are implemented in Lua.
lea wrote: November 20th, 2023, 10:40 amif so then will it ignore tags which are not implemented in lua?
No.
lea wrote: November 20th, 2023, 10:40 amwill these tags cause runtime error when running in this way or some other visible result?
No, they'll function normally.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Post Reply