Page 2 of 126 FirstFirst 1 2 3 4 12 52 102 ... LastLast
Results 11 to 20 of 1254

Thread: ZLib -- Zarqon's useful function library

  1. #11
    Senior Member zarqon's Avatar
    Join Date
    Nov 2007
    Location
    Seoul, Korea
    Posts
    3,505

    Default

    Basically, every script and their mom can include ZLib without causing trouble. (Yes, the scripts' moms.) Mafia seems to intelligently recognize whether or not a file has already been included, and will not include it twice. So, no worries -- feel free to go include-happy!

    Alhifar -- nice! I like how it also appears to handle choiceadvs that lead to combats.
    Sig by JakAtk
    My scripts: Prefref Plus | One-Click Wossname | Om******t (??) | Psychose-a-Matic | RandBot
    Combat suite: Best Between Battle | Mer********d (?!) | SmartStasis | BatMan | BatMan RE
    For script authors: ASH Wiki | ZLib | BatBrain | CLI Links | CanAdv | Script Registry | Map Manager | About Bats
    If you appreciate my work, help me become BAT KING OF THE WORLD! Thanks to all donators!

  2. #12
    Senior Member
    Join Date
    Jul 2008
    Posts
    526

    Default

    It does. I added that in as a result of the bug that had occurred when it was run on a choice adventure leading to a combat; it would cause mafia to be extremely confused.

  3. #13
    Senior Member
    Join Date
    Sep 2008
    Posts
    795

    Default

    (Crossposting from the wossname script since it belongs here)

    It would be nice to have a function that encapsulates the behavior you use with threshold (if it's not set as a property, prompt the user and assume a default). I would use this in my scripts - for example, eatdrink.ash. Every time someone gets a new version, they blow away the script settings they've changed, which I'm sure gets old. I imagine it would work like this:
    default_prop(foo,bar); //the default property for "foo" is "bar"
    get_prop(foo); //if foo is set manually in the user's preference file, return the setting; otherwise, return the default set via default_prop

  4. #14
    Senior Member
    Join Date
    Sep 2008
    Posts
    795

    Default

    Another request: A global setting to disable version prompting. If I'm running unattended for a while, I don't want version check popups.

  5. #15
    Minion Bale's Avatar
    Join Date
    Jun 2008
    Posts
    13,287

    Default

    Ditto that! I sometimes find the pop ups annoying. Would like to stop it. How about just printing out a red message about the version being out of date, then doing it anyway without prompting.
    If people like my scripts, please send me stuffed Hodgmen.
    Universal Recovery, OCD Inventory Control, CounterChecker, newLife, ChIT.


  6. #16
    Senior Member
    Join Date
    Sep 2008
    Posts
    795

    Default

    I propose a new function:

    Code:
    // Returns the property if set, or a default if not
    string get_preference(string pref, string pref_default) {
      string result = get_property(pref);
      if (result=="")
      {
        print("You have not set property '"+pref+"', so the default value of '"+pref_default+"' will be used.");
        return pref_default;
      }
      return result;
    }
    If scripts use this (e.g. for things like warplan and other preferences) then your preference customizations won't be wiped out when you upgrade, but there wills till be sensible defaults for a first time script user. So your threshold initialization, for example, becomes:
    Code:
    // set safetyThreshold, which is used by many of my scripts
    int threshold = to_int(get_preference("safetyThreshold", "4"));
    I would LOVE it if you did this, since I always have to recheck my settings every time I upload a script to make sure my defaults won't screw up anyone else...!

  7. #17
    Senior Member zarqon's Avatar
    Join Date
    Nov 2007
    Location
    Seoul, Korea
    Posts
    3,505

    Default

    @dj_d: Hmmmm.... you've got me thinking. I'll have to think about it more before implementing anything though. I think there must be a super awesome way to do this. Possibly something involving a global map of character preferences, rather than using mafia settings... or perhaps storing preferences on a remote server!

    Ditto that! I sometimes find the pop ups annoying. Would like to stop it.
    Originally Posted by Bale View Post
    They're meant to be annoying. How to stop it: download a current version. I had earlier complaints from users not knowing whether or not they had the latest and greatest. And I've had to deal with quite a few users reporting problems they encounter using outdated versions. This particular user annoyance exists for my benefit. On the plus side: at least now it's only once daily!

    If you, being an advanced user, would like to bypass the alerts, change the user_feedback() command in the version_check() function to a print statement yourself.
    Sig by JakAtk
    My scripts: Prefref Plus | One-Click Wossname | Om******t (??) | Psychose-a-Matic | RandBot
    Combat suite: Best Between Battle | Mer********d (?!) | SmartStasis | BatMan | BatMan RE
    For script authors: ASH Wiki | ZLib | BatBrain | CLI Links | CanAdv | Script Registry | Map Manager | About Bats
    If you appreciate my work, help me become BAT KING OF THE WORLD! Thanks to all donators!

  8. #18
    Senior Member
    Join Date
    Sep 2008
    Posts
    795

    Default

    If only you could find a way to shorten it... it's 10 lines, for crying out loud! Way too big.

  9. #19
    Senior Member matt.chugg's Avatar
    Join Date
    Nov 2006
    Posts
    617

    Default

    not as exciting as everyone elses, but heres 2 functions I use in more than one script, not sure quite how useful they are to people.

    Code:
    class parseclass(string c) {
    	class cls=to_class(c);
    
    	if(cls==$class[none]) {
    		switch(c) {
    			case "tt":
    			case "turtle":return $class[Turtle Tamer];
    			case "sc":
    			case "seal":return $class[Seal Clubber];
    			case "pm":
    			case "pasta":return $class[Pastamancer];
    			case "sauce":return $class[Sauceror];
    			case "db":
    			case "disco":return $class[Disco Bandit];
    			case "at":
    			case "accordion":
    			case "accord":return $class[Accordion Thief];
    			default:return $class[none];
    		}
    	}
    	return cls;
    }
    and probably somewhat pointlessly:

    Code:
    string pluralise(item i, int amount) {
    	if(amount==1) {
    		return to_string(i);
    	} 
    	return to_plural(i);
    }
    I demand inclusion! or bat part presents will stop! mwuahahahah!

    actually not really, just my penny worth.

  10. #20
    Senior Member zarqon's Avatar
    Join Date
    Nov 2007
    Location
    Seoul, Korea
    Posts
    3,505

    Default

    About ZLib "Script Settings"

    (edited 5/14/2017 to account for new handling of defaults)

    There are now two functions which allow for per-character script settings:

    void setvar(string varname, mixed dfault)
    string getvar(string varname)


    setvar() initializes a script variable by setting its default value and type in vars_defaults.txt. This only happens once, or again if your default gets deleted somehow. And once it's initialized, users can change its value by running ZLib in the CLI. Any values they change are saved per-character in vars_<myname>.txt. Your script can access the value of this setting (the user's changed value or otherwise the default) by calling getvar(). Several interesting possibilities now present themselves to users and script authors.

    For Users
    • Script settings are now all saved in one place, separate from mafia settings. I've read more than one post wishing that script-defined settings and mafia settings would be separate. This provides a solution.
    • Script settings are independent from scripts. This means that you will no longer need to edit scripts to adjust your setttings. Further, when you download a script update, the script will use your saved settings and you won't need to reset them!
    • To see all of your current settings, type "zlib vars" in the CLI. To change a setting, type "zlib settingname = value". If you're adjusting threshold, you can use "up" or "down" as the value to adjust your threshold relatively. This is almost exactly as convenient as mafia settings (possibly more so since you don't need to open a text file to find setting names!).
    • If for some reason you prefer to open a text file, ZLib settings are stored in a file called vars_defaults.txt in your data directory. Those which you have changed from the default value are saved in vars_<myname>.txt.
    • Scripts that use Zlib script settings will initialize the settings -- saving their default value and type in vars_defaults.txt -- when you run them for the first time. Attempting to edit a nonexisting setting won't work, so you'll need to run a script once (then, usually, mash the ESC key before it actually does anything) before you can configure it. Script documentation should tell you which settings to change to get your desired behavior.


    For Script Authors
    • Use setvar() to initialize a setting that your script will reference. To reference the setting, use getvar() and convert from string to whichever type the setting is supposed to be. Accessing vars[] or vardefaults[] directly (the previous method) is not recommended, as a value may exist in one but not the other, or both.
    • Script settings may now be used across scripts, in exactly the same way that mafia settings are. Basically, this works almost exactly like mafia settings, except that new settings can only be created by setvar() or manually editing the file ("zlib nonexistentsetting = value" will fail).
    • Settings are only stored if you run a script that defines/uses them. So your settings file will not contain any extraneous unused settings.
    • Script authors can now test for a setting's existence in vardefaults[], which means you can check to see if a user has used a given script. It's almost as good as a script_exists() function. This can allow scripts to work together with other scripts, if they exist!
    • Scripts with overlapping or related functionality can be designed to access a single shared setting, in much the same way that my scripts have until now all shared a "threshold" mafia setting. Changing a single setting can now change the behavior of every script that accesses that setting.


    The Gory Details

    When importing ZLib, it loads the setting defaults from vars_defaults.txt and a map of your script settings that have been changed from vars_<myname>.txt. To access a script setting within an ASH script, use getvar(varname).

    When a script calls setvar("threshold",4), ZLib checks to see if a setting called "threshold" already exists. If so, since dfault is an integer, it ensures that the value is an integer using normalize() (saving changes if necessary), but unless normalization changed the value, nothing else happens. If "threshold" does not exist, it initializes its default value to 4, its type to int, and saves those defaults back to vars_defaults.txt. The setting may now be accessed by getvar() or edited using ZLib in the CLI.

    The dfault parameter can be any primitive or ASH type ($item, $effect, etc), but not a map, array, or record.

    Choosing Setting Names

    The file of script settings will contain all script settings, sorted alphabetically. Also, there is no way to detect if a setting is unused, so if you decide to change the name, the old setting will never be deleted. Please think carefully about your setting names. If you have a setting named "setting1", a user will probably not have a clue which script that is for or what it does. True, this can be overcome with documentation, but it is far better to have settings that make sense just by looking at them.

    My recommendations:

    1. Use a name that clearly identifies what the setting is/does.

    2. Prefix your setting names with a script identifier. For example, here are some of my One-Click Wossname script settings:

    Code:
    setvar("ocw_warplan","optimal");
    setvar("is_100_run",false);
    setvar("ocw_change_to_meat",true);
    setvar("ocw_nunspeed",false);
    setvar("defaultoutfit","current");
    setvar("ocw_f_default","zombie");
    setvar("ocw_m_default","");
    Those settings which are specific to OCW are prefixed with "ocw_" so as to be found together in the settings file. However, some of the settings are usable across scripts, and are not so prefixed. For example, I intend to use the "is_100_run" variable in every script that swaps familiars, so as to avoid tainting a 100% run. Likewise, the "defaultoutfit" will be used by nearly all of my adventuring scripts that swap outfits (MacGuffin, OCW).

    That's it. Enjoy this new functionality!
    Last edited by zarqon; 05-14-2017 at 10:37 AM. Reason: script settings now save defaults!
    Sig by JakAtk
    My scripts: Prefref Plus | One-Click Wossname | Om******t (??) | Psychose-a-Matic | RandBot
    Combat suite: Best Between Battle | Mer********d (?!) | SmartStasis | BatMan | BatMan RE
    For script authors: ASH Wiki | ZLib | BatBrain | CLI Links | CanAdv | Script Registry | Map Manager | About Bats
    If you appreciate my work, help me become BAT KING OF THE WORLD! Thanks to all donators!

Similar Threads

  1. Replies: 1
    Last Post: 11-25-2013, 07:48 PM
  2. StDoodle's Libray - Another function library
    By StDoodle in forum Scripting Discussion
    Replies: 6
    Last Post: 10-29-2013, 10:04 PM
  3. ROFL -- Ridiculously Overelaborate Function Library
    By Catch-22 in forum Informational Scripts
    Replies: 6
    Last Post: 06-07-2012, 07:28 AM
  4. is there a way to see what a function within zlib returns?
    By maximillian the red in forum Community Support
    Replies: 6
    Last Post: 10-03-2011, 07:33 PM
  5. Adventure Function Library
    By muffins in forum Scripting Discussion
    Replies: 9
    Last Post: 05-06-2006, 12:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •