Character Info Toolbox

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.
 
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.
 
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.
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.
 
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()).

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!
 
That's a good point. I guess it only does work on delimiters which are known characters.
Perhaps I will adopt your technique.
 
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.
 
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.
 
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:
// 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(prop, val);
 
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);
 
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.
 
I did it. zlib vars are no longer being used in this script. To copy some of your zlib vars to vProps type zlib chit. in the CLI and choose the ones you need. Then just copy/paste the relevant line, changing the world "zlib" to "set" to create the vProp.

If you want to copy over ALL your vars, then simply copy/paste the following line into the CLI
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);

Note that after the first run of chit, it will compare your properties to the default values for those options and if they are the same, it will remove the unnecessary property, leaving only the properties which are necessary. So don't panic when you see only a few chit properties in preferences file.
 
I did it. zlib vars are no longer being used in this script. To copy some of your zlib vars to vProps type zlib chit. in the CLI and choose the ones you need. Then just copy/paste the relevant line, changing the world "zlib" to "set" to create the vProp.

If you want to copy over ALL your vars, then simply copy/paste the following line into the CLI
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);

Note that after the first run of chit, it will compare your properties to the default values for those options and if they are the same, it will remove the unnecessary property, leaving only the properties which are necessary. So don't panic when you see only a few chit properties in preferences file.

I copied the line of code and pasted it into my gCLI and hit <CR>. I got no response of any kind. Did it do anything? I'm sorry, but these instructions are inadequate for those (like me) with limited technical savy. How do I know if I want the first or second option? What will happen if I don't do anything? Please provide explicit instructions and an indication of how to tell if they worked or not. Sorry to sound like a whiney, entitled noobie, but that's exactly how I'm feeling at the moment.

Thanks for all your work and any clarification you can provide on this.
 
It should have done the job. It just doesn't output anything. You can see what it did if you type prefref chit in your CLI.

If you want the second option, just don't copy/paste it. The chance for the first option is over.
 
Last edited:
Not entirely sure why, but even removing script and reinstalling I was unable to get a basic CHIT interface (just had "Enable CHIT" at bottom of character pane, but clicking it did zlib chit.disable = false, which it was already).

I did get it when I copied over settings using the above script though.

In case it helps find what was missing, those settings were:
Code:
chit.autoscroll => true
chit.character.avatar => true
chit.character.title => true
chit.checkversion => false
chit.clan.display => off
chit.clan.home => El Chupacabra
chit.currencies => source essence,BACON
chit.currencies.showmany => false
chit.disable => false
chit.effects.classicons => none
chit.effects.describe => true
chit.effects.layout => songs,buffs,intrinsics
chit.effects.modicons => true
chit.effects.showicons => true
chit.effects.usermap => false
chit.familiar.anti-gollywog => true
chit.familiar.hats => spangly sombrero,sugar chapeau
chit.familiar.pants => spangly mariachi pants,double-ice britches,BRICKO pants,pin-stripe slacks,Studded leather boxer shorts,Monster pants,Sugar shorts
chit.familiar.protect => false
chit.familiar.showlock => false
chit.familiar.terrariumlinklarge => false
chit.familiar.weapons => time sword
chit.floor.layout => update, familiar
chit.gear.display.aftercore => favorites:amount=all, quest:amount=all, charter:amount=all, today:amount=all:create=false, rollover, DRUNK:amount=all
chit.gear.display.in-run => favorites:amount=all:pull=true:create=true, astral:amount=all, item, -combat, +combat, quest:amount=all:pull=true:create=true, today:amount=all:create=false, ML, initiative, path:amount=all, prismatic, res, meat, charter:amount=all, rollover, DRUNK:amount=all, Wow:amount=all
chit.gear.favorites => droll monocle,stinky cheese eye,Hand in Glove,Half a Purse,A Light that Never Goes Out,smiths,hobo code binder,buddy bjorn,The Crown of Ed the Undying,crumpled felt fedora,Hairpiece on Fire,Pantsgiving,Vicar's Tutu,Astral Shirt,duct tape shirt,Stephen's lab coat
chit.gear.layout => default
chit.gear.pull => true
chit.gear.recommend => in-run
chit.helpers.dancecard => true
chit.helpers.semirare => true
chit.helpers.spookyraven => true
chit.helpers.wormwood => stats,spleen
chit.helpers.xiblaxian => true
chit.kol.coolimages => true
chit.quests.hide => false
chit.recommendgear => in-run
chit.roof.layout => character,stats,gear
chit.size.wide => false
chit.stats.layout => muscle,myst,moxie|hp,mp,axel|mcd|trail,florist
chit.stats.showbars => true
chit.thrall.showname => false
chit.toolbar.layout => trail,quests,modifiers,elements,organs
chit.toolbar.moods => true
chit.walls.layout => helpers,thrall,vykea,effects
chit.currencies => BACON|Source essence
chit.familiar.hats => sugar chapeau|spangly sombrero
chit.gear.favorites => duct tape shirt|hobo code binder|crumpled felt fedora|stinky cheese eye|astral shirt|Pantsgiving|The Smith's Tome|A Light that Never Goes Out|Half a Purse|Hairpiece On Fire|Vicar's Tutu|Hand in Glove|Buddy Bjorn|Stephen's lab coat|droll monocle|The Crown of Ed the Undying
 
Prefref chit doesn't give any return values doesn't return any settings for me. Do I need to do something before the default values show in the settings?
 
Prefref chit doesn't give any return values doesn't return any settings for me. Do I need to do something before the default values show in the settings?

Nope! It's all good. One of the beautiful things about Veracity's vision for vProps is that it doesn't clutter up your preferences with unnecessary information. It will only save a property if your choice is different from the default. As long as you use default values, it won't show anything. If you create a setting that is equal to the default, the preference will actually be deleted!

Try adding an item to your favorites in the gear changer. (Next to each item in the gear changer's drop-down menu there is a little + icon. Click that icon to make it a favorite.) Now check prefref chit.
 
In order to change a setting, you need to know what it is called as well as what the default is, so you know whether you WANT to change it.

Surely you look at scripts that you run, in order to see the instructions and configuration options?
 
I emphasize the truth of what Veracity just said. I've never thought to look at setting BEFORE figuring out what I wanted to do with them. What is the problem that you are trying to solve by finding the defaults?


I guess that means I'll have to find the defaults somewhere in the script?

I put them right at the top of charpane.ash so they'll be easy to find if you want to change them. Full information on what they do is in /data/chit_ReadMe.txt

Keep in mind that you don't need to change the defaults to change a specific character's settings. They are there to change the values for ALL characters. (Assuming that you change the copy in /svn/mafiachit/relay.)
 
Back
Top