Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ General
➜ New options in utils.inputbox and utils.editbox
New options in utils.inputbox and utils.editbox
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Fri 01 Oct 2010 07:26 AM (UTC) Amended on Tue 03 May 2011 11:28 AM (UTC) by Nick Gammon
|
Message
| I have had some queries about the functions utils.inputbox and utils.editbox which used to display a fixed-size dialog box. This tended to look a bit flaky if you just wanted to ask the user to enter a small amount of data, when the dialog was actually quite large.
Now those two functions have a sixth argument, which is a table of "extra" information. These fields are named:
- box_width --> width of message box in pixels (min 180)
- box_height --> height of message box in pixels (min 125)
- prompt_width --> width of prompt text in pixels (min 10)
- prompt_height --> height of prompt text in pixels (min 12)
- reply_width --> width of reply in pixels (min 10)
- reply_height --> height of reply in pixels (min 10)
- max_length --> max characters they can type (min 1)
[EDIT] Also added (see post further down):
- validate --> validation function
- ok_button --> label for "OK" button
- cancel_button --> label for "Cancel" button
[EDIT] Also added in version 4.73:
- read_only --> text-entry area is read-only
- ok_button_width --> width of "OK" button
- cancel_button_width --> width of "Cancel" button
So for example:
result = utils.inputbox ( "Enter the room number", -- prompt
"Room", -- window title
"1234", -- default answer
"Courier", 10, -- font
{
box_width = 180,
box_height = 125,
prompt_width = 150,
prompt_height = 12,
reply_width = 80,
reply_height = 10,
max_length = 5,
}
)
Options which are omitted try to default to reasonable values.
The box width and height control the overall dialog box size.
The prompt width and height are the size of the field which prompts for the response. So if you have a short question you might make the prompt height small (like, 12).
The reply width and height are the size of the box into which you type the response.
The field "max_length" controls the maximum number of characters you can type into the field. So for example, if you are asking for a character name, and the maximum name is 12 characters, you could put 12 there.
This functionality is in version 4.64 onwards. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Fri 01 Oct 2010 10:41 AM (UTC) |
Message
| Example:
result = utils.inputbox ( "Your name?", "Character creation", "Nick", nil, nil,
{
box_width = 180,
box_height = 130,
prompt_height = 12,
reply_width = 80,
reply_height = 20,
max_length = 12,
}
)
 |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #2 on Fri 01 Oct 2010 10:41 PM (UTC) Amended on Fri 01 Oct 2010 10:42 PM (UTC) by Nick Gammon
|
Message
| Another few useful extra options are:
- validate --> validation function
- ok_button --> label for "OK" button
- cancel_button --> label for "Cancel" button
The two label options let you label the OK and Cancel buttons a bit more appropriately. For example, you might label the OK button "Find", and the cancel button "Close".
The "validate" function lets you do validation of the user-entered data before they are allowed to close the dialog box (this only applies if they hit the "OK" button, not the "Cancel" button).
The validate function is passed a single string which is what the user has typed. You can return nil or false to not accept the value. You can return a "true" value (basically everything except nil or false) to accept the entry.
The validation function can be used to check anything you wish. Examples might be:
- That the entry is not empty
- That it is a number
- If a number, that it is in a certain range
- If a thing (like a room, or spell) that this thing exists (eg. by table lookup)
- That the entry is not the duplicate of something that already exists
- That it conforms to some naming rules (eg. only alphabetic characters)
An example might be:
function age_check (s)
-- check a number
local n = tonumber (s)
if not n then
utils.msgbox (s .. " is not numeric")
return false
end -- if
-- check in range
if n < 1 or n > 100 then
utils.msgbox (s .. " is out of range 1 to 100")
return false
end -- if
-- passes checks
return true
end -- function age_check
result = utils.inputbox ( "Your age?",
"Character creation",
"20", -- default answer
"Courier", 10, -- font
{ validate = age_check,
max_length = 3, }
)
This will simplify somewhat those plugins that ask questions (the mapper springs to mind) because previously you had to let the utils.inputbox dialog close, then validate the answer, and then display an error, which looked a bit clunky. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| LezChap
(36 posts) Bio
|
Date
| Reply #3 on Sat 02 Oct 2010 08:09 PM (UTC) |
Message
| Awesome adds, thanks for the quick response to a feature request. | Top |
|
Posted by
| Fiendish
USA (2,534 posts) Bio
Global Moderator |
Date
| Reply #4 on Mon 02 May 2011 05:09 PM (UTC) |
Message
| It looks like the OK and Cancel boxes do not resize if you try to put longer strings in, so there is currently an effective limit on button text length. Is this expected? |
https://github.com/fiendish/aardwolfclientpackage | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #5 on Tue 03 May 2011 11:58 PM (UTC) |
Message
| Expected, yes. Useful, not really.
Altered in version 4.73 to allow you to specify your own widths. I did this rather than calculate the width based on the text, because you may prefer the buttons to be the same size, and that size being the width of the larger one.
https://github.com/nickgammon/mushclient/commit/d33099e4cf |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Fiendish
USA (2,534 posts) Bio
Global Moderator |
Date
| Reply #6 on Wed 04 May 2011 03:57 AM (UTC) Amended on Wed 04 May 2011 03:58 AM (UTC) by Fiendish
|
Message
|
Nick Gammon said:
Expected, yes. Useful, not really.
Altered in version 4.73 to allow you to specify your own widths. I did this rather than calculate the width based on the text, because you may prefer the buttons to be the same size, and that size being the width of the larger one.
https://github.com/nickgammon/mushclient/commit/d33099e4cf
I wouldn't have thought that the system font sizes would be predictable enough for manual widths to work. Is there a way for us to make the appropriate width calculation calculation based on...I guess(?)...getting the system font information? |
https://github.com/fiendish/aardwolfclientpackage | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #7 on Wed 04 May 2011 07:32 AM (UTC) |
Message
| Now you are pushing my knowledge limits. My experience is that button fonts tend to be fixed, but of course if you change themes, or something (like switch to "high readability mode") then the fonts probably get larger. But do the buttons too?
If you just want to change "OK" to "Equip my gear" or something, then some sort of trial-and-error probably would work for 99% of players.
A quick test shows that changing Display -> Appearance -> Font Size to "Extra Large Fonts" does not affect the font used in buttons (in MUSHclient at least) so you can probably just fudge it. Or work out what font the system uses, make a temporary miniwindow, and work out how many pixels you need. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Gorertz
(2 posts) Bio
|
Date
| Reply #8 on Mon 05 May 2014 07:18 PM (UTC) |
Message
| Hi.
I have a question about InputBox function in scripting.
I used to work on my mushclient scripts in VBscript, but lately i changed scripting language to Python and so the trouble began.
I used InputBox function in some of my scripts in vbscript but when i tried to use it in python it shows errors and it seems it does not work in this language.
Am i thinking rigt and if i'm wrong could i get an example how it supposed to look in python?
Gorertz | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
29,657 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top