dumb questions about lua

Discussion of Lua and LuaWML support, development, and ideas.

Moderator: Forum Moderators

Post Reply
User avatar
Boldek
Posts: 576
Joined: April 14th, 2011, 6:37 pm

dumb questions about lua

Post by Boldek »

Hello!
I am planning an empire builder, and after checking other works, I figured I was going to need to learn Lua. So after reading the wiki page, I'm still slightly confused.
What does Lua do that normal wml cannot?
How and when is Lua used in an event?

Thanks!
Guys I never thought I'd come back to this forum after 8 years this is wild
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: dumb questions about lua

Post by Anonymissimus »

Boldek wrote:What does Lua do that normal wml cannot?
Most importantly, it can "reload" and execute changed action lua (or wml) on-the-fly, that means, without the need to go to the mainscreen, press F5, and restart the scenario in order to reflect changes, making developing/debugging addons *much* more fast and convenient. (This was the main reason for me to start with lua.)

There is quite a number of powerful features which are not available in wml and also can't be made available easily. wesnoth.synchronize_choice and the wesnoth.game_events.x stuff for instance.

I leave the other questions for our growing lua coder community. ^_^
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
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: dumb questions about lua

Post by Elvish_Hunter »

Boldek wrote:What does Lua do that normal wml cannot?
A lot of things. Lua can be used even to create new WML tags, and the Wesnoth Lua Pack is an example of this. Also, Lua is much faster than WML, at the point that in the Lua equivalent of the {FADE_*} macros, I had to add an additional key to control the speed of fading.
Boldek wrote:How and when is Lua used in an event?
I usually use Lua to create additional tags; in certain situations, one can also embed Lua code in a WML file, by using the [lua] tag, but then the on-the-fly reload won't work anymore.
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
User avatar
artisticdude
Moderator Emeritus
Posts: 2424
Joined: December 15th, 2009, 12:37 pm
Location: Somewhere in the middle of everything

Re: dumb questions about lua

Post by artisticdude »

If you're just starting Lua and you don't have a whole lot of programming experience other than WML, I'd suggest taking a look at these links (they helped me get started). They aren't Wesnoth-specific, but they'll help you get to know the language to some extent, which should make programming lua for Wesnoth purposes a bit easier. :)

http://lua.gts-stolberg.de/en/index.php
http://foldit.wikia.com/wiki/Lua_Script ... eginner_1)

The Lua reference manual on http://www.lua.org can also be helpful, but since it's a reference rather than a tutorial it might not necessarily be the best place to start from if you haven't had a whole lot of programming experience in the past.

EDIT: Some of the links in this thread on the Unreal Software forums lead to some very nice Lua tutorials designed for beginners.
"I'm never wrong. One time I thought I was wrong, but I was mistaken."
User avatar
lipk
Posts: 637
Joined: July 18th, 2011, 1:42 pm

Re: dumb questions about lua

Post by lipk »

And here's a short reference which I found very useful too.
User avatar
Boldek
Posts: 576
Joined: April 14th, 2011, 6:37 pm

Re: dumb questions about lua

Post by Boldek »

Thanks everyone!
Guys I never thought I'd come back to this forum after 8 years this is wild
User avatar
battlestar
Posts: 690
Joined: January 1st, 2007, 7:12 am

Re: dumb questions about lua

Post by battlestar »

I'm reading this book:
Image

I find it an enjoyable easy read, especially with a lot of examples. But reading a whole book probably covers more than what's necessary.
LUA: Llama Under Apprenticeship
Hell faction: completed
User avatar
Roraborialis
Posts: 12
Joined: April 15th, 2012, 10:41 pm

Re: dumb questions about lua

Post by Roraborialis »

Elvish_Hunter wrote:
Boldek wrote:How and when is Lua used in an event?
I usually use Lua to create additional tags; in certain situations, one can also embed Lua code in a WML file, by using the [lua] tag, but then the on-the-fly reload won't work anymore.
So I could, for instance, make a tag that would do to defense ratings what steadfast does to resistances, and reuse it whenever I need to make a new ability for handling a defense rating boosting ability, or damaging attack? Or a tag for causing a given ability to target your target instead of yourself? One which causes an effect to last for a turn?
Is WML's tag framework written in lua?
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: dumb questions about lua

Post by Anonymissimus »

Partly it is. The other parts are in C++.
Do note that you can only create new action tags. For abilities you'd need event-driven ones.
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
User avatar
Roraborialis
Posts: 12
Joined: April 15th, 2012, 10:41 pm

Re: dumb questions about lua

Post by Roraborialis »

Anonymissimus wrote:Partly it is. The other parts are in C++.
Do note that you can only create new action tags. For abilities you'd need event-driven ones.
So I cannot do an entire skill via lua, Not exactly what I was asking, but I should have worded it and it is good to know. Thank you.
So, Of the following, what could possibly be made into a working tag:
Use a tag for variable logic.
Trigger a predetermined WML event using variables written within the tag:
Examples:

Code: Select all

[DefRating]
sub=20
##Add, sub, divide, or multiply are all valid.
terrain=
##Uses normal terrain values. Leave blank or omit to include all terrains.
dur=turn
##Where Turn, Cure, and till Move are valid. Omit for it to be active whenever the conditions for it to be met.
[/DefRating]
[DefRating] having a WML script embedded in the lua that effects a units defense rating.
Example usage: Units that have increased defense ratings at night. An attack that causes the target to become more likely to become hit.

Code: Select all

[Filter]
[Trigger]
Trigger on=2
##Trigger on being the value that T will trigger the event
And=4
##Secondary variable needed for the trigger to work, omit or leave blank. It is represented by A.
Not=1
##Teritiary variable that if met, will prevent the trigger from activating.
[/Trigger]
[/Filter]
If all conditions in the trigger tag are met through the WML code, the filter is considered passing.
Example usage in practice: If the unit hits twice and has attacked four times without getting hit, trigger extra attacks.
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: dumb questions about lua

Post by Elvish_Hunter »

Roraborialis wrote:One which causes an effect to last for a turn?
Please note that, from 1.11.0, support for [object] duration=turn will be available.
Roraborialis wrote:Example usage in practice: If the unit hits twice and has attacked four times without getting hit, trigger extra attacks.
This seems me like a thing that can be done with event-driven abiities. The right place for asking these things will be the WML Workshop then.
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
User avatar
8680
Moderator Emeritus
Posts: 742
Joined: March 20th, 2011, 11:45 pm
Location: The past

Re: dumb questions about lua

Post by 8680 »

Elvish_Hunter wrote:The right place for asking these things will be the WML Workshop then.
...If you want to use WML. If you want to use Lua, you should start your own thread here in Lua Labs, or have this one split.
Post Reply