Dugi's lua questions
Moderator: Forum Moderators
Re: Question: wml versus lua in matters of variable operatio
@Dugi
I think that your reasons "to keep scenarios, item lists, skills' properties and so on in WML" comes from misunderstanding of "lua storage" concept.
EDIT: Though I agree with storing scenarios in WML. But everything else CABD faster in lua.
I think that your reasons "to keep scenarios, item lists, skills' properties and so on in WML" comes from misunderstanding of "lua storage" concept.
EDIT: Though I agree with storing scenarios in WML. But everything else CABD faster in lua.
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: Question: wml versus lua in matters of variable operatio
Not sure what you are asking, but it's possible to have sort-of arbitrary "automatically scoped" wml variables within custom events, namely by misusing the automatic $weapon and $second_weapon variables, which allow you to pass arbitrary wml tables/config objects/a block of wml. See the second part in this post http://forums.wesnoth.org/viewtopic.php ... 66#p510066 for an example.Xudo wrote:Is it possible to create variables in special namespace instead of $unit ?.
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: Question: wml versus lua in matters of variable operatio
Thanks for your replies, that's all I needed to know, but await a lot of replies soon because I will start working on it within a few days.
Re: Question: wml versus lua in matters of variable operatio
Question. I am trying to make a GUI, and I need a text (in label) to be separated into multiple lines. I have set characters_per_line to 30, but it is not getting separated. I have tried to limit the resolution of the window, but it just added a scrollbar. Any ideas?
The object whose text I want to separate into lines is named gui_class_description .
Another question: are variable indexes working in the same way as in WML? Because I have seen something like this:
And I have no idea how could it look in WML.
The object whose text I want to separate into lines is named gui_class_description .
Code: Select all
local dialog = { maximum_width=800, maximum_height=600 ,
T.tooltip { id = "tooltip_large" },
T.helptip { id = "tooltip_large" },
T.grid { T.row {
T.column { T.grid { T.row { T.column { T.label { id="title" , definition="title" , label="Select hero class"} } },
T.row{ T.column { horizontal_grow = "false" , grow_factor=1 , horizontal_alignment = "left" , vertical_alignment = "top" , border= "All" , border_size = 5, T.label { id = "gui_class_description", label="Necromancer is a specialist on raising undead minions and crippling enemies with various curses and poisons, with a skeletal figure affecting reistances. Necromancers are specialist spellcasters, and generally weak in melee combat." , characters_per_line = 30 } }} ,
T.row { T.column { horizontal_grow = true, T.listbox { id = "gui_character_chosen", horizontal_scrollbar_mode = "never" ,
T.list_definition { T.row { T.column { horizontal_grow = true,
T.toggle_panel { T.grid { T.row {
T.column { horizontal_alignment = "left", T.label { id = "the_label" } },
T.column { T.image { id = "the_icon" } }
} } }
} } }
} } },
T.row { T.column { T.grid { T.row {
T.column { T.button { id = "ok", label = "Choose" } },
T.column { T.button { id = "cancel", label = "Back" } }
} } } }
} }
} }
}
Code: Select all
local foo = { "v1" , "v2" , "v3" }
Re: Question: wml versus lua in matters of variable operatio
I haven't tried doing any GUI stuff. What Wesnoth version are you using? I was under the impression that 1.10 can't do this kind of GUI-related stuff.Dugi wrote:Question. I am trying to make a GUI, and I need a text (in label) to be separated into multiple lines. I have set characters_per_line to 30, but it is not getting separated. I have tried to limit the resolution of the window, but it just added a scrollbar. Any ideas?
That's not a valid WML table. It's equivalent to '{ [1]="v1" , [2]="v2" , [3]="v3" }'. WML can do an array of records, but not of simple strings. Assuming you want an array of strings, here are some ways to do it:Dugi wrote: Another question: are variable indexes working in the same way as in WML? Because I have seen something like this:And I have no idea how could it look in WML.Code: Select all
local foo = { "v1" , "v2" , "v3" }
Code: Select all
-- More traditional, but very verbose. This method is necessary if you need
-- multiple fields per item.
{
T.item{
value = 'v1'
},
T.item{
value = 'v2'
},
T.item{
value = 'v3'
}
}
-- I prefer this:
{
_1 = 'v1',
_2 = 'v2',
_3 = 'v3'
}
-- Some people use constructed variable names.
function getScalarFromList(listName, index)
return V[listName .. index]
end
function setScalarInList(listName, index, value)
V[listName .. index] = value
end
setScalarInList('myArray', 1, 'v1') -- Equivalent to V.myArray1 = 'v1'
setScalarInList('myArray', 2, 'v2')
setScalarInList('myArray', 3, 'v3')
Re: Dugi's lua questions
Thanks, Luther.
Quick question (for somebody who knows to do stuff with GUI):
Why this does tell me that a grid cell does not exactly have 1 child?
And I am on wesnoth 1.10, it seems to support GUI well.
This GUI was supposed to write several lists in two columns, with a title and two buttons bellow. The second column is not written yet because it didn't work without it.
And sorry for asking a lot, I feel like a total noob now.
Quick question (for somebody who knows to do stuff with GUI):
Why this does tell me that a grid cell does not exactly have 1 child?
Code: Select all
local dialog = { maximum_width=800, maximum_height=600 , T.tooltip { id = "tooltip_large" }, T.helptip { id = "tooltip_large" },
T.grid {
T.row { T.column { T.label { id="title" , definition="title" , label="Create your hero"} }} ,
T.row { T.column { T.grid {
T.row { T.column { horizontal_grow = "false" , grow_factor=1 , horizontal_alignment = "left" , vertical_alignment = "top" , border= "All" , border_size = 5, T.label { id = "gui_class_description", label="Necromancer is a specialist on raising undead minions and crippling enemies with various curses and poisons, with a skeletal figure affecting reistances. Necromancers are specialist spellcasters, and generally weak in melee combat." , characters_per_line = 30 } } }},
T.row { T.column { horizontal_grow = true, T.listbox { id = "gui_character_chosen", horizontal_scrollbar_mode = "never" ,
T.list_definition { T.row { T.column { horizontal_grow = true,
T.toggle_panel { T.grid { T.row {
T.column { horizontal_alignment = "left", T.label { id = "gui_class_name" } },
T.column { T.image { id = "gui_class_icon" } }
} } }
} } }
} } }
}}}
},
T.row { T.column { T.grid { T.row {
T.column { T.button { id = "ok", label = "Choose" } },
T.column { T.button { id = "cancel", label = "Back" } }
}}}}
This GUI was supposed to write several lists in two columns, with a title and two buttons bellow. The second column is not written yet because it didn't work without it.
And sorry for asking a lot, I feel like a total noob now.
Re: Dugi's lua questions
If you show example of interface drawn in any graphical editor, then it will be easier to figure out what do you need.
Re: Dugi's lua questions
It was reporting an error, and I have verified that there is no ambiguity in that, so screenshots aren't really needed. The line breaking problem should be also explanatory enough, I would have posted screenshots, but I cannot do it right now (I'm not on Linux). I will post them asap.
- Elvish_Hunter
- Posts: 1576
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: Dugi's lua questions
Right now, I can't test your window (I'll do it ASAP), but I can give you a suggestion: create macrowidgets. For example, the last T.grid with the two buttons becomes a variable called buttonbox:
so you can call it:
This will make your code easier to read, and also easier to isolate the offending chunks.
Code: Select all
local buttonbox = T.grid { T.row {
T.column { T.button { id = "ok", label = "Choose" } },
T.column { T.button { id = "cancel", label = "Back" } }
}}
Code: Select all
T.row { T.column { buttonbox } }
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: Dugi's lua questions
I tried it with a high organisation of spaces and brackets, and managed to make something that works to a certain extent.
The problem with 'a grid cell does not exactly have 1 child' appeared when I left an empty row or column, planning to add something after trying out the part I had already written.
I have made this window as I wanted it to be, but I still have the problem with line-breaking. I have no idea how to force the labels to break into multiple lines.
So, this is if I try to write all values to fit the sizes: This is how it looks if I write the class description properly (causing it to be way too long if there is no line breaking): This is the code of the whole interactive window:
The problem with 'a grid cell does not exactly have 1 child' appeared when I left an empty row or column, planning to add something after trying out the part I had already written.
I have made this window as I wanted it to be, but I still have the problem with line-breaking. I have no idea how to force the labels to break into multiple lines.
So, this is if I try to write all values to fit the sizes: This is how it looks if I write the class description properly (causing it to be way too long if there is no line breaking): This is the code of the whole interactive window:
Spoiler:
- Elvish_Hunter
- Posts: 1576
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: Dugi's lua questions
I too did something similar. What I did was splitting it in some macrowidgets, rework the indentation in a sort-of C++ style and fixing some brackets when an error was raised. Now it works.Dugi wrote:I tried it with a high organisation of spaces and brackets, and managed to make something that works to a certain extent.
Window code
Well, you can look to the scroll_label widget. Don't worry about scrollbars, because they won't show up unless they're necessary. In the above code I replaced the label with a scroll_label, for example.Dugi wrote:I have no idea how to force the labels to break into multiple lines.
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: Dugi's lua questions
Thanks a lot!Well, you can look to the scroll_label widget. Don't worry about scrollbars, because they won't show up unless they're necessary. In the above code I replaced the label with a scroll_label, for example.
I really wonder why I didn't find it earlier, I have skimmed through that page at least 10 times.
EDIT: Bummer. Two scroll_label-s cannot be used in a single window if their text is too long. This is how it looks when if only one text is longer than the space it is given: This is how it will look when two of them require the text compressing feature of scroll_label : EDIT #2:How do I change the tooltip property in GUI by callback events (workaround attempt)?
I tried (entering dialog, finding grid, finding the second row in it, the second column in it, then the grid inside it,...):
Code: Select all
dialog.grid.row[2].column[2].grid.row[3].column.listbox.tooltip = "blablabla"
Code: Select all
dialog.grid[2].row[2].column.grid[3].row.column.listbox.tooltip = "blablabla"
Re: Dugi's lua questions
Bump.
Sorry for bumping, but I need my questions, at least the one from EDIT#2 answered (as it should not be hard to answer), and probably nobody noticed I edited my last post.
I also need to ask one more question, would it be feasible if I wrote many essential data-holding variable arrays in WML as the contents of an otherwise unused dummy unit type, that would be stored by lua code, turned into lua variables and then used? It would be the contents of [abilities] or [event] tags in the unit's file.
This way I would avoid storing these variables inside save files, and allow other people to easily edit it.
Sorry for bumping, but I need my questions, at least the one from EDIT#2 answered (as it should not be hard to answer), and probably nobody noticed I edited my last post.
I also need to ask one more question, would it be feasible if I wrote many essential data-holding variable arrays in WML as the contents of an otherwise unused dummy unit type, that would be stored by lua code, turned into lua variables and then used? It would be the contents of [abilities] or [event] tags in the unit's file.
This way I would avoid storing these variables inside save files, and allow other people to easily edit it.
Re: Dugi's lua questions
It should be possible, yes.
Just to name a different approach: In my campaign, I have created data files for easier editing and maintaining of areas as well. I then load the file via a WML preprocessor include and handle its contents to a Lua function, which then parses the file. Depending on how your variables are going to look, this might be an even easier way.
Just to name a different approach: In my campaign, I have created data files for easier editing and maintaining of areas as well. I then load the file via a WML preprocessor include and handle its contents to a Lua function, which then parses the file. Depending on how your variables are going to look, this might be an even easier way.
In case you're interested, here's the important files
UMC Story Images — Story images for your campaign!
Re: Dugi's lua questions
Hm, I understand the way it reads the data, but I need to make it support WML stuff, like subtags and macro substitutions. But this would be also quite useful.
I still need a reply to the question how can I add something="somethingelse" into the third variable array foo in a variable. variable.foo[3].something="somethingelse" like in WML does not seem to work and I am failing to google it. Workaround with wesnoth.set_variable kinda kills the purpose.
I still need a reply to the question how can I add something="somethingelse" into the third variable array foo in a variable. variable.foo[3].something="somethingelse" like in WML does not seem to work and I am failing to google it. Workaround with wesnoth.set_variable kinda kills the purpose.