Getting user input

StDoodle

Minion
Forgive me if I'm missing something, but after searching through the master list of ash functions on the wiki, and trying "ashref [rackin'ma'brain]," I'm still unable to come up with more elegant solutions to getting user input of a numerical (or non-boolean, for that matter) input. Mostly, I'm looking for ways to get integer input. So far, the only solutions I've come up with that can be used outside of "main" are:

1) Define & include an external script & main function, where the main function requires & int, but don't supply it. Haven't tested to see if & how this would work, but perhaps...

2) int val; while (user_confirm("Your total is currently " + to_string(val) + "; do you wish to add 1?")) { val = val + 1; }

Both seem kind of clunky, but I just KNOW I'm missing something elementary...

Edit: okay, can't get option 1 to work... hmm...
 
Last edited:

heeheehee

Developer
Staff member
The first solution is probably the best option out there right now. As far as I can tell, you're not really missing anything; it's just how ASH works. I think.
 

Bale

Minion
Both seem kind of clunky, but I just KNOW I'm missing something elementary...
Nope, you're not. If you search about you'll find a bit of discussion involving other people's pros and cons about why mafia is this way.

Edit: okay, can't get option 1 to work... hmm...
Save this script as input-int.ash

Code:
void main(int Enter_an_integer) {
   set_property("input", to_string(Enter_an_integer));
}

Then in the main program you have a function like this:

Code:
int get_int() {
   cli_execute("call input-int.ash");
   return get_property("input").to_int();
}
The key is that you need to use cli_execute to call the input script, then use it's input by saving it as a property. Attempting to include the script will fail to gain you anything. Yes, this is a huge kludge.
 

StDoodle

Minion
Nope, you're not. If you search about you'll find a bit of discussion involving other people's pros and cons about why mafia is this way.

Ah, thanks again Bale. I was able to find discussion pertaining specifically to main(), but not to general user-input. My guess is that this is part of the holdover from the early mafia philosophy of being targeted at scripters & programmers. With that philosophy, it makes more sense to tell the user to edit a configuration file or the script itself; but over the last year or so I've seen a large number of relatively non-computer-savvy folks starting to use mafia (partially my fault for advocating its logging assistance ;)), and it would be awesome to have an easier way to set up preferences for these folks. But I don't want to hog the feature-request board. ;)

[...script...]

Yeah, I think I'll stick with what I'm doing currently in my script; the main() function already takes an unlimited number of parameters via a split_string() on the main argument, so it's possible to set specific settings with a more specialized list of parameters; otherwise, default values will be used.

Glad to know I wasn't missing anything, though! Thanks again.
 

Bale

Minion
Actually, the main reason that scripts cannot accept input concerns issues holatuwol has with javascript programs having focus problems on pop-up windows that could potentially freeze mafia. Though some of what you suggest is not entirely absent.
 
1) Define & include an external script & main function, where the main function requires & int, but don't supply it. Haven't tested to see if & how this would work, but perhaps...

If you want to see another example of this in action you could look at the script I posted here. It's not the prettiest solution, but it works.
 

zarqon

Well-known member
Can you give an example of feedback that needs to happen in the middle of a script rather than at the beginning? I think we could probably work out a solution to whatever it is that doesn't need to interrupt execution.
 

StDoodle

Minion
Can you give an example of feedback that needs to happen in the middle of a script rather than at the beginning? I think we could probably work out a solution to whatever it is that doesn't need to interrupt execution.

http://www.kolmafia.us/showthread.php?t=3443

Basically, I want the same script to handle preferences & listing & "checking off" items. If I tried to allow that in this script, it would cause two big problems:

1) No good way to suppress asking for input on things not relevant to the player (I for one am not a big fan of a reminder of shiny toys that I don't have).

2) That's a hell of a lot of arguments for main()

Now, the user won't usually be prompted for any information; but when you go to setup your preferences, it's nice to be able to pass along some data. Currently, I'm working on handling this by using a different method of preference assignment when specific parameters are called; ie you'd be able to type the parameters "SETUP BADGER 3" if you wanted to set the astral mushroom reporting threshold to three, rather than 0 or 5. But arbitrary numbers, without the need of an additional script, would be neato. I suppose I could try to handle parsing more than one preference at a time, but that introduces additional room for user-error.
 
Last edited:

slyz

Developer
How about using a zlib variable (a string you could parse) that the user can configure using zlib cdaily = BADGER 3, GARNISH 1 etc ?

Or you can look at DerDongo's equipt.ash to see how he handled this. I'm not a programmer, so I'm learning a *lot* of things by reading it.
 
Last edited:

zarqon

Well-known member
I would set that up as a script with a single string parameter in main(). This parameter would be checked for keywords such as "pool" or "friars", and whichever actions were included in the parameter would be performed; for other actions, information would be printed. There could also be support for keywords like "all" or "info" which would perform all available actions, or only display all available info. Anything else that needed user tweaking would be either a script variable or a zlib setting.
 

StDoodle

Minion
I would set that up as a script with a single string parameter in main().

So would I; in fact I already did!

I was hoping, though, to be able to make it a little easier on the "casual" user, by allowing them to type in numbers or answer questions to setup their settings. I had already planned on (and am about done programming) the ability to specifically set individual settings with something along the lines of:
Code:
customdaily.ash PIXIE 0 BANDER 2

All in all, not a big loss; most settings have valid values of 0, 1 or 2, which is fairly painless to do with a combination of "user_confirm()" 's. [btw, what exactly IS the correct grammar for what I just did?] Only a small handful of settings have a reasonable need for additional values; the users will just have to suck it up and either edit them into their preferences file, or set them via the CLI with text parameters.
 

zarqon

Well-known member
As far as ease of use, I've really liked Raorn's idea for the old bounty script -- include a "usage" function which displays whenever the user enters a) nothing or b) faulty input. In this case, it would list current settings and the commands needed to change them. Kind of like ZLib settings, but more user-friendly (typing "zlib vars" in the CLI gives you a list from which you can copy/paste directly to edit vars, but doesn't actually document how to change those vars).

If you feel you must use user_confirm()'s (I think that's correct grammar), I guess it's not too ugly so long as they are sheltered in some kind of "config" function which only runs when specified by the user. But it seems like you've got this all figured out already.

Cool script, by the way! Now that I've checked it out I see a few more things I need to add to my logout script.
 

gausie

D̰͕̝͚̤̥̙̐̇̑͗̒e͍͔͎͈͔ͥ̉̔̅́̈l̠̪̜͓̲ͧ̍̈́͛v̻̾ͤe͗̃ͥ̐̊ͬp̔͒ͪ
Staff member
Addressed in r20797 with the following caveat

There are three functions currently:
* `string user_prompt(string message)`
* `string user_prompt(string message, int timeoutInMillis, string defaultValue)`
* `string user_prompt(string message, aggregate options)`
Note two things:
1. There is not currently a timeout-able option select function. It's harder to do so I've left it for now
2. Whatever type of aggregate you pass as options you will get a string in return. This could be changed in the future
 
Top