Page 119 of 121 FirstFirst ... 19 69 109 117 118 119 120 121 LastLast
Results 1,181 to 1,190 of 1210

Thread: ZLib -- Zarqon's useful function library

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

    Default

    r32 Updates!

    This update brings us some pretty big changes for script settings. And most of them are the sort of changes where, after the fact, you look at them and think "Dang, why didn't I just make it work like this to begin with?" Or rather, I look at them and think that. You look at them and think whatever you're about to comment below.

    Inspired by Veracity's recent work around properties, I have slightly overhauled the way ZLib handles script settings:

    • First, setvar() now saves the default value and type information to vars_defaults.txt. Your vars_<myname>.txt file is not edited at this point.
    • Since the defaults are now saved separately, vars_<myname>.txt now only contains values that have been changed from the default.
    • Improved CLI output for searching/editing settings when running ZLib in the CLI.
    • Since type information is now saved for each setting, we can now normalize settings when changing them rather than the next time setvar() is called! You get immediate feedback on whether your edit worked as desired.


    Important Note

    There's also a new function:

    string getvar(string varname)

    Hitherto, we have simply used a direct vars[] lookup to reference script settings. However, with this new implementation, I'd eventually like vars[], just like vars_myname.txt, to contain only those settings which have been changed from the default. Hence, this new function, which really should have existed since the dawn of script settings.

    "Script settings had a dawn?" Yes.

    So, if you are a script author using ZLib's handy-dandy script settings, at some point not too far from now you'll want to

    search: vars[
    replace with: getvar(

    And handle the closing ] to ) as well. For all your scripts. I'll be doing this over time with my scripts as well.

    Since this is a not insignificant change I'll give everyone loads of time to transition. Let's say... six whole months! Or maybe a year! For now, ZLib adds the default values back in to vars[] so as not to break existing scripts. But in the meantime, let's all encourage each other to be better versions of ourselves and use getvar(), not vars[].

    I've also updated this information on ZLib's Wiki page (which you can get to by typing "ashwiki zlib" in the CLI). And in the big info-post I made when I first introduced script settings, in case anyone has linked to that post.

    The best and most exciting part of the script settings revamp is yet to come -- a new relay script for editing ZLib script settings and mafia properties. I have everything except the actual editing part complete and it's looking awesome:

    PrefrefPlus.PNG

    Changes to Kmail Functions

    Also this update brings us the fix suggested by AlbinoRhino above, implemented by digitrev in his New You script, and as it turns out, suggested by Bale in this very thread back in June of 2011. Somehow that suggestion passed right by me back then without ever catching my eye. My eye was no doubt looking at some far-off vision of the future and was not so easily distracted by the mundane reality of the present!

    So, the future is now! Since items, etc. can be received mid-kmail, the message field will now be the entire message.

    Also, I discovered a little bug in kmail() which I'm quite surprised no one spotted yet. When sending meat and more than 11 different items to a person who can receive non-gift items, the amount of meat specified would be sent in all the item group kmails, not just the first. I have driven the windshield of correct code through the flight path of this bug, and it exists no more.

    Enjoy the future, everyone!
    Sig by JakAtk
    My scripts: 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. #1182
    Senior Member zarqon's Avatar
    Join Date
    Nov 2007
    Location
    Seoul, Korea
    Posts
    3,392

    Lightbulb

    In case it's helpful, I updated all my scripts (and everyone else's) to use getvar() by doing this simple batch search/replace in Notepad++:

    notepad replace.PNG

    I have posted it here for you to copypasta. Since regexes are of course extremely dangerous beasts, I have enclosed the search in a protective code tag. Please remove it from your clipboards immediately after use.

    Code:
    Find: \bvars\[\"(.+?)\"\]
    Replace with: getvar\(\"\1\"\)

  3. #1183
    Senior Member
    Join Date
    Apr 2009
    Posts
    1,670

    Default

    Of course, that will only catch accesses by literal names, not by variables (vars["barf"] vs. string vname="barf"; vars[vname]).
    It will also not catch accesses using single quotes (ash accespts that too).
    It will also mangle monstrous codes that use something like vars["prefix" + '["i am a troll"]' + ".postfix"]

    So, you know, regexes. Use at your peril. Verify.

  4. #1184

    Default

    Mangling that monstrous code sounds like a bonus

    And nice work zlib, I was already wondering why mafia reported updating all my variables when I ran a few of my scripts.

  5. #1185
    Senior Member zarqon's Avatar
    Join Date
    Nov 2007
    Location
    Seoul, Korea
    Posts
    3,392

    Default

    @xKiv: Thank you for clarifying that, I hadn't meant to imply that the regex was a one-size-fits-all easy fix! I first clicked the "Find All" button to review all the instances it would change and make sure they were correct. I had to revert a few of them afterwards. Also another search for just the opening vars[ would be recommended to catch those other cases. Fortunately ZLib vars are nearly always referenced by literal name, so those cases should be few to nonexistent.
    Sig by JakAtk
    My scripts: 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!

  6. #1186
    Senior Member
    Join Date
    Apr 2009
    Posts
    1,670

    Default

    BTW, I can't believe I didn't go for "use at your PER(i)L".

  7. #1187
    Senior Member Theraze's Avatar
    Join Date
    Mar 2010
    Posts
    8,668

    Default

    Question. EatDrink had some values that changed from boolean to ints. I manually used vars[] to rewrite them when people have invalid values, but... is there some better way to do it rather than setting vars[] with updatevars() to seal it, since setvar() will only set it if's completely blank...?

    Second EatDrink question - it allows users to set any item they'd like to avoid (or gorge) and each gets its own eatdrink_avoid_item or eatdrink_fav_item var. We then use var_check to search through vars to see if it's set and, if set, verify that it's true. The delisting of defaults will make EatDrink start consuming astrals and other quest items without warning. Does EatDrink need to have its own version of getvar to not complain about over 18650 missing avoid and fav records?
    Last edited by Theraze; 05-17-2017 at 02:44 AM.

  8. #1188
    Senior Member zarqon's Avatar
    Join Date
    Nov 2007
    Location
    Seoul, Korea
    Posts
    3,392

    Default

    You can continue to write to vars[] as before, though checking for a variable in vars is not a guarantee that it does or does not exist. You would also have to check vardefaults[].

    However, though I wasn't clear what you meant by "delisting of defaults" I think you're fine in this case, as values that are not present in defaults can still exist and will not be removed (quite necessary given we're transitioning from not having defaults). Usually that would mean you haven't run the script the setting belongs to yet, but it could also be used for arbitrary values. It would only be removed from vars if you set it to a value that is the same as the default.

  9. #1189

    Default

    The new update of ZLib seems to have broken Harvest.ash rather completely. I'm seeing some frankly bizarre behavior that I don't understand, where I'm getting conflicting values for variables via the CLI and in-script:
    Code:
    > zlib har_farming_location
    
    Copy/paste/modify/enter any of the following lines in the CLI to edit settings:
    
    zlib har_farming_location = Barf Mountain
    Requests complete.
    That's as it should be. But when I try to access that same variable in a pared-down test script, test.ash:
    Code:
    import <zlib.ash>;
    
    print("har_farming_location is " + getvar("har_farming_location"));
    Code:
    > call scripts\test.ash
    
    har_farming_location is The Castle in the Clouds in the Sky (Top Floor)
    I'm pretty sure "The Castle in the Clouds in the Sky (Top Floor)" is the default value of the variable as set by the Harvest.ash script, but I haven't run anything in between my direct zlib invocation and my test.ash call. What am I missing here? Why are values available via direct zlib invocation but not by the new getvar() call?

  10. #1190
    Senior Member
    Join Date
    Jan 2012
    Location
    Texas
    Posts
    346

    Default

    Do you vprops by Veracity installed?

Similar Threads

  1. Replies: 1
    Last Post: 11-25-2013, 06: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
  •