enclave's Lua thread

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

Moderators: Forum Moderators, Developers

Re: enclave's Lua thread

Postby enclave » February 4th, 2017, 11:26 pm

thank you gfgtdf.. you gave me something to think about.. always helpful.
i have 1 million more questions but i don't have time to do anything about it at the moment.. I will come back in couple days.. and I feel I really need an expert for saved games.. somebody who could give me very detailed information of how exactly it all works..

I just tested different version of my add-on.. the latest version has a turn1 autosave.gz size of 3.5 mb (unzipped around 69mb)
i believe its unreloadable straight away...

the previous version autosave turn1 .gz size is 1.8 mb (unzipped around 28 mb) so i believe there is still space to play and reload.. possibly as much as u like..

in very far previous version autosave turn 1 .gz is 861 KB (unzipped around 11mb) so well.. never had any problems with reload file size and never thought there could ever be one..

The autosave even includes the settings for modifications I have (which are not currently used for this save/game), why? Well actually whatever.. if they there, then they needed.. I'm more interested in finding my fault.. what do I do to make initial autosave on turn 1 to become 3.5 mb??? ;( On turn 19 with ~400 units the size becomes 4.85 (only +1 mb.. not bad at all, but why it is already 3.5 mb in the very beginning?)

As I said before, I have 1million questions.. but maybe somebody knows where I should ask this question to get most efficient and correct answers? or advices.. I would like to know what exactly goes into save, how could it fill 3.5 mb space? and what difference it makes to write something with macro, or with fire event or with lua.. in terms of space of the save game.. Looks like I have been writting the mod for around 2 years and I still know nothing about how to do it properly! :(
enclave
 
Posts: 533
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Postby enclave » February 5th, 2017, 7:26 pm

Maybe anyone knows who wrote this https://wiki.wesnoth.org/Wml_optimisation and that https://wiki.wesnoth.org/Advanced_Optim ... _and_Hacks ? I would happily ask that person what would be difference between using lua and firing events in terms of space for turn 1 autosave file size..

I believe my add-on is not only huge in terms of amount of code written and different functionality, but it also tends to have enormous amounts of units on maps.. its limited to 232 units per side.. but when I done the limit it was not really intentional as I never expected to run out of space and being unable to reload games... (as I find performance to be quite good). But I also plan to extend it in future (for example now it has 3 races, in future it will be around 6-7 or maybe more.. adding 2 races increased the turn 1 savefile by around 1 mb).

Please don't get me wrong, I'm not trying to ask as many stupid questions as I can, I just want to know exactly what would be the most efficient way to optimise my code, it is critical, as I don't have 1 extra life to spend on coding my era, - If I manage to change every macro into custom event now and then after adding couple more races I will find out that I need to recode everything again.. into lua or anything else.. I would be very disappointed.. So if I need to change everything now, into something, I would like it to be the most efficient space-saving change or at least very close to it..

Thank you everyone in advance.
enclave
 
Posts: 533
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Postby Ravana » February 5th, 2017, 7:53 pm

I suggest you run preprocessor on affected addon and observe if output has something that it shouldnt have.

Not sure though, how to only get the part that would be included in save... I know I once managed to get 15k lines of that kind to stderr.
User avatar
Ravana
Moderator
 
Posts: 1472
Joined: January 29th, 2012, 12:49 am
Location: Estonia

Re: enclave's Lua thread

Postby James_The_Invisible » February 5th, 2017, 8:18 pm

enclave wrote:Maybe anyone knows who wrote this ...

The wiki saves history for every single page so you can find that out yourself. Just scroll to the very bottom of that page and click History (in your language). But maybe you need to be registered (and logged in) to see that link. For the record, I remember that the second page was written by Dugi.
My content: For Power series
Ports: Danse Macabre Story of the Wose
Royal Guard/Silver Mage
User avatar
James_The_Invisible
 
Posts: 416
Joined: October 28th, 2012, 1:58 pm
Location: Somewhere in the Northlands, fighting dark forces

Re: enclave's Lua thread

Postby gfgtdf » February 5th, 2017, 9:03 pm

Since saves are in (compressed) wml/text format you can just open them with a text edtior and see what takes up all that space, If you don'T know how to uncompress thme you can chanre the comoression method in the wesnoth asvanced preferences to "none" then it won't compress the savefiles anymore and save it as plain text.

enclave wrote:Maybe anyone knows who wrote this https://wiki.wesnoth.org/Wml_optimisation and that https://wiki.wesnoth.org/Advanced_Optim ... _and_Hacks ? I would happily ask that person what would be difference between using lua and firing events in terms of space for turn 1 autosave file size..

I actuall doubt the second page apliyes to your code (since it seems to be mostly writteln with sp stuff in mind), i'd take a look at the first one i think it's quite well written. What it basically said is that (big enough) macros (#define) are bad and make the code ineffcient, unless they are used exactly once. For example mainline has a macro FORCE_CHANCE_TO_HIT (see https://github.com/wesnoth/wesnoth/blob ... s.cfg#L614) which is quite big, it is usually assumed that this macro is uses only once or twice in a scneario so that it doesnt matter that much. But if you wanted to use it many time it's quite inefficient so one would have to think about another solution. OIr course this also applies to other macros that use that macro.
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.
gfgtdf
Developer
 
Posts: 912
Joined: February 10th, 2013, 2:25 pm

Re: enclave's Lua thread

Postby enclave » February 6th, 2017, 8:33 pm

Ravana wrote:I suggest you run preprocessor on affected addon and observe if output has something that it shouldnt have.

Not sure though, how to only get the part that would be included in save... I know I once managed to get 15k lines of that kind to stderr.

How to "run preprocessor" or is there something I can read about it in wikipedia? (if you think it is written in wikipedia, just say yes and I will try to find it myself, whichever you find easier answer, I don't want to spend much of anyone's time, you all very helpful)

James_The_Invisible wrote: The wiki saves history for every single page so you can find that out yourself. Just scroll to the very bottom of that page and click History (in your language). But maybe you need to be registered (and logged in) to see that link.
Thank you! Ravana gave a link for me (so maybe you need to be registered, I don't know, probably not) and I think I found that the original author, but it says he Last visited forum: Thu Oct 22, 2015 1:19 pm (so more than a year ago.. I will message him but I guess I may wait another year for a reply, but anyway it may be helpful, plus he may receive e-mail that somebody messaged him, so there is hope)

gfgtdf wrote:Since saves are in (compressed) wml/text format you can just open them with a text edtior and see what takes up all that space, If you don'T know how to uncompress thme you can chanre the comoression method in the wesnoth asvanced preferences to "none" then it won't compress the savefiles anymore and save it as plain text.

Yeah I have tried to read the wml, but unfortunately I gave up on this (I used 7-zip to uncompress, seems it can uncompress most types of whatever I meet..), the uncompressed size for the latest version is 70mb of text.. (notepad++ seems to be able to open it without any problems or long wait, unlike I assume regular windows notepad would struggle or fail to open) which is 1 million 801 thousands 928 lines.. I managed to find some bits that I think shouldn't be there (like all my other installed add-ons settings etc), but to find the real problem in near 2 million of lines... it's not a task for a human.. so I assume my problem is repeated macros.

Funny that I created the events that contain events, for example if there are Orcs on map, then I fire event that orcs are on map, so this "Orc event" has all related to orcs events with all the macros etc.. but the size of the savefile nearly does not change at all if there are no orcs (maybe couple kilobites).. it doesn't care.. it writes all these macros related to orcs in the basecode of savefile (I "guess" it writes, because I can not check 2 million lines to find out what exactly is in this bloody savefile :D I just read the optimisation and I "believe" the macros are my problem).. I wonder if it could be avoided somehow, I wonder if there is a way to not write all macros related to something that is not going to happen on the map.. with some kind of #ifdef or anything else that I never tried to use? (like if there is no orcs, why write all events and macros into basecode of savefile? they will never appear on map or be used). I guess all the settings are written into basecode of savefile as well.. when in reality maybe a user is using only 20% of settings, the savefile will include all 100% of macros and events related to settings that are not even in use. But like I said, I only "guess" because I "believe" there is no chance for a human being to check all these thousands of lines to find out. My best guess is I need to replace macros with something.. But it creates a lot of questions.

For example, if I change macros to lua, does it mean the replays will be corrupted? How will replay know what was going on if there would be no record of it in savefile? I guess there will be some kind of record.. Will it be smaller than firing event? And if I use fire event, what would be the best way to pass the variables to it? with just {VARIABLE some_variable some_value} or there are better built-in ways? I assume that if I use macro then the macro text will just be copied everywhere and if I use fire event then there will be just a link to the event.. so 1 little line instead of 1000 repeated ones.. ? more or less?
Lua scares me with only one thing, OOS.. one mistake and u are screwed and will only find out that you are screwed some days later in multiplayer game after loads of people already downloaded your add-on and screwed themselves as well..

gfgtdf,
You have 2 options: 1) Insert the lua code in the scenario or 2) read it from disk every time the scenrio is loaded. Option (1) is the safer one, but option (2) allows you to reduce the amount of the 'programming code' (e.g. [event]) in the savefile to 0 but it requires all players to have your addon installed. If you are targeting 1.13 then i reccomend using option (2) since it has a 'download addon on demand' feaute so that reuiring download of an addon is less of an issue.


Ok.. I "think" I understand the option #1.. I just basically insert [lua] code = << >> [/lua] as I go along my cfg files, instead of macros or something like that.
But I completely don't know what you mean by #2 (I would not use it yet anyway, most people are on 1.12 and it looks like they will stay there for a while.. I need to apply the optimization immediately.. so it's not an option at the moment), however I would really like to know what you mean? Which way read it from disk? It makes me think I need to do something in preload event.. am I anywhere near? Ah.. I think I get you.. You are saying that luas that are used like this:
Code: Select all
[lua]
    code = "wesnoth.dofile '~add-ons/Civ_General/macros/new/city.lua'"
[/lua]
would require add-on but not get into savefile code and therefore will consume 0 mb of memory??
Sorry if I ask stupid questions.. and thanks again..
enclave
 
Posts: 533
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Postby Ravana » February 6th, 2017, 8:49 pm

enclave wrote:
Ravana wrote:I suggest you run preprocessor on affected addon and observe if output has something that it shouldnt have.

Not sure though, how to only get the part that would be included in save... I know I once managed to get 15k lines of that kind to stderr.

How to "run preprocessor" or is there something I can read about it in wikipedia? (if you think it is written in wikipedia, just say yes and I will try to find it myself, whichever you find easier answer, I don't want to spend much of anyone's time, you all very helpful)

It is from wesnoth.exe -p. --help has documentation.

I tried it on ageless, it gave 1.2m lines. But most of it is just taken from unit_type hopefully.

I noticed though that 1.1m of it was made out of 2 very similar parts, seems that something is included twice. (Basically I constantly held page down button until indents got suspiciously high, then searching for event ids showed several cases where one event takes 50k lines)


So it might help in finding what events get included too many times, but might not help much.
User avatar
Ravana
Moderator
 
Posts: 1472
Joined: January 29th, 2012, 12:49 am
Location: Estonia

Re: enclave's Lua thread

Postby gfgtdf » February 6th, 2017, 8:58 pm

enclave wrote:Yeah I have tried to read the wml, but unfortunately I gave up on this (I used 7-zip to uncompress, seems it can uncompress most types of whatever I meet..), the uncompressed size for the latest version is 70mb of text.. (notepad++ seems to be able to open it without any problems or long wait, unlike I assume regular windows notepad would struggle or fail to open) which is 1 million 801 thousands 928 lines.. I managed to find some bits that I think shouldn't be there (like all my other installed add-ons settings etc), but to find the real problem in near 2 million of lines... it's not a task for a human.. so I assume my problem is repeated macros.


You don't need to fully understand the savefiles to find out which macors are the problem, you just give your self a rnadom mumber bettwen 1 and the number of lines of that file and then look at that line. Now you try to find out form whcih macro this code comes from and what other macros use that macro, now you have alredy a high change that you foudn the macro(s) that macke the savefile big. In case you didnt find it just repeat this procedure with different rnadom lines ~10 times to be sure

enclave wrote:Funny that I created the events that contain events, for example if there are Orcs on map, then I fire event that orcs are on map, so this "Orc event" has all related to orcs events with all the macros etc.. but the size of the savefile nearly does not change at all if there are no orcs (maybe couple kilobites).. it doesn't care.. it writes all these macros related to orcs in the basecode of savefile (I "guess" it writes, because I can not check 2 million lines to find out what exactly is in this bloody savefile :D I just read the optimisation and I "believe" the macros are my problem).. I wonder if it could be avoided somehow, I wonder if there is a way to not write all macros related to something that is not going to happen on the map.. with some kind of #ifdef or anything else that I never tried to use? (like if there is no orcs, why write all events and macros into basecode of savefile? they will never appear on map or be used). I guess all the settings are written into basecode of savefile as well.. when in reality maybe a user is using only 20% of settings, the savefile will include all 100% of macros and events related to settings that are not even in use. But like I said, I only "guess" because I "believe" there is no chance for a human being to check all these thousands of lines to find out. My best guess is I need to replace macros with something.. But it creates a lot of questions.

For example, if I change macros to lua, does it mean the replays will be corrupted? How will replay know what was going on if there would be no record of it in savefile? I guess there will be some kind of record.. Will it be smaller than firing event? And if I use fire event, what would be the best way to pass the variables to it? with just {VARIABLE some_variable some_value} or there are better built-in ways? I assume that if I use macro then the macro text will just be copied everywhere and if I use fire event then there will be just a link to the event.. so 1 little line instead of 1000 repeated ones.. ? more or less?
Lua scares me with only one thing, OOS.. one mistake and u are screwed and will only find out that you are screwed some days later in multiplayer game after loads of people already downloaded your add-on and screwed themselves as well..


Unless you got for my option (2) this won't mean that the information is no longer in savefiles, it just mens that it is no longer copied 100 times on each savefiles. Look, assume this code:
Code: Select all
#define HEALTHY_UNIT ID X Y TYPE
[unit]
type={TYPE}
id,x,y={ID},{X},{Y}
[modifications]
{TRAIT_HEALTHY}
[/modifications]
[/unit]
#endef
{HEALTHY_UNIT a1 1 2 Knight}
{HEALTHY_UNIT a2 2 2 Knight}
{HEALTHY_UNIT a3 4 2 Knight}

This small code will already copy the wml of {TRAIT_HEALTHY} 3 times in the savefile which is already 80 lines of code in the savefile. This is becasue macros are just copying of text, nothing more. But really, this can all be read the the first optimisation page that you had already.
enclave wrote:gfgtdf,
You have 2 options: 1) Insert the lua code in the scenario or 2) read it from disk every time the scenrio is loaded. Option (1) is the safer one, but option (2) allows you to reduce the amount of the 'programming code' (e.g. [event]) in the savefile to 0 but it requires all players to have your addon installed. If you are targeting 1.13 then i reccomend using option (2) since it has a 'download addon on demand' feaute so that reuiring download of an addon is less of an issue.


Ok.. I "think" I understand the option #1.. I just basically insert [lua] code = << >> [/lua] as I go along my cfg files, instead of macros or something like that.
But I completely don't know what you mean by #2 (I would not use it yet anyway, most people are on 1.12 and it looks like they will stay there for a while.. I need to apply the optimization immediately.. so it's not an option at the moment), however I would really like to know what you mean? Which way read it from disk? It makes me think I need to do something in preload event.. am I anywhere near? Ah.. I think I get you.. You are saying that luas that are used like this:
Code: Select all
[lua]
    code = "wesnoth.dofile '~add-ons/Civ_General/macros/new/city.lua'"
[/lua]
would require add-on but not get into savefile code and therefore will consume 0 mb of memory??
Sorry if I ask stupid questions.. and thanks again..

Yes that's what i ment, wesnoth.dofile reads the file form the disk do it requires all users to have that addon installed.
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.
gfgtdf
Developer
 
Posts: 912
Joined: February 10th, 2013, 2:25 pm

Re: enclave's Lua thread

Postby enclave » February 6th, 2017, 9:10 pm

Ravana wrote:I tried it on ageless, it gave 1.2m lines. But most of it is just taken from unit_type hopefully.

I noticed though that 1.1m of it was made out of 2 very similar parts, seems that something is included twice. (Basically I constantly held page down button until indents got suspiciously high, then searching for event ids showed several cases where one event takes 50k lines)

So it might help in finding what events get included too many times, but might not help much.


Thank you Ravana, I will try to have a look. Hope to clear some megabytes off my savefiles within this week.. will start with fire event as I know what macros I changed that doubled the savefile size.. will replace that with fire event..
so after that I will have some relaxed time for testing different optimization things if fire_event can fix the problem. Now I just urgently need to fix it at least a little bit and make players happy :D Will report back if any success... Thanks everyone!!!


EDIT: I have changed some macros (not too many not too few.. but ones that often repeated and were very basic) into fire event and it decreased around 500kb of compressed savefile size, which I find really great. What more important, is the new macros performed with fire event nearly adding no kilobytes to the savefile.. So in short, the effect is HUGE and changing all repeated macros info fire event will free enormous amount of spaces in my mod, making it tiny soon enough or at least it will not have any save/reload issue for at least couple years, which means I don't need to convert it to lua now for even more effect. The importance of fire event should be emphasized more in future.. It is also relatively easy to convert macros into fire events. I will have some questions regarding fire events and macros soon, but it will be in another thread (WML), not here.
Very happy with results. Not sure if fire events will work slower than macros though.. Time will tell. (I have also tried to backgrade the version of my mod before one of the new features that were space consuming, it freed around 700kb of compressed space, which was 23MB of uncompressed space, - just removing related macros. Later when I converted that new feature macros into fire events, it added around nothing to my mod, so just to emphasize again, the impact of changing macros into fire events regarding space-saving is HUGE and shouldn't be underestimated. Same code with pure macros which is 23MB of WML space may become 0MB if converted into purely fire events).
enclave
 
Posts: 533
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Postby enclave » February 19th, 2017, 12:04 am

Hi, anyone tried or has ideas how to synchronize select event?
Thanks in advance.

PS. maybe if i fire event inside of select event or some other hacks possibly? I will try different things if nobody has ideas. Thanks :)
enclave
 
Posts: 533
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Postby enclave » February 19th, 2017, 8:14 pm

gfgtdf wrote:when yourin an normal select event triggered by the user, your only change to make gamestate changes in a synced way is to
1) use ai.synced_command or [do_command] like i said before.
2) Set some variable and use that in a later synced evnet, for example a moveto event, in this case you must quer< that variable withvia wesnoth.synchronize_choice


lol, my memory is really really really bad (and it's true..).. thanks gfgtdf, I like your #2 hint..
Will experiment with that.. but moveto doesnt work for my project.. so will have to find some other event that works. Shouldnt be a problem. Good thing that all my previous posts come up in google.. so I can actually google what I forgot and find it :) So i'm happy to know that all these we post here may help somebody else as well.. Will post some codes if anything worked for me in my 1.12 version..
enclave
 
Posts: 533
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Postby enclave » February 25th, 2017, 12:52 am

Turned out to be very simple for my goal..

First, you have some select event like so:
Code: Select all
[event]
name=select
first_time_only=no
   [store_unit]
   variable=selected_unit
   [filter]
   x,y=$x1,$y1
   [/filter]
   [/store_unit]
[/event]

Select event is unsynced.. so whatever you do there would cause OOS if it affects what other players see or have (change their units hp.. blocks their way.. message them some info from this event.. etc)
To synchronize it with other players you need to run some other event (known to be synced, from the list: https://wiki.wesnoth.org/EventWML ctrl+f "multiplayer safety" or "List of synchronized events"), and use lua wesnoth.synchronize_choice (https://wiki.wesnoth.org/LuaWML/Misc#we ... ize_choice) code to synchronize it.. I will show how in next blocks.

Then you have some right click menu where you would like to use unsynced variable from select event and turn it into synced variable like so:
Code: Select all
[set_menu_item]
      description=_"~Tell Others What Unit I Selected"
      image=items/archery-target-right.png~CROP(25,28,25,28)~SCALE(25,25)
      [command]
                       [lua]
                       code = <<
local result = wesnoth.synchronize_choice(
function()
return { value = wesnoth.get_variable("selected_unit.name") }
end,
function()
return { value = wesnoth.get_variable("selected_unit.name") }
end)
wesnoth.set_variable("selected_unit.name",result.value)
                       >>
                       [/lua]
                       [message]
message="Im letting everyone know that I have selected unit with name $selected_unit.name"
                       [/message]
      [/command]
[/set_menu_item]


its very simple.. you dont need to change anything in this part:
Code: Select all
local result = wesnoth.synchronize_choice(
function()

then you need to change this part into the name of your unsynced variable:
return { value = wesnoth.get_variable("your_unsynced_variable_name_here") }
then not change anything here:
Code: Select all
end,
function()

then u may copy the same thing u done before into here or possibly even delete it, not sure:
return { value = wesnoth.get_variable("your_unsynced_variable_name_here_ai_choice") }
the second time it is only needed if you have ai that could also somehow use your right click menu and would be offered a choice.. in this case his choice of variable would be "your_unsynced_variable_name_here_ai_choice".. so he wouldnt actually be given any choice.. it would always result whatever you written there.. (blah blah.. its complicated to explain if you dont have a dialog with inputs like in default example of wiki)
And then you need to change the result.. without changing end)
but just to change result.value.. ideally it will be the same name.. you had in your select event.. to avoid mistakes.. I think..
wesnoth.set_variable("your_unsynced_variable_name_here",result.value) but this time it is synchronized now.. all other players will know that variable and it will be same for everyone.. no OOS (out of sync errors: https://wiki.wesnoth.org/OOS_(Out_of_Sync)) if you decide to use $your_unsynced_variable_name_here this variable to change gamestate (damage some enemy unit for that amount of hitpoints.. or create some terrain that will affect enemy movements.. or movements of your units that would affect enemy in any future.. etc etc..)

I found wiki example be useful but overcomplicated... T.Option .. blabla.. very complicated if you don't know lua and need to synchronize something basic but not dialog.. I had no idea what to remove, what to keep.. but it worked right after first trial.. very lucky.
enclave
 
Posts: 533
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Postby gfgtdf » February 25th, 2017, 1:55 pm

enclave wrote:Turned out to be very simple for my goal..
... ..and use lua wesnoth.synchronize_choice (https://wiki.wesnoth.org/LuaWML/Misc#we ... ize_choice) code to synchronize it..

wesnoth 1.13 also has a [sync_variable] https://wiki.wesnoth.org/InternalAction ... ariable.5D tag made specificly for cases like this if you don't want to use lua.
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.
gfgtdf
Developer
 
Posts: 912
Joined: February 10th, 2013, 2:25 pm

Re: enclave's Lua thread

Postby enclave » March 2nd, 2017, 8:38 pm

Ok... finally some lua questions..
I'm trying to keep my code optimized now, so.. this is more or less optimization question.. but its touching LUA, not WML..
I had a problem with [fire_event]
The problem was that if I use some code in moveto event that has [fire_event] in it then either a unit stops before reaching target or it stops before attacking and need to select it again and choose attack etc.. I dont like it to happen, its annoying.. so I changed my repeated code into {MACRO}... stupidly it's all in lua, inside that macro.. so I ideally could create a lua function..
1) but how to create a function in lua, which could be called in multiple events? where do I write that function? is it a global function? I really have no idea.. when I done any lua functions they were local.. and were happening right there.. in the same event.. or context.. please if somebody answers this, could you write a detailed example (short one, but full), I'm really stupid to understand shortcuts.. Thanks in advance..

PS. i found that fire event seems not have affect on it.. same happens in macro.. problem must be somewhere else. but maybe lua function/procedure could still help. forgot my other questions.. one of which wasnt lua.. but WML..
enclave
 
Posts: 533
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Postby gfgtdf » March 2nd, 2017, 9:28 pm

enclave wrote:1) but how to create a function in lua, which could be called in multiple events? where do I write that function? is it a global function? I really have no idea.. when I done any lua functions they were local.. and were happening right there.. in the same event.. or context.. please if somebody answers this, could you write a detailed example (short one, but full), I'm really stupid to understand shortcuts.. Thanks in advance..


You define a custom wml tag with wesnoth.wml_actions this is also explained at the wiki page about lua also there are plenty of examples since most other tags, inclusing [fire_event],[if], [store_side] and many others (see wml-tags.lua file) are implemented like that. Usually you do this in a preload event.
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.
gfgtdf
Developer
 
Posts: 912
Joined: February 10th, 2013, 2:25 pm

PreviousNext

Return to Lua Labs

Who is online

Users browsing this forum: No registered users and 1 guest