Elvish_Hunter's Lua thread
Moderator: Forum Moderators
- Elvish_Hunter
- Posts: 1575
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: Elvish_Hunter's Lua thread
After some time of experiments (and after working a lot on Python + Tkinter + ttk ), I managed to create a working dialog with Lua. It contains some widgets (a slider, a text box, a toggle button and a button), to which I have to set some starting values, and from which I have to retrieve the resulting values. You can see the result below.I'm currently on 1.9.7+svn (49936M). Am I doing something wrong, or did I hitten three bugs in a row?
The problem that I have is that it seems like I can't set a starting value for slider and text_box (I know that I can use value= for slider and label= for text_box, but I need to have the code set them in the preshow function depending, for example, on a unit's movement points or name), and that I can't retrieve the value from slider in the postshow function (I gain an "unsupported widget" error). Finally, when I accidentally placed a non-existent widget (I used T.textbox instead of T.text_box), I gained a crash and an assertion failed error in the terminal:Code: Select all
[textbox]
history = other_recruits
label = None
[/textbox]
src/gui/auxiliary/window_builder.cpp:119 ASSSERTION FAILED: 0
Trace/breakpoint trap
Code for dialog is here:
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)
-
- Posts: 462
- Joined: June 8th, 2006, 3:25 am
Re: Elvish_Hunter's Lua thread
I hunted down the definitions of set_dialog_value and get_dialog_value. For get_dialog_value, the following widgets are currently supported: listbox, multipage, toggle button, text box. For set_dialog_value, it specifically supports listbox, multipage, and toggle button, then has a default case which tries to handle the widget as a tcontrol (which apparently succeeds for a label but not a textbox or slider).
Looks like silene just didn't get around to adding support for any other widgets to those functions before leaving.
Looks like silene just didn't get around to adding support for any other widgets to those functions before leaving.
- Elvish_Hunter
- Posts: 1575
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: Elvish_Hunter's Lua thread
Thank you . I reported this as bug #18271 on Gna! https://gna.org/bugs/index.php?18271
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)
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: Elvish_Hunter's Lua thread
Exasperation: You are ready to make a patch that adds the feature then ? I guess it's enough to add the according else if() {... } blocks in the same way as for the already supported widgets. Other than that I recognize the same, currently explicitely supported:
set_dialog_value:
listbox
multi_page
toggle_button
get_dialog_value:
listbox
multi_page
toggle_button
text_box
All other widgets may or may not work. So both aren't bugs, just lack of features.
set_dialog_value:
listbox
multi_page
toggle_button
get_dialog_value:
listbox
multi_page
toggle_button
text_box
All other widgets may or may not work. So both aren't bugs, just lack of features.
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
-
- Posts: 462
- Joined: June 8th, 2006, 3:25 am
Re: Elvish_Hunter's Lua thread
We'll see. At the time I type this, I'm compiling an attempt at adding support for slider getting/setting. Assuming this works, I'll look at what other widgets might be feasible for me to do. It does look like a pretty simple task, there's a fairly obvious pattern to follow from the ones silene already did.
I think the other part of Elvish_Hunter's report is a bug, though. If you try to create a widget of a type that doesn't exist, it should handle the task more gracefully (I've seen devs say that if WML causes a crash, it's a bug; this doesn't exactly fall into that category, but it's close enough that I think the same logic applies).
I think the other part of Elvish_Hunter's report is a bug, though. If you try to create a widget of a type that doesn't exist, it should handle the task more gracefully (I've seen devs say that if WML causes a crash, it's a bug; this doesn't exactly fall into that category, but it's close enough that I think the same logic applies).
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: Elvish_Hunter's Lua thread
I found out why some widgets work and others don't - the ones derived from the class tcontrol do, the others don't since the cast fails then. You should ask mordante what would be the most suitable type(s) to cast to so that a maximum of widgets are supported.
The assertion failure is plainly annoying of course (I've come used to the scenario staying open no matter what I do, and there's just a lua error...).
Silene wrote about how to solve these here:
http://forums.wesnoth.org/viewtopic.php ... 34#p453534
The assertion failure is plainly annoying of course (I've come used to the scenario staying open no matter what I do, and there's just a lua error...).
Silene wrote about how to solve these here:
http://forums.wesnoth.org/viewtopic.php ... 34#p453534
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
-
- Posts: 462
- Joined: June 8th, 2006, 3:25 am
Re: Elvish_Hunter's Lua thread
Well, tslider and ttext_box are both indirectly derived from tcontrol; that's why trying to set the value of a slider fails silently instead of giving an error (like trying to get the value of a slider does). But they need to be handled differently than a "typical" tcontrol. For the tcontrol default case, you use the input as a string and call the set_label() member function. For a slider, you need to use the input as a number, check to make sure it's in bounds, then call the set_value() member function. For a text_box, it looks like you need to treat the input as a string but use set_value() (which, unlike the slider, comes from being derived from ttext_) instead of set_label(). I'm not sure what other widgets have distinct values that you might need to get/set. Maybe tprogress_bar (set_percentage()/get_percentage)?
In fact, it looks like all the individual widgets are derived from tcontrol, directly or indirectly. The issue just seems to be whether "value" is synonymous with "label" for that particular widget.
In fact, it looks like all the individual widgets are derived from tcontrol, directly or indirectly. The issue just seems to be whether "value" is synonymous with "label" for that particular widget.
- Elvish_Hunter
- Posts: 1575
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: Elvish_Hunter's Lua thread
Thank you, now slider and text_box work fine. I needed them for a project, and below there are the details.
As a UMC author/maintainer, several times I used the debug console. And several times I did some typos, that enforced me to retype the command from scratch. I also noticed that the most used attributes that I modify in a unit while debugging are MP, XP, HP and attacks left; also, statuses cannot be modified from the debug console - they aren't a "first level variable".
So, I made this tag, called [show_quick_debug]. It is meant to be used inside a [set_menu_item], and this is why it "stores" the unit at x1,y1. When used with a code like thisif there is no unit in the hex shows a warning, but if there is a unit... It seems to work well, except for two problems:
- when modifying a unit's facing from Lua, it seems to not show immediatly, even after [redraw]
- setting a unit's side using Lua (es. side=3) causes a Segmentation Fault if that side is invalid because the scenario does not have enough sides (only two sides, for example). I worked around it, and such workaround will remain even if the crash will be fixed.
The parameters that can be modified are all those that don't require accessing the .__cfg field, and then using put_unit.
I'm also planning to add support for translatable strings, but the most important thing was making it up and running.
Any comments, suggestion, etc.? By the way, if nobody is against it, I'll put it in the WLP.
As a UMC author/maintainer, several times I used the debug console. And several times I did some typos, that enforced me to retype the command from scratch. I also noticed that the most used attributes that I modify in a unit while debugging are MP, XP, HP and attacks left; also, statuses cannot be modified from the debug console - they aren't a "first level variable".
So, I made this tag, called [show_quick_debug]. It is meant to be used inside a [set_menu_item], and this is why it "stores" the unit at x1,y1. When used with a code like this
Code: Select all
[set_menu_item]
id=quick_debug
description=Quick Debug
[command]
[show_quick_debug]
[/show_quick_debug]
[/command]
[/set_menu_item]
- when modifying a unit's facing from Lua, it seems to not show immediatly, even after [redraw]
- setting a unit's side using Lua (es. side=3) causes a Segmentation Fault if that side is invalid because the scenario does not have enough sides (only two sides, for example). I worked around it, and such workaround will remain even if the crash will be fixed.
The parameters that can be modified are all those that don't require accessing the .__cfg field, and then using put_unit.
I'm also planning to add support for translatable strings, but the most important thing was making it up and running.
Any comments, suggestion, etc.? By the way, if nobody is against it, I'll put it in the WLP.
And here there are more than 250 lines of code:
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: Elvish_Hunter's Lua thread
If there is enough space, I would change the first two lines. By now, you have a layout like this:
This looks a bit cluttered up and you'll search long for the desired information.
My suggestion would be to keep the labels in the top column and use the bottom column for the values:
IMO, it's clearer this way.
Crend
Code: Select all
X 14 Y 10 ID Elvish Archer-17 Valid map
Type Elvish Archer Name Urandeladir Can recruit no Petrified no
My suggestion would be to keep the labels in the top column and use the bottom column for the values:
Code: Select all
X Y Type Name ID Can recruit Valid Petrified
14 10 Elvish Archer Urandeladir Elvish Archer-17 no map no
Crend
UMC Story Images — Story images for your campaign!
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: Elvish_Hunter's Lua thread
Great. I'm eager to try it.
For hitpoints and experience I suggest default values: hitpoints to 1 (checkboxes: 0 ? kill+fire_event ? ) and exp to max_exp (checkbox: advance).
EDIT
However - in the end it may make more sense if you could add such functionality to the C++ debug functionalities. Setting more than just toplevel attributes is a feature request since long, and the inspect dialog was apparently planned to have setting functionalities too.
fixedElvish_Hunter wrote:- setting a unit's side using Lua (es. side=3) causes a Segmentation Fault if that side is invalid because the scenario does not have enough sides (only two sides, for example).
Fits perfectly into debug_utils.lua. Other than that I dont know whether it's better to have it as a function or as a tag.Elvish_Hunter wrote:By the way, if nobody is against it, I'll put it in the WLP.
For hitpoints and experience I suggest default values: hitpoints to 1 (checkboxes: 0 ? kill+fire_event ? ) and exp to max_exp (checkbox: advance).
EDIT
However - in the end it may make more sense if you could add such functionality to the C++ debug functionalities. Setting more than just toplevel attributes is a feature request since long, and the inspect dialog was apparently planned to have setting functionalities too.
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
- Elvish_Hunter
- Posts: 1575
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: Elvish_Hunter's Lua thread
It is possible, but of course I'd like to hear some more opinions on that matter before modifying it (mainly because creating and modifying such a WML table, without having keys like row=, column=, rowspan= and columnspan= for every widget was quite hard).Crendgrim wrote:If there is enough space, I would change the first two lines.
Thanks!Anonymissimus wrote:Great. I'm eager to try it.
I was thinking about another solution: given that probably in future we'll see more graphical tags/functions, I thought of creating a gui-tags.lua file, linked to the wml-tags.lua by using wesnoth.require. What about it?Anonymissimus wrote:Fits perfectly into debug_utils.lua.
We must consider that this dialog may be used also by UMC authors that don't know Lua, so I think that the tag form will be simpler for them - it could be put in a macro called in every scenario, for example.Anonymissimus wrote:Other than that I dont know whether it's better to have it as a function or as a tag.
Default values are taken from the unit stats; in this peculiar case, the unit had no XP, hence the slider is set to 0. If it had 32 XP, the slider will be set at 32, for example. If you're referring to the slider limits, that probably may be done by creating the dialog table after having get_unit acquiring the unit, and before having show_dialog showing it. Not sure if it'll work.Anonymissimus wrote:For hitpoints and experience I suggest default values: hitpoints to 1 (checkboxes: 0 ? kill+fire_event ? ) and exp to max_exp (checkbox: advance).
EDIT: modification done, it works. I decided to place one more checkbutton, instead of the three suggested by you, called Fire events. If selected, the unit is killed when its HP are set to 0, and advances when its XP are set to maximum.
New code:
This is a matter for our C++ coders; and anyway, the inspect window has a lot of parameters, and having one smaller dialog with only the most used parameters is useful as well.Anonymissimus wrote:However - in the end it may make more sense if you could add such functionality to the C++ debug functionalities. Setting more than just toplevel attributes is a feature request since long, and the inspect dialog was apparently planned to have setting functionalities too.
Since you talked about C++, can you suggest me any good tutorial, apart from the one at cplusplus.com ?
EDIT 2: I added support for translatable strings and [show_quick_debug] is on umc-dev.
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)
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: Elvish_Hunter's Lua thread
What else could one want than the unit being killed when setting hitpoints to 0 ?Elvish_Hunter wrote: If selected, the unit is killed when its HP are set to 0, and advances when its XP are set to maximum.
What else could one want than the unit being advanced when setting experience to max_experience ?
So maybe you should just make these the only conditions. Both are very frequent.
Also, the animations should be played when killing/advancing (testing unit animations).
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
-
- Posts: 462
- Joined: June 8th, 2006, 3:25 am
Re: Elvish_Hunter's Lua thread
Elvish_Hunter: If you do decide to follow this advice, note that you can set special labels on a slider to be displayed instead of the max and/or min. So you could add something likeAnonymissimus wrote:What else could one want than the unit being killed when setting hitpoints to 0 ?
What else could one want than the unit being advanced when setting experience to max_experience ?
So maybe you should just make these the only conditions. Both are very frequent.
Also, the animations should be played when killing/advancing (testing unit animations).
Code: Select all
minimum_value_label = "Kill Unit",
maximum_value_label = "Full Health"
Code: Select all
maximum_value_label = "Level Up"
Overall, this is looking great!
Re: Elvish_Hunter's Lua thread
Thanks for the work on the widgets, Exasperation! Also, EH - looks great! Would it be all right with you if I port this into ModularLua?
I frequently want to set the hitpoints to 0 to ensure a kill when one unit attacks another.Anonymissimus wrote: What else could one want than the unit being killed when setting hitpoints to 0 ?
- Elvish_Hunter
- Posts: 1575
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: Elvish_Hunter's Lua thread
Anonymissimus wrote:Great. I'm eager to try it.
Exasperation wrote:Overall, this is looking great!
Three great in a row. It must be a record. Thanks!melinath wrote:Also, EH - looks great!
Done...Anonymissimus wrote:What else could one want than the unit being killed when setting hitpoints to 0 ?What else could one want than the unit being advanced when setting experience to max_experience ?So maybe you should just make these the only conditions. Both are very frequent.
... done (although it required me to add a small wesnoth.delay to fire animations correctly)...Anonymissimus wrote:Also, the animations should be played when killing/advancing (testing unit animations).
... and done. Strangely, now I obtain this warning in the terminal:Exasperation wrote:note that you can set special labels on a slider to be displayed instead of the max and/or min.
Code: Select all
warning gui/draw: Text: text is too wide for the canvas and will be clipped.
I also added translation marks, translations directory, and textdomain. Unfortunately, wmlxgettext doesn't seem able to handle Lua files. In case that you want to know, this was my command line and its output:
Code: Select all
linux@linux-desktop:~/wesnoth/data/tools$ '/home/linux/wesnoth/data/tools/wmlxgettext' '/home/linux/.local/share/wesnoth/1.9/data/add-ons/Wesnoth_Lua_Pack'
msgid ""
msgstr ""
"Project-Id-Version: wesnoth 1.9.7+svn\n"
"Report-Msgid-Bugs-To: http://bugs.wesnoth.org/\n"
"POT-Creation-Date: 2011-06-29, 21:22+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL\@ADDRESS>\n"
"Language-Team: LANGUAGE <LL\@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
Spoiler:
It's open source, right? You can do whatever you want. Perhaps wait some time (say, one week?) to see if any issue emerges?melinath wrote:Would it be all right with you if I port this into ModularLua?
Well, restoring the Fire events checkbutton isn't too hard, if needed. It is safe on umc-dev.melinath wrote:I frequently want to set the hitpoints to 0 to ensure a kill when one unit attacks another.
Also, Anonymissimus, Exasperation and melinath: do you like the current upper labels layout, do you prefer Crendgrim's proposal, or do you have another suggestion?
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)