enclave's Lua thread
Moderator: Forum Moderators
Re: enclave's Lua thread
I will try that, thanks! my lua skills are like a beginner beginner level.. this helps me understand more about lua arrays.. structure..
A question.. would it look like this then?
What about them being stored in pairs? Would i be able to do something like this ![Wink ;)](./images/smilies/icon_wink.gif)
A question.. would it look like this then?
Code: Select all
local saved_terrains = wesnoth.get_locations { x = "5", y = "25", { "not", { terrain = "M*,W*,M*^*,W*^*,Ai*,Ai*^*,Rrc,Q*,X*,Q*^*,X*^*,Iwr,Rp^Ecf,Rp^Dr,_off^_usr"} } })
for i=0,saved_terrains.length,1 do ... end
later? or this this some kind of different type of array? if i do wesnoth.set_variable("ns_saved_terrains",saved_terrains)
would it work? would it be same wml array? You can see how bad I am at lua when you see my questions ![Wink ;)](./images/smilies/icon_wink.gif)
Re: enclave's Lua thread
>What about them being stored in pairs?
You can iterate them as pairs like your example does.
>Would i be able to do something like this for i=0,saved_terrains.length,1 do ... end later? or this this some kind of different type of array?
Lua only has tables - no special array types. So, possible, but unless you need to manipulate those indexes, better use pairs.
>if i do wesnoth.set_variable("ns_saved_terrains",saved_terrains) would it work? would it be same wml array?
It will not.
You can iterate them as pairs like your example does.
>Would i be able to do something like this for i=0,saved_terrains.length,1 do ... end later? or this this some kind of different type of array?
Lua only has tables - no special array types. So, possible, but unless you need to manipulate those indexes, better use pairs.
>if i do wesnoth.set_variable("ns_saved_terrains",saved_terrains) would it work? would it be same wml array?
It will not.
Re: enclave's Lua thread
Another code requiring translation.. otherwise im stuck (and btw i have no idea how ipairs work.. never met something to work in pairs in any programming language i seen so far)
how to translate it into wesnoth.fire ?
or with local xbegin xend ybegin yend
or some other way?
Code: Select all
[store_locations]
x=$xbegin-$xend
y=$ybegin-$yend
[not]
terrain=_off^_usr
[/not]
variable=ns_cube
[/store_locations]
Code: Select all
wesnoth.fire("store_locations",
{ x="$xbegin-$xend", y="$ybegin-$yend", not { terrain="_off^_usr" }, variable="ns_cube"})
Code: Select all
wesnoth.fire("store_locations",
{ x="xbegin-xend", y="ybegin-yend", not { terrain="_off^_usr" }, variable="ns_cube"})
Re: enclave's Lua thread
Lua does not evaluate your $. I think you know by now how to transfer simple variables between WML and Lua.
I think your not needs extra {}.
I think your not needs extra {}.
Re: enclave's Lua thread
that's the right way to write it:
xbegin xend ybegin yend are locals
Code: Select all
wesnoth.fire("store_locations",
{ x=xbegin-xend, y=ybegin-yend, variable="ns_cube3", { "not", { terrain="Gg,Mm,Hh" }} })
Re: enclave's Lua thread
A question..
It is known that lua causes OOS if used math.random, will it still cause OOS if we do math.randomseed(1234) prior to it? It should generate same sequences of number for all players or no? would it still need synchronization?
It is known that lua causes OOS if used math.random, will it still cause OOS if we do math.randomseed(1234) prior to it? It should generate same sequences of number for all players or no? would it still need synchronization?
Re: enclave's Lua thread
If you set seed in synchronised way, all players get same sequence. Obviously, if you set it to constant, you wont get any randomness.
Re: enclave's Lua thread
Hi, I'm trying to use this:
wesnoth.fire("replace_map",{map="{campaigns/Heir_To_The_Throne/maps/01_The_Elves_Besieged.map}",expand="yes",shrink="yes"})
wesnoth.fire("replace_map",{map="{add-ons/Optimisation_Tester/maps/4p_A_New_Land.map}",expand="yes",shrink="yes"})
i tried tons of different ways and nothing works, always same error:
a terrain with a string with more than 4 characters has been found, the affected terrain is : {add-ons/Optimisation_Tester/maps/4p_A_New_Land.map}
[replace_map] works fine, but lua doesn't how to replace "{" with string so that it doesnt think of it as about a table?? or what I need to do to make it work? Thanks!
wesnoth.fire("replace_map",{map="{campaigns/Heir_To_The_Throne/maps/01_The_Elves_Besieged.map}",expand="yes",shrink="yes"})
wesnoth.fire("replace_map",{map="{add-ons/Optimisation_Tester/maps/4p_A_New_Land.map}",expand="yes",shrink="yes"})
i tried tons of different ways and nothing works, always same error:
a terrain with a string with more than 4 characters has been found, the affected terrain is : {add-ons/Optimisation_Tester/maps/4p_A_New_Land.map}
[replace_map] works fine, but lua doesn't how to replace "{" with string so that it doesnt think of it as about a table?? or what I need to do to make it work? Thanks!
Re: enclave's Lua thread
[args] I guess. Or do the inclusion manually. I think 1.13 Lua has support to read files too.
Re: enclave's Lua thread
i tried to google [args] lua, but couldn't find anything.. what do you mean? Thanks
Re: enclave's Lua thread
ctrl+f would have helped. Or search. When you search for
args
you get 6 results, 3. is most useful.Re: enclave's Lua thread
thanks, but my level of lua didn't let me understand any of them to find them useful. I'll just workaround if nobody knows how to solve the problem, its a lot quicker. If i find solution in future I'll post it, so far just to let people know, things like
Ok,didn't work.
But has worked ![Wink ;)](./images/smilies/icon_wink.gif)
And just to give people more examples of how it works:
\{
\}
didn't work.Ok,
Code: Select all
local string st = "{campaigns/Heir_To_The_Throne/maps/01_The_Elves_Besieged.map}"
wesnoth.fire("replace_map",
{map = st, expand = "yes" , shrink = "yes" })
But
Code: Select all
{VARIABLE st "{campaigns/Heir_To_The_Throne/maps/01_The_Elves_Besieged.map}"}
[lua]
code = <<
wesnoth.fire("replace_map",
{map = wesnoth.get_variable("st"), expand = "yes" , shrink = "yes" })
>>
[/lua]
![Wink ;)](./images/smilies/icon_wink.gif)
And just to give people more examples of how it works:
{campaigns/Heir_To_The_Throne/maps/01_The_Elves_Besieged.map}
to get campaign map{~add-ons/Optimisation_Tester/maps/4p_A_New_Land.map}
to get map from any of your installed add-ons{multiplayer/maps/4p_A_New_Land.map}
to get any default multiplayer map that comes together with Wesnoth clean install.Spoiler:
Re: enclave's Lua thread
hi, any ideas why this filter would not work?
The particular place is I tried multiple versions with
Thanks..
Code: Select all
local bool bb = wesnoth.match_location(xx, yy, { terrain = wesnoth.get_variable("fvar_terrains"), { "not", { "filter_adjacent_location", { terrain = wesnoth.get_variable("fvar_village_type") } } } })
{ "not", { "filter_adjacent_location",
because the following below code is working perfectly fine:
Code: Select all
local bool b = wesnoth.match_location(xx, yy, { terrain = wesnoth.get_variable("fvar_terrains"), { "filter_adjacent_location", { terrain = wesnoth.get_variable("fvar_village_type") } } })
not
after filter adjacent location... and without brackets.. doesn't work for me, says "bad argument #3, WML table expected, got table"Thanks..
Re: enclave's Lua thread
You need an additional
Edit: I mean, not just around that string, but around the string and the actual filter that follows it.
{}
around "filter_adjacent_location"
?Edit: I mean, not just around that string, but around the string and the actual filter that follows it.
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
Re: enclave's Lua thread
Thanks mattsc, I['m quite sure I already tried it and it didnt work.. so workaround was just to use some obvious and unneeded filter..mattsc wrote:You need an additional{}
around"filter_adjacent_location"
?
Edit: I mean, not just around that string, but around the string and the actual filter that follows it.
Something like that
local bool bb = wesnoth.match_location(xx, yy, { terrain = wesnoth.get_variable("fvar_terrains"), "not", { x=0, { "filter_adjacent_location", { terrain = wesnoth.get_variable("fvar_village_type") } } } })
not sure exactly now.. lazy to search how i "solved" it.. since nobody cares. if anyone really needs it, just ask me.