vultraz's lua questions
Moderator: Forum Moderators
Re: vultraz's lua questions
A few more comments.
This:Can be simplified to this:
And since you don't use Can be simplified to this:
Finally, while you can use
This:
Code: Select all
if result == true then
Code: Select all
if result then
result
anywhere else, this:Code: Select all
local result = wesnoth.eval_conditional { { "have_unit", { canrecruit = "true", side = boss_side } } }
if result then
Code: Select all
if wesnoth.eval_conditional { { "have_unit", { canrecruit = "true", side = boss_side } } } then
string.format()
, you don't have to.Re: vultraz's lua questions
ok... umm... well because of complications, I was forced to move to the addon to SP ans scrap the plans I had for this nice unit death system. So the lua I was written isn't needed now (I saved it though)
Right now I'm working on my inventory, yet another thing I realized I have to do before I tackle the shop, and:
gives:
Help please.
Right now I'm working on my inventory, yet another thing I realized I have to do before I tackle the shop, and:
Code: Select all
function wesnoth.wlm_actions.inventory_item(cfg)
local u_id = wesnoth.get_variable("unit.id")
local u_index = wesnoth.get_variable("inventory." .. unit_id .. ".length") + 1
local var_path = "inventory." .. u_id .. u_index ..
wesnoth.set_variable(var_path .. ".name", cfg.name)
wesnoth.set_variable(var_path .. ".id", cfg.id)
wesnoth.set_variable(var_path .. ".image", cfg.image)
wesnoth.set_variable(var_path .. ".status", cfg.status)
wesnoth.set_variable(var_path .. ".command", helper.get_child(cfg, "command"))
end
Help please.
Creator of Shadows of Deception (for 1.12) and co-creator of the Era of Chaos (for 1.12/1.13).
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
Re: vultraz's lua questions
Read your very first line carefully, especially the order of letters like 'l' and 'm'.
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: vultraz's lua questions
OH GAWD...How did I not see that?!
Creator of Shadows of Deception (for 1.12) and co-creator of the Era of Chaos (for 1.12/1.13).
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
Re: vultraz's lua questions
Besides the spelling error, the fourth line should probably be:Or:
Code: Select all
-- note brackets around index and lack of stray concatenation operator
local var_path = "inventory." .. u_id .. "[" .. u_index .. "]"
Code: Select all
-- this might be more easily readable
local var_path = ("inventory.%s[%i]"):format(u_id, u_index)
Re: vultraz's lua questions
Code: Select all
local item_action = helper.get_child(cfg, "command")
local remove_action = helper.get_child(cfg, "remove_command")
wesnoth.set_variable(var_path .. ".command", item_action.__cfg)
wesnoth.set_variable(var_path .. ".remcommand", remove_action.__cfg)
An example of usage:
Code: Select all
[inventory_item]
id=scen1_key
name= _ "Key"
image=misc/x.png
description= _ "An old, but well taken care of, key. It appears to be down here for safekeeping."
action= _ "This key can be used to open a locked gate."
section=items
status=shared
[command]
{VARIABLE special_key.present no}
[/command]
[remove_command]
{VARIABLE special_key.present yes}
[/remove_command]
[/inventory_item]
Creator of Shadows of Deception (for 1.12) and co-creator of the Era of Chaos (for 1.12/1.13).
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: vultraz's lua questions
Where does it say that the parameter passed to a wml tag implementation has a __cfg field ? What you probably want is item_action.__literal etc.
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
Re: vultraz's lua questions
Ok working on a custom window for the inventory now.
I'd like to have 1 option (contents of T.toggle_panel I guess) for each index (each of which contains 1 item's stat vars) in an array. Shadowmaster said to:
Code: Select all
local item_list = T.listbox { id = "inventory_list",
definition = "default",
T.list_definition { T.row { T.column { vertical_grow = "true",
horizontal_grow = "true",
T.toggle_panel { T.grid { T.row { T.column { grow_factor = 0,
horizontal_alignment = "left",
border = "all",
border_size = 5,
T.toggle_button { id = "checkbox",
definition = "default",
linked_group = "checkbox" } },
T.column { grow_factor = 1,
horizontal_grow = "true",
border = "all",
border_size = 5,
T.image { id = "image",
definition = "default" } },
T.column { grow_factor = 1,
horizontal_grow = "true",
border = "all",
border_size = 5,
T.label { id = "name",
definition = "default",
linked_group = "name" } } } } } } } } }
But I have no idea how. Can someone give me some pointers? Thanks<vultraz> shadowmaster: Ok got it. Just one more thing, I'd like to have the options print out from an array, where each index is a separate item. how can i do that?
<shadowmaster> iterate over the array and push items into the listbox in the loop block?
<vultraz> shadowmaster: ????? I get the first part (FOREACH?). but the second..
<shadowmaster> vultraz: push items into the listbox in the loop block?
<vultraz> yeah
<shadowmaster> that means that in the loop body you'll issue a call to whatever function is used to insert rows at the end of the listbox
<shadowmaster> don't ask me about how to do that in Lua for I have only programmed with GUI2 in C++
Creator of Shadows of Deception (for 1.12) and co-creator of the Era of Chaos (for 1.12/1.13).
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
- Elvish_Hunter
- Posts: 1576
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: vultraz's lua questions
First of all, I never experimented with toggle_panel so far, hence I cannot provide you a chunk of code right now
That said, a listbox requires both a list_definition and a list_data, which is missing in your code.
EDIT: I'm using a listbox in the Wesnoth Lua Pack, you may want to take this as example:
That said, a listbox requires both a list_definition and a list_data, which is missing in your code.
My guess is to use helper.get_variable_array to read the array's content. Then the problem will be to set as many lines in the listbox as the array's indexes. This one may be made by making a temp_list_data = {} table, and using table.insert() for each array index. Then, in the dialog definition, you'll use T.list_data temp_list_data.vultraz wrote:I'd like to have 1 option (contents of T.toggle_panel I guess) for each index (each of which contains 1 item's stat vars) in an array. Shadowmaster said to:
EDIT: I'm using a listbox in the Wesnoth Lua Pack, you may want to take this as example:
Code: Select all
local facing_radiobutton = T.horizontal_listbox { id = "facing_listbox",
T.list_definition { T.row { T.column { T.toggle_button { id = "facing_radiobutton" } } } },
T.list_data {
T.row { horizontal_alignment = "left",
border = "all",
border_size = 5,
T.column { label = _"nw" } },
T.row { horizontal_alignment = "left",
border = "all",
border_size = 5,
T.column { label = _"ne" } },
T.row { horizontal_alignment = "left",
border = "all",
border_size = 5,
T.column { label = _"n" } },
T.row { horizontal_alignment = "left",
border = "all",
border_size = 5,
T.column { label = _"sw" } },
T.row { horizontal_alignment = "left",
border = "all",
border_size = 5,
T.column { label = _"se" } },
T.row { horizontal_alignment = "left",
border = "all",
border_size = 5,
T.column { label = _"s" } }
} }
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)
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
Re: vultraz's lua questions
Ok, so should I put the array stuff in the preshow function?
One other thing, the wiki says the helper.get_variable_array Fetches all the WML container variables with given name and returns a table containing them (starting at index 1). Doesn't that mean it won't get any items stored in the 0 index?
One other thing, the wiki says the helper.get_variable_array Fetches all the WML container variables with given name and returns a table containing them (starting at index 1). Doesn't that mean it won't get any items stored in the 0 index?
Creator of Shadows of Deception (for 1.12) and co-creator of the Era of Chaos (for 1.12/1.13).
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: vultraz's lua questions
get/set_variable_array perform the index shift for you, no worry.vultraz wrote:One other thing, the wiki says the helper.get_variable_array Fetches all the WML container variables with given name and returns a table containing them (starting at index 1). Doesn't that mean it won't get any items stored in the 0 index?
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
Re: vultraz's lua questions
Something like this?
Also, what should I set the ids of the T.image and T.label to so that they will actually appear? Currently they're set to 'image' and 'name', respectively. As there are variables in that in temp_list_data (see above), should they automatically fill in? And what do the linked_group= keys do?
Code: Select all
local function item_preshow()
temp_list_data = { name = { }, image = { } }
function inventory_category_scan(section)
u_id = wesnoth.get_variable("unit.id")
i = 0
repeat
table.insert(temp_list_data.name, i , wesnoth.get_variable( u_id .. section .. "[" .. i .. "].name"))
table.insert(temp_list_data.image, i , wesnoth.get_variable( u_id .. section .. "[" .. i .. "].image"))
i = i + 1
until i == wesnoth.get_variable( u_id .. section .. ".length")
end
inventory_category_scan(".items")
inventory_category_scan(".weapons")
inventory_category_scan(".potions")
wesnoth.set_dialog_value ( "DESCRIPTION PLACEHOLDER", "description" )
wesnoth.set_dialog_value ( "Switch items", "switch_button" )
wesnoth.set_dialog_value ( "Leave in chest", "leave_chest_button" )
wesnoth.set_dialog_value ( "Exit", "ok_button" )
end
Creator of Shadows of Deception (for 1.12) and co-creator of the Era of Chaos (for 1.12/1.13).
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
-
- Posts: 462
- Joined: June 8th, 2006, 3:25 am
Re: vultraz's lua questions
You need to either use wesnoth.set_dialog_value to insert the values into the widgets like so:
or set up the dialog definition dynamically by building a list of list_data entries based on the inventory like so:
The list_data section is not mandatory (it defaults to empty), but if you don't use a list_data section you will need to use set_dialog_value to insert your data from the preshow function (or potentially from a callback that's set in the preshow function, but that doesn't seem to be necessary in this case).
Just a further note on toggle panels; I haven't experimented with them either, they may be one of the widgets that is not yet fully supported by the Lua dialog interface (the only one I am currently sure isn't fully supported is the multipage widget). If they are, full support for them will probably have to wait for 1.11 because of the 1.9 feature freeze.
Code: Select all
local function item_preshow()
local u_id = wesnoth.get_variable("unit.id") -- just to check, is unit a WML variable which contains the name of another WML variable?
local function inventory_category_scan(section) -- changed function name to match usage
for i = 1, wesnoth.get_variable(string.format("%s.%s.length", u_id, section)) do -- using .. works too, but I personally prefer string.format for all but the simplest uses
-- additionally, should this be "%s.variables.%s.length"? (assuming u_id holds the name of a WML variable that contains a stored unit here)
-- also, a for loop seems simpler here, since it only needs to perform the get_variable once
wesnoth.set_dialog_value(wesnoth.get_variable(string.format("%s.%s[%d].name", u_id, section, i - 1)), "inventory_list", i, "name")
wesnoth.set_dialog_value(wesnoth.get_variable(string.format("%s.%s[%d].image", u_id, section, i - 1)), "inventory_list", i, "image")
end
end
inventory_category_scan("items")
inventory_category_scan("weapons")
inventory_category_scan("potions")
wesnoth.set_dialog_value("DESCRIPTION PLACEHOLDER", "description")
wesnoth.set_dialog_value("Switch items", "switch_button")
wesnoth.set_dialog_value("Leave in chest", "leave_chest_button")
wesnoth.set_dialog_value("Exit", "ok_button")
end
Code: Select all
local list_data = {}
local u_id = wesnoth.get_variable("unit.id")
local function inventory_category_scan(section)
for i = 0, wesnoth.get_variable(string.format("%s.%s.length", u_id, section)) - 1 do
table.insert(list_data, T.row { T.column {<build appropriate toggle panel data here based on i>} })
end
end
inventory_category_scan("items")
inventory_category_scan("weapons")
inventory_category_scan("potions")
local item_list = T.listbox {
id = "inventory_list",
definition = "default",
T.list_definition { T.row { T.column {
vertical_grow = "true",
horizontal_grow = "true",
T.toggle_panel { T.grid { T.row {
T.column {
grow_factor = 0,
horizontal_alignment = "left",
border = "all",
border_size = 5,
T.toggle_button {
id = "checkbox",
definition = "default",
linked_group = "checkbox" } },
T.column {
grow_factor = 1,
horizontal_grow = "true",
border = "all",
border_size = 5,
T.image {
id = "image",
definition = "default" } },
T.column {
grow_factor = 1,
horizontal_grow = "true",
border = "all",
border_size = 5,
T.label {
id = "name",
definition = "default",
linked_group = "name" } } } } } } } },
T.list_data list_data }
Just a further note on toggle panels; I haven't experimented with them either, they may be one of the widgets that is not yet fully supported by the Lua dialog interface (the only one I am currently sure isn't fully supported is the multipage widget). If they are, full support for them will probably have to wait for 1.11 because of the 1.9 feature freeze.
Re: vultraz's lua questions
Ok I'm trying out the first one as the second confuses me, and I get this after clicking the menu after picking up an item:
As for the array structure, each main character has an array in his id that contains variables used by things like the inventory and shop. So an item here might be in, for example:
That's why I used unit.id to fill in the first part of the array based on who was using it at the time. There's also an separate array called shared_items that follows the same structure. I'm going to have to expand the function to include it, as the scared stuff is supposed to print in the same manner as the personal stuff, but in a different T.column.
Error:
Code: Select all
Rhyan.items[0].<stat code, eg name, section, description, image, etc>
Creator of Shadows of Deception (for 1.12) and co-creator of the Era of Chaos (for 1.12/1.13).
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
-
- Posts: 462
- Joined: June 8th, 2006, 3:25 am
Re: vultraz's lua questions
Ok, so unit.id does give you the name of a WML variable, and it's not storing the actual unit, so no .variable needed. Just wanted to make sure.
The error you're getting says that I got the identifying path to the widget wrong, which isn't too surprising since I'm going by the table you posted a few posts earlier, which doesn't seem to be the entire table you're using (your preshow references widgets with ids "description", "switch_button", "ok_button", and "chest_button", none of which exists in the table that you posted; also that table doesn't include the outer grid, tooltip, and helptip parts). That just means you have to correct the path I gave to match the full WML description of the dialog that you're actually using. At a guess, is "inventory_list" not a unique widget identifier?
Looking in the wiki, the big example from http://wiki.wesnoth.org/LuaWML:Display# ... alog_value actually uses this same technique for populating a listbox, I could have just pointed there.
The error you're getting says that I got the identifying path to the widget wrong, which isn't too surprising since I'm going by the table you posted a few posts earlier, which doesn't seem to be the entire table you're using (your preshow references widgets with ids "description", "switch_button", "ok_button", and "chest_button", none of which exists in the table that you posted; also that table doesn't include the outer grid, tooltip, and helptip parts). That just means you have to correct the path I gave to match the full WML description of the dialog that you're actually using. At a guess, is "inventory_list" not a unique widget identifier?
Looking in the wiki, the big example from http://wiki.wesnoth.org/LuaWML:Display# ... alog_value actually uses this same technique for populating a listbox, I could have just pointed there.