Page 195 of 195 FirstFirst ... 95 145 185 193 194 195
Results 1,941 to 1,950 of 1950

Thread: Character Info Toolbox

  1. #1941
    Senior Member AlbinoRhino's Avatar
    Join Date
    May 2008
    Posts
    618

    Default

    I kind of suspect there are many CHiT users who don't monitor this thread and WOULD need a migration script. I probably should have voted THREE.

  2. #1942
    Minion Bale's Avatar
    Join Date
    Jun 2008
    Posts
    13,149

    Default

    I believe that ChIT users who don't pay attention to this forum at all probably don't know they can customize ChIT. So they'll never realize anything happened.

  3. #1943
    Developer Veracity's Avatar
    Join Date
    Mar 2006
    Location
    The Unseelie Court
    Posts
    10,805

    Default

    I'd like mention that I'm going to be using a rather stripped down and customized version of the vProp code. Thanx to Veracity for the inspiration, but since I have control over how it is used I don't need to account for every variation. Also, I need to use multiple delimiters in a single property whereas vProp is only able to handle one at a time.
    Originally Posted by Bale View Post
    vprop uses split_string() to divide sets/lists on "delimiter". That means "delimiter" is actually a regex. If you use "|", ",", ";", etc., it looks like a simple string, but you can be more complicated. (And since "|" is a regexp character, if you use exactly "|" as your "delimiter", we convert it into "\\|" for use by split_string()).

    In case anyone is curious -- mostly for Veracity's curiosity -- I present my intended code. Note that normalize_prop() has a functional improvement over vProp's equivalent to allow me to mix comma and bar in a single property.
    See above. But your technique is fine.

    define_property() is merely a stripped down version since it doesn't have to survive in someone else's environment. (I feel safe in believing that I won't attempt to override a default mafia property.)
    Yeah, that's fair. You can still use vprops's to_list_of_string(), etc, functions on built-in properties without needing to pass them through define_property or normalize first.

    Despite my changes I owe much gratitude to Veracity for envisioning the concept and designing the original, astonishingly robust, code for me to work with.
    Glad you like it! I thought for a long time about how I wanted it to behave and implemented a handful of new property functions for ASH's runtime library in order to make it possible, and it ended up being quite simple, actually.

    Code:
    string normalize(string value, string type) {
    	if(value == "string")
    		return value;
    	string func = "to_" + type;
    	return call string func(value);
    }
    Yeah, OK. Personally, I don't like "call", although this is a perfectly good use of it, since it obviates having a switch to figure out which function to call. Here are some thoughts.

    - call looks up an ASH function with particular arguments and return type at run time. If it can't find one, it throws an exception and aborts your script. Which is to say, you find your bug at run time.
    - calling a function by name in your script does that at compile time.
    - my switch statement internally turns into an if/then/else chain of string comparisons.
    - looking up functions at runtime does string comparison of the name on every user-defined or built-in function in the scope and then chooses the one whose params match.

    Which is to say:

    - Using "call" makes a small function which doesn't need to know all datatypes, but which requires a very expensive lookup to find the function and will abort your script at runtime if it fails.
    - Using "switch" and direct function calls makes a larger function which has to know all the possible target functions at compile time, but is way more efficient at runtime and will detect errors at compile time, not runtime.

    Your approach using "call" is not "wrong" - but it doesn't have the runtime characteristics that I, personally, prefer.

    Code:
    string normalize_prop(string value, string type) {
    	matcher list = create_matcher("(^|[,|])([^,|]*)", value);
    	buffer newlist;
    	while(list.find())
    		list.append_replacement(newlist, list.group(1) + normalize(list.group(2), type));
    	return newlist;
    }
    Interesting approach. My requirements were a little different, in that vprops allows "set" types, and when it normalizes a "set" value, it creates a temporary set, which will result in duplicates being discarded, before reconstructing the string. Using either your approach or my approach, coercing a property via to_set_of_xxx() will result in the same value, but my approach will "fix" the string value, if there are duplicates in it.

    Code:
    string define_property(string name, string type, string def) {
    	// All "built-in" properties exist. A "custom" property that doesn't exist uses the (normalized) default.
    	string normalized_def = normalize_prop(def, type);
    	if(!property_exists(name))
    		return normalized_def;
    
    	// The property exists and (potentially) overrides the default
    	string raw_value = get_property(name);
    	string value = normalize_prop(raw_value, type);
    	if(value == normalized_def)
    		remove_property(name);
    	else if(raw_value != value)
    		set_property(name, value);
    
    	return value;
    }
    Perfectly nice simplification given only user properties.
    Ph'nglui mglw'nafh Cthulhu
    R'lyeh wgah-nagl fhtagn.

  4. #1944
    Minion Bale's Avatar
    Join Date
    Jun 2008
    Posts
    13,149

    Default

    vprop uses split_string() to divide sets/lists on "delimiter". That means "delimiter" is actually a regex. If you use "|", ",", ";", etc., it looks like a simple string, but you can be more complicated. (And since "|" is a regexp character, if you use exactly "|" as your "delimiter", we convert it into "\\|" for use by split_string()).
    Originally Posted by Veracity View Post
    That wasn't my problem. I thought of using the regexp there, but the problem is that (unless I don't understand things correctly) if I did that it won't put the correct delimiter back between the elements after normalizing them. Did I fail to understand that properly?

    Interesting point about discarding duplicates. I hadn't thought of that at all!
    If people like my scripts, please send me stuffed Hodgmen.
    Universal Recovery, OCD Inventory Control, CounterChecker, newLife, ChIT.


  5. #1945
    Developer Veracity's Avatar
    Join Date
    Mar 2006
    Location
    The Unseelie Court
    Posts
    10,805

    Default

    That's a good point. I guess it only does work on delimiters which are known characters.
    Perhaps I will adopt your technique.
    Ph'nglui mglw'nafh Cthulhu
    R'lyeh wgah-nagl fhtagn.

  6. #1946
    Developer Veracity's Avatar
    Join Date
    Mar 2006
    Location
    The Unseelie Court
    Posts
    10,805

    Default

    Or, maybe not. Hard to understand how a list of items that included, for example, "Tea, Earl Grey, Hot" with comma as a delimiter could work.
    Ph'nglui mglw'nafh Cthulhu
    R'lyeh wgah-nagl fhtagn.

  7. #1947
    Minion Bale's Avatar
    Join Date
    Jun 2008
    Posts
    13,149

    Default

    For my part, you've convinced me that call is the wrong approach.

    Meanwhile I've hit a wall on normalizing items. How can we handle normalizing Ouija Board, Ouija Board? Paring out duplicate items in the set would at least keep the property from increasing in size every time the charpane refreshes. (Every time it runs, the number of Ouji Boards doubles.) I'm not sure that's a perfect solution though.

    Edit: Your post about "Tea, Earl Grey, Hot" just ninja'ed me. Similar issue. I suppose that using a semi-colon or | might be an improvement, but I feel like I'm coping out and waiting for those characters to show up in an item name.

  8. #1948
    Minion Bale's Avatar
    Join Date
    Jun 2008
    Posts
    13,149

    Default

    I've completed converting ChIT to vProp style variables. I'm going to give another day or two to soak in before I release it so I have a chance to properly shake it out.

    I also wrote a migration script for people who want to keep their old zlib vars. It was really easy. So much easier than converting ChIT. Just four lines long and one of them imports zlib. I'll attach the script file to a post in this thread once I make the update to ChIT.

    PHP Code:
    // This script converts zlib vars for ChIT. It creates new mafia properties with the same names as the old vars.
    // Two vars have been removed from the configuration.
    import "zlib.ash";

    foreach 
    prop,val in vars
        
    if(prop.contains_text("chit.") && prop!= "chit.gear.display.aftercore.defaults" && prop!= "chit.gear.display.in-run.defaults")
            
    set_property(propval); 

  9. #1949
    Senior Member Theraze's Avatar
    Join Date
    Mar 2010
    Posts
    8,631

    Default

    Or as a one line that can be copy-pasted into the gCLI tab:
    Code:
    ashq import "zlib.ash"; foreach prop,val in vars if(prop.contains_text("chit.") && prop!= "chit.gear.display.aftercore.defaults" && prop!= "chit.gear.display.in-run.defaults") set_property(prop, val);

  10. #1950
    Minion Bale's Avatar
    Join Date
    Jun 2008
    Posts
    13,149

    Default

    That's a pretty good idea. I'm sure that for pretty much everyone it will be easier to copy/paste a single line than it will be to download a file to /scripts and run it there.

Similar Threads

  1. Bug - Fixed Bad Spoiler Info
    By Bale in forum Bug Reports
    Replies: 1
    Last Post: 05-30-2014, 08:39 AM
  2. Daily Info
    By icon315 in forum Relay Override Scripts
    Replies: 66
    Last Post: 06-19-2013, 01:42 PM
  3. Feature More monster info
    By ckb in forum Bug Reports
    Replies: 19
    Last Post: 05-06-2013, 10:07 PM
  4. Replies: 0
    Last Post: 02-08-2011, 02:30 PM
  5. MMG toolbox
    By Veracity in forum Scripting Discussion
    Replies: 12
    Last Post: 08-10-2009, 03:43 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
  •