enclave's Lua thread
Moderator: Forum Moderators
Re: enclave's Lua thread
Can't get this function to return anything other than error.. any ideas?gfgtdf wrote:Code: Select all
function get_vieweing_side_income() return helper.get_child(wesnoth.theme_items.income, "text") end
I'm trying to use it like this:
Code: Select all
local abc = get_vieweing_side_income()
wesnoth.message("bum","bum" .. abc .. "bum")
Re: enclave's Lua thread
Your code is wrong in in 2 ways:Can't get this function to return anything other than error.. any ideas?
I'm trying to use it like this:
1)
wesnoth.theme_items.income
is a function, to get the wml table you need to call it with () at the end, like in wesnoth.theme_items.income()
2)
helper.get_child(cfgm nam)
is a returns a, returns subtag of a waml table to, get an attibute like text=3, just use cfg.text
. Not however that text is no atribute of wesnoth.theme_items.income()
it is a attribute of a [element]
child of wesnoth.theme_items.income()
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.
Re: enclave's Lua thread
Sorry I have now tried multiple version of what you said, including these 2:
and
it always returns error about me concatenating nil value (local if "cfg.text" or global if cfg.text without brackets)
I tried different ways.. no success.. any ideas?
Can't I just extract that upkeep text somehow like so (I just don't know the exact structure..): ?
Code: Select all
function get_vieweing_side_upkeep()
return helper.get_child(wesnoth.theme_items.upkeep(), "cfg.text")
end
local abc = get_vieweing_side_upkeep()
wesnoth.message("bum","bum" .. abc .. "bum")
Code: Select all
function get_vieweing_side_upkeep()
return helper.get_child(wesnoth.theme_items.upkeep(), cfg.text)
end
local abc = get_vieweing_side_upkeep()
wesnoth.message("bum","bum" .. abc .. "bum")
I tried different ways.. no success.. any ideas?
Can't I just extract that upkeep text somehow like so (I just don't know the exact structure..):
Code: Select all
t = wesnoth.theme_items.upkeep()
local abc = t["element"].["text"]
Re: enclave's Lua thread
No your first have to extract the subtag wne then use
.text
on that subtag:
Code: Select all
local whole_wml = wesnoth.theme_items.upkeep()
local element_subtag = wesnoth.get_child(whole_wml, "element")
local text = element_subtag.text
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.
Re: enclave's Lua thread
yyyyyyyyyyyyyyaaaaaaaaaay it finally worked..
I corrected your code a little bit, it contained mistakes but after trial and error it worked!
it finally gave me what i needed, thanks so much gfgtdf!!!!!!!!!!!!
by the way, any ideas how to read particular text[number] of element? There may be many.. T.elements
maybe
PS. and you were right, with income it would be easier..
actually I tried with income, but because it is negative in my case and I could not replicate the "-" sign for some reason, I had to do it with upkeep
AND IT WORKS! it shows different reources depending on who's turn it is!
I made sure that each side upkeep is equal to $side_number and then used this code:
At the moment my problem is that when I end turn, side loses this new resource bar, so it only shows for whoever turn it is, but it is great! it means tomorrow I will fix it and it will work perfectly and soon I will update my mod with a new nice resource display bar!!!!!!!!! me happy, players happy!! Thanks again and again gfgtdf!!!
I corrected your code a little bit, it contained mistakes but after trial and error it worked!
Code: Select all
local whole_wml = wesnoth.theme_items.upkeep()
local element_subtag = helper.get_child(whole_wml, "element")
local abc = element_subtag.text
wesnoth.message("bum","bum" .. abc .. "bum")
by the way, any ideas how to read particular text[number] of element? There may be many.. T.elements
maybe
local element_subtag = helper.get_child(whole_wml, "element[1]")
? if you know what I mean..PS. and you were right, with income it would be easier..
actually I tried with income, but because it is negative in my case and I could not replicate the "-" sign for some reason, I had to do it with upkeep
AND IT WORKS! it shows different reources depending on who's turn it is!
I made sure that each side upkeep is equal to $side_number and then used this code:
Code: Select all
[event]
name=turn refresh
first_time_only=yes
##
[lua]
code=<<
local old_display_terrain = wesnoth.theme_items.terrain
wesnoth.theme_items.terrain = function()
local oldvalue = old_display_terrain()
--
local whole_wml = wesnoth.theme_items.upkeep()
local element_subtag = helper.get_child(whole_wml, "element")
local abc = element_subtag.text
if (abc == wesnoth.get_variable("side_number").." ".."("..wesnoth.get_variable("side_number")..")") then
local newtag1 = T.element { image="items/straw-bale1.png~SCALE(32,32)~CROP(7,7,18,18)~SCALE(18,18)",
tooltip="food" }
local newtag2 = T.element { text=wesnoth.get_variable("player["..wesnoth.get_variable("side_number").."].food").." ",
tooltip="Amount of food current side has"}
--
local newtag3 = T.element { image="terrain/forest/deciduous-summer-small.png~CROP(42,35,63,75)~SCALE(18,18)",
tooltip="wood" }
local newtag4 = T.element { text=wesnoth.get_variable("player["..wesnoth.get_variable("side_number").."].wood").." ",
tooltip="Amount of wood current side has"}
--
local newtag5 = T.element { image="scenery/rock2.png~CS(42,42,42)~CROP(12,17,53,40)~SCALE(16,16)",
tooltip="stone" }
local newtag6 = T.element { text=wesnoth.get_variable("player["..wesnoth.get_variable("side_number").."].stone").." ",
tooltip="Amount of stone current side has"}
--
local newtag7 = T.element { image="items/gold-coins-small.png~CROP(22,24,31,30)~SCALE(17,17)",
tooltip="gold" }
local newtag8 = T.element { text=wesnoth.get_variable("player["..wesnoth.get_variable("side_number").."].gold").." ",
tooltip="Amount of gold current side has"}
table.insert(oldvalue,1,newtag1)
table.insert(oldvalue,2,newtag2)
table.insert(oldvalue,3,newtag3)
table.insert(oldvalue,4,newtag4)
table.insert(oldvalue,5,newtag5)
table.insert(oldvalue,6,newtag6)
table.insert(oldvalue,7,newtag7)
table.insert(oldvalue,8,newtag8)
end
return oldvalue
end
>>
[/lua]
[/event]
Re: enclave's Lua thread
Hi, is there a way to find out that players chosen random race or picked one?
Thank you..
PS. and if possible to know who picked random and who didn't..?
Thank you..
PS. and if possible to know who picked random and who didn't..?
Re: enclave's Lua thread
Not sure, why do you want that?enclave wrote:Hi, is there a way to find out that players chosen random race or picked one?
Thank you..
PS. and if possible to know who picked random and who didn't..?
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.
Re: enclave's Lua thread
I wanted to make an option.. that would randomize the race if mirror. But I thought it would be good if it only worked for people who chosen random..
For example if my add-on had 3 different races, humans, orcs and elves.
player 1 chosen humans,
player 2 chosen random
player 3 chosen random.
host chosen in options to make all races different so they don't repeat.
So I thought would be good idea if player 1 would remain with humans, no matter what.. and only player2 and player 3 would get something different (Orcs and Elves), so every player has different race.
If i make such script it will change every single race.. even if player picked humans. But I thought would be great if the ones who picked would not suffer.
Any ideas?
Thanks!
For example if my add-on had 3 different races, humans, orcs and elves.
player 1 chosen humans,
player 2 chosen random
player 3 chosen random.
host chosen in options to make all races different so they don't repeat.
So I thought would be good idea if player 1 would remain with humans, no matter what.. and only player2 and player 3 would get something different (Orcs and Elves), so every player has different race.
If i make such script it will change every single race.. even if player picked humans. But I thought would be great if the ones who picked would not suffer.
Any ideas?
Thanks!
Re: enclave's Lua thread
I don't know how exactly but there are other random-no-mirro addons so i think it's possible.enclave wrote:I wanted to make an option.. that would randomize the race if mirror. But I thought it would be good if it only worked for people who chosen random..
Also note that wesnoth 1.13 has random-no-mirror function in it so such an addon will be unnecessary in wesnoth 1.13
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.
Re: enclave's Lua thread
I "think" none of these add-ons would ignore randomization if player has chosen his race, I may be wrong but I'm quite sure that even if player chosen he wants to be Orcs he could end up being Human or Drake or other with any of the currently existing no mirror add-ons.gfgtdf wrote: I don't know how exactly but there are other random-no-mirro addons so i think it's possible.
Also note that wesnoth 1.13 has random-no-mirror function in it so such an addon will be unnecessary in wesnoth 1.13
If you have 1.13 installed, could you check what will happen for me?
Start a local game for 6 players in default era,
player 1 pick Random
player 2 pick Random
player 3 pick Random
player 4 pick Northerners
player 5 pick Random
player 6 pick Random
Enable no-mirror option (you said it has been implemented into 1.13)
And tell me if player 4 remained Northerners? If possible host same thing 3 times, to make sure that it happens the same all the time.
My idea of my add-on was to make sure that player 4 will remain Northerners, but every other race will be no mirror, hence the question.. if there is a way to find out who picked race and who picked random..
Thanks very much in advance if you could find a few minutes to test it for me.. I have no 1.13 installed unfortunately..
Re: enclave's Lua thread
https://wiki.wesnoth.org/SideWML "chose_random: (Version 1.13.0 and later only) indicates if a side chose a random faction during creation"enclave wrote:Hi, is there a way to find out that players chosen random race or picked one?
Thank you..
PS. and if possible to know who picked random and who didn't..?
Re: enclave's Lua thread
Sry, but (assuming that your OS is directly supported by wesnoth and you don't need to compile it yourself) i think installing 1.13.6 is actulally less work than doing these tests. So i'm not really motivated to so these things for you.enclave wrote: Thanks very much in advance if you could find a few minutes to test it for me.. I have no 1.13 installed unfortunately..
the wiki might be wrong here so it possibel that its supported on 1.12 aswell.Ravana wrote:https://wiki.wesnoth.org/SideWML "chose_random: (Version 1.13.0 and later only) indicates if a side chose a random faction during creation"enclave wrote:Hi, is there a way to find out that players chosen random race or picked one?
Thank you..
PS. and if possible to know who picked random and who didn't..?
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.
Re: enclave's Lua thread
thanks to both of you;)
Re: enclave's Lua thread
A strange question.. Looks like my mod's save file size has reached the limit..
When somebody (including me) tried to reload a save of New Settlers in multiplayer, it didn't let us and was said that it has reached the 40mb wml size or something similar. What would be the most efficient way to reduce the size?
I looked into the wml code of the save.. and wow.. it saves a lot of things.. first thing that came to my mind, was that.. if I do all the calculations in LUA instead of WML would it help?
for example if i understand things right then if I sort an array in WML then it will all be stored into saved file, but what if I do all calculations in lua and only save results in wml variables? Will it cause OOS or will it reduce the size of save file?
I know that clearing as many variables as possible would help.. but what else can help? and what helps most?
Thanks..
When somebody (including me) tried to reload a save of New Settlers in multiplayer, it didn't let us and was said that it has reached the 40mb wml size or something similar. What would be the most efficient way to reduce the size?
I looked into the wml code of the save.. and wow.. it saves a lot of things.. first thing that came to my mind, was that.. if I do all the calculations in LUA instead of WML would it help?
for example if i understand things right then if I sort an array in WML then it will all be stored into saved file, but what if I do all calculations in lua and only save results in wml variables? Will it cause OOS or will it reduce the size of save file?
I know that clearing as many variables as possible would help.. but what else can help? and what helps most?
Thanks..
Re: enclave's Lua thread
Yes i have seens that before, once there was an addon "betwren darkness and light" it was coded very ineffectiveley and had the same problemenclave wrote:
A strange question.. Looks like my mod's save file size has reached the limit..
When somebody (including me) tried to reload a save of New Settlers in multiplayer, it didn't let us and was said that it has reached the 40mb wml size or something similar.
Well yes it can help, but its possible the problem is somwhere else, for example its quite possible that there just too many units on the map.enclave wrote: What would be the most efficient way to reduce the size?
I looked into the wml code of the save.. and wow.. it saves a lot of things.. first thing that came to my mind, was that.. if I do all the calculations in LUA instead of WML would it help?
But of coursew it is also possible that your wml code abuses macors to repeat code so that it becomes really big, in this case replacing your code with lua can help.
In wml you can and should also clenaup you temporary variables with {CLEAR_VARIABLES}enclave wrote: for example if i understand things right then if I sort an array in WML then it will all be stored into saved file, but what if I do all calculations in lua and only save results in wml variables?
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.enclave wrote: Will it cause OOS?
enclave wrote: I know that clearing as many variables as possible would help.. but what else can help? and what helps most?
Thanks..
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.