PDA

View Full Version : Lich Script Settings



Iamnaeth
08-07-2008, 06:30 PM
How do I have character specific containers running the same script?

I added a setup aspect to my scripts like this:

def setup()
toggle_echo; toggle_unique; toggle_echo
echo "Reply to the following questions by typing \";s to sell <answer>\""
echo "There is no checking for those questions but if you mess up the script likely won't operate."
echo
clear

echo "Where do you store gems and alchemy?"
Settings["lootsack"] = unique_get
Settings.save
exit
end

Settings.load

if variable[1] =~ /setup/i then setup(); end

What I've run into is that if character 1 denotes that he keeps his gems in his jacket, when character 2 runs the script, he tries to get the gems from the jacket even though when he ran the script he specified cloak.

Any tips? Thanks!

Shaelun
08-08-2008, 02:41 AM
Use a second hash with the character name as the key for the first hash, and "lootsack" (or whatever) as the key for the second hash. It would require a little extra checking to make sure you don't erase all the values already in the second hash.

... God this stuff can be difficult to express verbally. Here:



def setup
Settings.load
Settings[Char.name] = Hash.new unless Settings[Char.name].kind_of? Hash

echo "Your container selection, user?"

Settings[Char.name]["lootsack"] = unique_get
Settings.save
exit
end

The Settings[Char.name] = Hash.new unless Settings[Char.name].kind_of? Hash makes sure that if a Hash object already exists for the current character's name, it's just left alone -- but if there isn't one already stored (which would probably only happen the first time the current char ran the script), an empty one is created and stuck in.

The reason you need Settings[Char.name]["lootsack"] (two dereferences instead of one) is because the first bracketed reference, Char.name, dereferences the hash tied to the current character's name. Then that hash has to be dereferenced by a second set of brackets, just as you were doing originally.

Iamnaeth
08-08-2008, 12:49 PM
Thanks for the detailed reply! I'm going to be honest though, it's WAY over my head. I'm gonna give a little time to playing and experimenting with it though. Again, thanks so much!