Proposed helper.get_text_input
Moderator: Forum Moderators
-
- Developer
- Posts: 546
- Joined: January 12th, 2011, 2:18 am
- Location: Pennsylvania, USA
Proposed helper.get_text_input
I propose that the following would be added after helper.get_user_choice, in the helper.lua file:
Any thoughts on the form, syntax, or implementation of the above?
If approved, I can submit a patch & edit the wiki as appropriate.
Code: Select all
--! Displays a WML text input message box with attributes from table @attr
--! with optional table @options containing optional label, max_length, and text key/value pairs.
--! @returns the entered text.
function helper.get_text_input(attr, options)
options = options or {}
local msg = {}
for k,v in pairs(attr) do
msg[k] = attr[k]
end
local ti = {}
for k,v in pairs(options) do
ti[k] = options[k]
end
ti["variable"]="LUA_text_input"
table.insert(msg, { "text_input", ti })
wesnoth.fire("message", msg)
local result = wesnoth.get_variable("LUA_text_input")
wesnoth.set_variable("LUA_text_input")
return result
end
If approved, I can submit a patch & edit the wiki as appropriate.
Co-Author of Winds of Fate
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.
- Elvish_Hunter
- Posts: 1575
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: Proposed helper.get_text_input
You can try replacing wesnoth.fire with wesnoth.wml_actions.message; you may also need to use wesnoth.synchronize_choice to avoid an out-of-sync in multiplayer.SigurdTheDragon wrote:Any thoughts on the form, syntax, or implementation of the above?
Other than that, I don't know if this may be useful in core or not, so I'd like to hear the other developers' opinion. In the worst case, I'll add it to the Wesnoth Lua Pack.
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)
-
- Developer
- Posts: 546
- Joined: January 12th, 2011, 2:18 am
- Location: Pennsylvania, USA
Re: Proposed helper.get_text_input
Thanks, hadn't realized that wesnoth.wml_actions is the best way as opposed to wesnoth.fire which is the older way.Elvish_Hunter wrote:You can try replacing wesnoth.fire with wesnoth.wml_actions.message
As I based this off of helper.get_user_choice, maybe that means that it should be updated (along with some others in helper that use wesnoth.fire) but the wiki mentions some operational differences between wesnoth.fire and wesnoth.wml_action.
I originally wrote it cause I saw a conceptional need (ie, there's a way to do [message] with [options], why not cover [text_input] as well?)Elvish_Hunter wrote:Other than that, I don't know if this may be useful in core or not,
Is that sufficent reason here?
As for wesnoth.synchronize_choice(function()), maybe I'm reading it wrong but wouldn't it be used like this with helper.get_user_choice?
Code: Select all
local result = wesnoth.synchronize_choice(helper.get_user_choice({speaker="narrator", message=msg }, { "option 1", "option 2" }))
Co-Author of Winds of Fate
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.
- Elvish_Hunter
- Posts: 1575
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: Proposed helper.get_text_input
The problem is that helper.get_user_choice seems to be almost unused, except in Settlers of Wesnoth. To make things worse, I found this post by silene, that seems to indicate that helper.get_user_choice may cause OOS errors.SigurdFireDragon wrote:I originally wrote it cause I saw a conceptional need (ie, there's a way to do [message] with [options], why not cover [text_input] as well?)
Is that sufficent reason here?
At this point, I cannot commit it, sorry. But not everything is lost: it can enter in the Wesnoth Lua Pack without problems.
So, there are two options:
- I or Anonymissimus commit it in the WLP
- you commit it in the WLP by yourself. This will require you to use SVN, and to ask Espreon for commit access on Wesnoth-UMC-Dev (if you already did both things, even better)
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)
-
- Developer
- Posts: 546
- Joined: January 12th, 2011, 2:18 am
- Location: Pennsylvania, USA
Re: Proposed helper.get_text_input
I'll take option #2, it's time I got an account there.
Co-Author of Winds of Fate
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.
Re: Proposed helper.get_text_input
The OOS that silene was talking about in that post is caused by improper usage - the contents of synchronized block are only calculated on one PC, so if you advance the RNG inside, it would only advance on one client, leading to OOS.
-
- Developer
- Posts: 546
- Joined: January 12th, 2011, 2:18 am
- Location: Pennsylvania, USA
Re: Proposed helper.get_text_input
Committed @ UMC-Dev Repository r11702Elvish_Hunter wrote:...you commit it in the WLP by yourself...
I was grateful that it was there, it saved me the trouble of figuring out how to write it, and I made heavy use of a slight variation of it when I converted my one add-on to be almost all lua.Elvish_Hunter wrote:The problem is that helper.get_user_choice seems to be almost unused, except in Settlers of Wesnoth.
Co-Author of Winds of Fate
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.