Lua question
Moderator: Forum Moderators
- Captain_Wrathbow
- Posts: 1664
- Joined: June 30th, 2009, 2:03 pm
- Location: Guardia
Lua question
The following code is taken from the 1.7 addon "Wesnoth Lua Pack", published by Melinath. In case you don't know, this was a collection of useful snippets of lua code for people to use.
I want to be able to use these two tags in my campaign, but unfortunately I don't know the first thing about lua, how it works, syntax, or how to embed it in my WML. I'm really not that interested in learning lua right now, (although I's like to get around to it sometime) I just want to be able to use this code. What do I have to do to make those two tags usable in my campaign? Do I have to put that code in a certain place in my campaign's files? Do I need to put it within some other WML tags? Do I need to add anything to my _main.cfg file?
Forgive my ignorance, but I know absolutely nothing about lua... any help is appreciated. Thanks.
code:
Forgive my ignorance, but I know absolutely nothing about lua... any help is appreciated. Thanks.
Re: Lua question
You need to place them in a preload event, like this:
Of course, the event must be in a place that will launch anywhere the new tags are used. So, an [era], or maybe in all your scenarios (if it's a campaign), or an ever-present [unit_type]. You can also make a macro out of the whole event so it's easier to call in all scenarios or something. Anyway, I think you know how that works at that point
Code: Select all
[event]
name=preload
first_time_only=no
[lua]
code=<<
-- The lua snippets here.
>>
[/lua]
[/event]
Jazz is not dead, it just smells funny - Frank Zappa
Current projects: Internet meme Era, The Settlers of Wesnoth
Current projects: Internet meme Era, The Settlers of Wesnoth
- Captain_Wrathbow
- Posts: 1664
- Joined: June 30th, 2009, 2:03 pm
- Location: Guardia
Re: Lua question
And then I can use [store_shroud] and [set_shroud] as if they were normal WML tags?
Huh, that's more simple than I was expecting...
Neat, thanks!
Also, just out of curiosity, why does it have to be first_time_only=no? If it's "preload", wouldn't it only happen once no matter what?
Huh, that's more simple than I was expecting...
Neat, thanks!
Also, just out of curiosity, why does it have to be first_time_only=no? If it's "preload", wouldn't it only happen once no matter what?
- Pentarctagon
- Project Manager
- Posts: 5597
- Joined: March 22nd, 2009, 10:50 pm
- Location: Earth (occasionally)
Re: Lua question
taken from EventWML.wiki wrote:Note: Unlike prestart and start, the preload event must be able to fire more than once! This is because it is triggered each time a savegame is loaded in addition to the initial time when it loads before the scenario 'prestart'. This means that it is effectively mandatory to have the first_time_only=no key value in a preload event.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
take one down, patch it around
-2,147,483,648 little bugs in the code
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: Lua question
A better strategy would be to put the above lua code in a file named (e.g.) wml_tags.lua and to load it like this (untested):
This has the (absolutely fantastic!!!) advantage that the lua code is not loaded during wml preprocessing time meaning that when you (may) want to start editing lua you don't need to go back to the mainscreen to test changes and a lot more goodies. (syntax highlight, wesnoth-independant stack traceback,...)
Code: Select all
[event]
name=preload
first_time_only=no
[lua]
code=<<
helper = wesnoth.require("lua/helper.lua")--you'll also need to load this since those lua functions use it
wesnoth.dofile("~add-ons/Your_Addon_Directory_Name/lua/wml_tags.lua")
>>
[/lua]
[/event]
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
- Captain_Wrathbow
- Posts: 1664
- Joined: June 30th, 2009, 2:03 pm
- Location: Guardia
Re: Lua question
@Pentarctagon: Ah ha. I see.
@Anonymissimus: Interesting. I'll have to try that too.
Thanks, everyone!
@Anonymissimus: Interesting. I'll have to try that too.
Thanks, everyone!