![]() |
|
#1
|
|||
|
|||
|
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! |
|
#2
|
|||
|
|||
|
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: Code:
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.
__________________
Mohandas K. Gandhi often changed his mind publicly. An aide once asked him how he could so freely contradict this week what he had said just last week. The great man replied that it was because this week he knew better. Last edited by Shaelun : 08-08-2008 at 01:42 AM. |
|
#3
|
|||
|
|||
|
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!
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|