Building an alternative to ActionWML

Brainstorm ideas of possible additions to the game. Read this before posting!

Moderators: Forum Moderators, Developers

Forum rules
Before posting a new idea, you must read the following:
gfgtdf
Developer
Posts: 1110
Joined: February 10th, 2013, 2:25 pm

Re: Building an alternative to ActionWML

Post by gfgtdf » September 23rd, 2018, 8:49 pm

writing condition in lua is already partly possibel though, for generall conditional there exists a table wesnoth.conditionals (or was it called wml_conditionls dontremember) and for general unit/side/location etc filters they have a lua_function = attribute.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.

User avatar
Celtic_Minstrel
Developer
Posts: 1279
Joined: August 3rd, 2012, 11:26 pm
Contact:

Re: Building an alternative to ActionWML

Post by Celtic_Minstrel » September 23rd, 2018, 10:17 pm

josteph wrote:
September 23rd, 2018, 8:46 pm
I saw that. What I was trying to say is, making it possible to write conditions in lua is a small incremental step, that can be done right away, in the direction you're proposing. It will be an improvement in its own right since it will let people write lua instead of using [and] and [or] and [not] and {VARIABLE_CONDITIONAL foo boolean_equals true}.

I don't disagree with your other suggestions, such as expanding the lua API. I am just saying that it is already possible to write the actions in lua, if anybody wants to (maybe because they don't want to write control structures in WML), but it's not already possible to write the conditions in lua, so maybe start there. If UMC authors write their conditions in lua and their actions in WML, it will be easier to eventually transition to an all-lua system as you propose.
Ah, I see what you mean.

In fact, the [lua] tag can now be used as a conditional tag, so technically it is already possible to write your conditions in Lua, at least the non-filter conditions. I actually hadn't considered putting the filter conditions in Lua too...
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.

josteph
Developer
Posts: 159
Joined: August 19th, 2017, 6:58 pm

Re: Building an alternative to ActionWML

Post by josteph » September 23rd, 2018, 11:09 pm

Celtic_Minstrel wrote:
September 23rd, 2018, 10:17 pm
In fact, the [lua] tag can now be used as a conditional tag,
Added to https://wiki.wesnoth.org/ConditionalAct ... ition_Tags. Also added [proceed_to_next_scenario]. Please check.

User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Building an alternative to ActionWML

Post by Sapient » September 25th, 2018, 9:15 am

Celtic_Minstrel wrote:
September 23rd, 2018, 10:17 pm
In fact, the [lua] tag can now be used as a conditional tag, so technically it is already possible to write your conditions in Lua, at least the non-filter conditions. I actually hadn't considered putting the filter conditions in Lua too...
The WML for filters was designed intentionally to be declarative and to disallow changes to game state. If you inject arbitrary Lua code in the middle of filtering, then all sorts of things can go wrong-- it could potentially even cause crashes when the game enters an invalid state. One of the advantages of WML over Lua is that it disallows newbies from shooting themselves in the foot with such mistakes. I find WML to be a well-suited language for writing Wesnoth campaigns.

I feel that introducing Lua as a middle-man for the WML engine was a mistake. That led to WML coders becoming second class citizens as capabilities were added to Lua without equivalent in WML. That led to pressure to learn yet an additional language, when formerly only people interested in writing AIs would need to do that. And now that is being used as an excuse to dump WML altogether.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."

User avatar
Celtic_Minstrel
Developer
Posts: 1279
Joined: August 3rd, 2012, 11:26 pm
Contact:

Re: Building an alternative to ActionWML

Post by Celtic_Minstrel » September 26th, 2018, 12:05 am

This is an interesting point you make here. It's certainly possible to prevent changes to the game state from Lua code, and I even did something like this for AI Candidate Action evaluation functions, but extending that to the general Lua API would be a lot more work... but certainly still possible. Should we do that? It would be relevant whether or not ActionWML is actually dropped.

I wonder if it's possible to clone a Lua thread for this purpose? That would make read-only Lua code simpler, but I suppose it could involve a lot of memory allocation. I guess it's probably better to code the restriction into the API like I did in the AI engine…

It is certainly true that ActionWML (at least currently) has some advantages over Lua as a coding language for campaigns - I've even acknowledged this in the first post with the section on the Lua API. But I think these advantages could be transferred over to Lua.

About dumping WML altogether, I'm not precisely in favour of it. I'm on board with dumping ActionWML, though if the decision were solely mine to make I'd probably keep it around indefinitely as a deprecated API, but I'm against dumping WML as a declarative data language.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.

gfgtdf
Developer
Posts: 1110
Joined: February 10th, 2013, 2:25 pm

Re: Building an alternative to ActionWML

Post by gfgtdf » September 28th, 2018, 1:28 pm

Celtic_Minstrel wrote:
September 26th, 2018, 12:05 am
This is an interesting point you make here. It's certainly possible to prevent changes to the game state from Lua code, and I even did something like this for AI Candidate Action evaluation functions, but extending that to the general Lua API would be a lot more work... but certainly still possible. Should we do that? It would be relevant whether or not ActionWML is actually dropped.

I wonder if it's possible to clone a Lua thread for this purpose? That would make read-only Lua code simpler, but I suppose it could involve a lot of memory allocation. I guess it's probably better to code the restriction into the API like I did in the AI engine…
I don't know exactly what you mean by 'thread' here, but yes it's probably not feasible. You could try to add 'gamestate locks' while doing filters, but i do think that it only worth if it really causes crashes otherwise. Also note that there are cases where people do want to change the gamestate in filters temprarily for example to do checks like 'would this unit be able to move to y if unit o woudl not be there' so that unit o is temporarily removed and then the movepaths are checked. I'm quite sure that the ai also does such stuff during evalulation.
Celtic_Minstrel wrote:
September 26th, 2018, 12:05 am

It is certainly true that ActionWML (at least currently) has some advantages over Lua as a coding language for campaigns - I've even acknowledged this in the first post with the section on the Lua API. But I think these advantages could be transferred over to Lua.

About dumping WML altogether, I'm not precisely in favour of it. I'm on board with dumping ActionWML, though if the decision were solely mine to make I'd probably keep it around indefinitely as a deprecated API, but I'm against dumping WML as a declarative data language.
In my opinion wml should not be complteley removed as a configuration language, but we should move away form in as our internal way to represent data, with lua basicially being on top of the c++ part it makes much more sense if the c++ engine would work with lua-like tables instead fo the current 'config class', this would not only mostly remove the need for things like wml.tag and wml.get_child(), it would also fix other problems that appear during lua<->wml conversion, for example that when you store a string "1.1" in a variable it will currently come back as number 1.1 after wsnoth.get_variable()
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.

User avatar
Celtic_Minstrel
Developer
Posts: 1279
Joined: August 3rd, 2012, 11:26 pm
Contact:

Re: Building an alternative to ActionWML

Post by Celtic_Minstrel » September 29th, 2018, 12:19 am

I basically meant cloning the entire Lua state, but thinking about it now, I don't think it would work too well since the Lua objects are just wrappers around the internal C++ objects.

I don't think gamestate locks would be too difficult to implement though. I might do it the exact same way as in the AI, where you can override the protections if you really know what you're doing.

I don't see the problem with "1.1" and 1.1 being interchangeable. That's the case in vanilla Lua too, anyway.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.

User avatar
Pentarctagon
Forum Administrator
Posts: 3629
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: Building an alternative to ActionWML

Post by Pentarctagon » September 29th, 2018, 12:29 am

The true/false -> yes/no conversion can be particular annoying and unintuitive though.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code

gfgtdf
Developer
Posts: 1110
Joined: February 10th, 2013, 2:25 pm

Re: Building an alternative to ActionWML

Post by gfgtdf » September 29th, 2018, 12:49 am

Celtic_Minstrel wrote:
September 29th, 2018, 12:19 am
I don't see the problem with "1.1" and 1.1 being interchangeable. That's the case in vanilla Lua too, anyway.
well, at least it will make the comparisions like remote_data.version = local_version (assuming local_version is a string and remote_data is table serialized as wml) suddenly fail as soon as version has has only one dot inside (i recently had exactly this bug in one of my addons). I mean ofcourse its fixable by addiong tostring but such things come unexpected. Also there are functions like wesnoth.get_unit that are overloaded with and have differnt behviour dependent on the parameter type.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.

User avatar
Celtic_Minstrel
Developer
Posts: 1279
Joined: August 3rd, 2012, 11:26 pm
Contact:

Re: Building an alternative to ActionWML

Post by Celtic_Minstrel » September 29th, 2018, 1:55 am

Both of those things are probably fixable by representing WML tables (and, perhaps even the attribute values) as userdata instead of raw Lua values. Whether that's actually worth it, I'm not sure (it might have other downsides).
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.

eurydike
Posts: 44
Joined: March 20th, 2018, 1:43 am

Re: Building an alternative to ActionWML

Post by eurydike » October 5th, 2018, 5:49 am

Forgive me for participating into the conversation despite not having enough experience with any of the topics at hand, C++, Lua or ActionWML. For starters I have to say that I appreciate the intent of the author here, WML syntax for conditionals, loops and the like seems burdensome and it would be nice to be able to do everything in Lua with clean syntax. I've never used Lua before, despite being an actual thing outside Wesnoth, but with the little experience I have with both it seems that ActionWML is clumsier.

I imagine the implications of attempting to rid the world of ActionWML entirely include positive premises such as changing the standard format for scenario, era, ability & all things WML to such that you'd be writing somesort of lua equivalent datastructures instead of WML datastructures. For an example consider the unit information like, [attack]keys, [specials].. This format could be changed so that the parser expects a luafile with tables corresponding to the values. Example:

Code: Select all

#textdomain wesnoth-old_era
[unit_type]
    id=old_era_minotaur_warrior
    name= _ "Minotaur warrior"
    race=old_era_race_minotaur
    image="minotaur_axe.png"
    ellipse="misc/ellipse"
	profile=""
    hitpoints=54
    movement_type=old_era_minotaur_fighter
    movement=5
    experience=70
    cost=24
    level=1
    alignment=chaotic
    advances_to=old_era_minotaur_champion
    {AMLA_DEFAULT}
    description= _ "Minotaur warriors are skilled enough to wield an axe, they're strong and dangerous." 
    
    [resistance]
    [/resistance]
   
    [attack]
        name=great_axe
        description=_"Great Axe"
        icon=attacks/battleaxe.png
        type=blade
        range=melee
        damage=11
        number=2
        [specials]
            {OLD_ERA_WEAPON_SPECIAL_MASSIVE}
        [/specials]
    [/attack]  
    [attack]
        name=Horns
        description=_"Horns"
        icon=attacks/ram.png
        type=pierce
        range=melee
        damage=13
        number=1
        [specials]
            {WEAPON_SPECIAL_CHARGE}
        [/specials]
    [/attack]     
[/unit_type]

Code: Select all

#textdomain wesnoth-old_era
unit_type = {
    id="old_era_minotaur_warrior",
    name= _ "Minotaur warrior",
    race="old_era_race_minotaur",
    image="minotaur_axe.png",
    ellipse="misc/ellipse",
	profile="",
    hitpoints=54,
    movement_type="old_era_minotaur_fighter",
    movement=5,
    experience=70,
    cost=24,
    level=1,
    alignment="chaotic",
    advances_to="old_era_minotaur_champion",
    amla=AMLA_DEFAULT()
    description= _ "Minotaur warriors are skilled enough to wield an axe, they're strong and dangerous.",
    attacks[1]={
        name="great_axe",
        description=_"Great Axe",
        icon="attacks/battleaxe.png",
        type="blade",
        range="melee",
        damage=11,
        number=2,
        specials={
            OLD_ERA_WEAPON_SPECIAL_MASSIVE(),
        },
    },
    attacks[2] = {
        name="Horns",
        description=_"Horns",
        icon="attacks/ram.png",
        type="pierce",
        range="melee",
        damage=13,
        number=1,
        specials= {
            WEAPON_SPECIAL_CHARGE(),
	},
    },
}
This maybe a silly example, basically there's curly brackets and quotes around strings.. But despite the difference being almost neglible, there are implications. Also in this example there are several strings, but they could also be pointing to some sort of variables. So every key in the file can replaced by a function that generates a value. For an example you might have a function autogenerate a large chunk of the values. Well this example might not say much, but what I'm trying to get at is that if you're working with lua, and then you get some sort of data from the game, if it was already in lua format things would more straightforward. Okay I'm sorry this is probably a foolish comment because I don't understand any of these things properly. But I wanted to say something. :D :oops: :hmm: :whistle:

Shiki
Developer
Posts: 232
Joined: July 13th, 2015, 9:53 pm
Location: Germany

Re: Building an alternative to ActionWML

Post by Shiki » October 5th, 2018, 12:17 pm

That looks very interesting. If that would be the format in which UMC is stored it would be way easier to get into Lua, and it looks as intuitive as WML.
Maintainer of Era of Myths.
Introduction to WML filtering and WML variables.

gfgtdf
Developer
Posts: 1110
Joined: February 10th, 2013, 2:25 pm

Re: Building an alternative to ActionWML

Post by gfgtdf » October 5th, 2018, 11:17 pm

eurydike wrote:
October 5th, 2018, 5:49 am

I imagine the implications of attempting to rid the world of ActionWML entirely include positive premises such as changing the standard format for scenario, era, ability & all things WML to such that you'd be writing somesort of lua equivalent datastructures instead of WML datastructures.
I had the same idea so i fully support that idea, there are some minor issues in your examples though:

1)

Code: Select all


    attacks[1]={
        name="great_axe",
        ...
    },
    attacks[2] = {
        name="Horns",
        ...
    },
is invalid lua te correct way is

Code: Select all

    attacks = {{
        name="great_axe",
        ...
      },
      {
        name="Horns",
        ...
      },
    }
2) more importantly #textdomain wesnoth is clearly invalid lua. i see bascially 2 options:

2.1) use vanilly lua that would look like

Code: Select all

local _ = textdomain.wesnoth
return {
  id="old_era_minotaur_warrior",
  name= _ "Minotaur warrior",
  race="old_era_race_minotaur",
  ...
}
2.1) use a custom format like you suggested that is not longer vanilly lua (meanign it cannot be read with luas require or lua dofile)

Code: Select all

## section textdomains
local _ = textdomain.wesnoth
return {
  id="old_era_minotaur_warrior",
  name= _ "Minotaur warrior",
  race="old_era_race_minotaur",
  ...
}

Needless to say if we do that, we will ofcouse still accept wml data input it will just be converted to lua in the parsing step.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.

User avatar
Celtic_Minstrel
Developer
Posts: 1279
Joined: August 3rd, 2012, 11:26 pm
Contact:

Re: Building an alternative to ActionWML

Post by Celtic_Minstrel » October 6th, 2018, 1:27 am

eurydike wrote:
October 5th, 2018, 5:49 am
I imagine the implications of attempting to rid the world of ActionWML entirely include positive premises such as changing the standard format for scenario, era, ability & all things WML to such that you'd be writing somesort of lua equivalent datastructures instead of WML datastructures. For an example consider the unit information like, [attack]keys, [specials].. This format could be changed so that the parser expects a luafile with tables corresponding to the values.
I wasn't even considering going that far to eliminate WML entirely. I'm not going to say "no, we can't do this", but... I don't think we should drop all WML wholesale all at once. Deprecating ActionWML and creating alternatives to it is a good first step; once we get that done, then we can talk about switching away from WML entirely. Personally, I think there's no point in doing so (WML serves its purpose pretty well for most things in Wesnoth, in my opinion), but if it's done properly with a long period during which both the old and the new formats continue to work, then I wouldn't be opposed to it.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.

shevegen
Posts: 204
Joined: June 3rd, 2004, 4:35 pm

Re: Building an alternative to ActionWML

Post by shevegen » October 6th, 2018, 10:46 am

I know too little about the internals and 90% of my experience writing code is in Ruby, so this is not wholly
applicable at all (although ruby or mruby is not that dissimilar in lua, to some extent; at the least I would
consider them to be in the same family).

I personally never liked WML, so I don't think I'd like the extensions, be them ActionWML or anything at
all. I feel that XML is the wrong thing to want to go about dictating program logic, although I understand
that alternatives may not be ideal either, all of the time. Even though I don't like XML, but other formats
are not automatically perfect (like yaml - I like yaml, but yaml can be picky in parsing and is indent-specific,
so ... not great).

Lua is in as much better because it is its own language rather than a custom extension that can only be
used for wesnoth.

On that note I should say that wesnoth is, if you look at it as a whole, really really very good, considering
that it is free. One of my favourite suggestions is to extend the engine to allow it to be used for other
games too, more easily. So on that note, the more alternatives, the better! But at the same time, as
odd as this is ... WML (and its variants) should most likely be preserved, maintained and improved, too.
Even though I'd agree with Celtic_Minstrel. :)

People could use what they would prefer. If wesnoth's engine were usable for other projects, that would
be a good thing, IMO.

So while I think there are reasons in favour of deprecating ActionWML, my suggestion is to focus more
on improving the alternatives (and ignoring ActionWML if you don't like or don't use it).

Otherwise I agree that it should be possible to be able to switch between any alternative whenever so
desired, such as ActionWML or lua.

Would it be useful to have a specification that could be used as a reference for implementations? E.g.
the default one would be what ActionWML allows; past the point of where a specification is added,
every implementation can and should adhere to the possibilities that exist through that specification
(e. g. for when you write scenarios and campaigns).

> The #1 reason why we cannot deprecate ActionWML is that ActionWML is currently the only way
> to write an event.

I think that should definitely be changed. Events should be "triggerable" without ActionWML too.

Edit: Just read that you wrote something similar actually:

-> I'm not precisely in favour of it. I'm on board with dumping ActionWML, though if the decision were solely
mine to make I'd probably keep it around indefinitely as a deprecated API,

Which makes sense.

> If that would be the format in which UMC is stored it would be way easier to get into Lua, and it
> looks as intuitive as WML.

In my opinion, alternatives are good if they can be equivalent. I'd also love to use ruby rather than
lua; and I am sure python folks love to use python rather than lua too. ;) But I think all of this could
happen in the long run. What may be useful is to document all of WML even better, perhaps work
on towards an "agnostic" specification, improve lua too (since it can serve as "bootstrap" language,
as the first alternative to WML, which may be useful lateron) and, well - people would be able to
decide what they'd like to use. (Specification could ensure consistency among implementations;
I noticed some error messages in lua-based scenarios that seem different from WML-centric
errors, e. g. suddenly lua-based errors that appear on the main map interface, which I do not
remember from any WML-centric scenario ... at the least not in this form. May perhaps be
because WML is more tested than lua and more campaigns written with it, I can not say.)

Post Reply