|
knuffel Wanderer
Joined: 12 Jul 2002 Posts: 73
|
Posted: Sun Nov 15, 2009 1:50 pm
Newbie Question: How to make a variable linked to a room. |
Dear All,
After years of "retirement" I returned back to mudding and came to the conclusion I actually had no backup at hand of my good old ZMUD days.
No problem as such, after some amnesia symptoms and aha feelings, I cashed up for CMUD and start to rediscover and map my previous worlds.
Great fun.
Got some basic triggers and buttons helping me out, but now I was wondering what the best way is of doing the following.
I have a lot of rooms with random herbal life and some rooms with specific herbs.
I want to execute a command like
where @herbs is or the generic value herbs a room specific value set in the room that is automatically updated / cleared when I move to the next room.
What would be the easiest way forward.
I browsed through some of the ready scripts, but they look more like rocket science programs ;-)
Thanks for pointing me in the good direction.
Boris |
|
|
|
orphean Apprentice
Joined: 21 Oct 2008 Posts: 147 Location: Olympia, WA
|
Posted: Sun Nov 15, 2009 5:42 pm |
Are you using the mapper? If you are this is easy. Add a room script for the rooms were you can find herbs that sets the @herbs variable to whatever you want it to be for that room.
One room's script might look like
Code: |
#var herbs rosemary |
If there are more than one type of herb in a room I would use a string list instead
Code: |
#var herbs parsley|sage|rosemary|thyme |
Then you could make an alias for search that looks something like:
Code: |
#forall @herbs { #send search %i } |
If you aren't using the mapper it becomes much harder, and you will need to figure out a way for Cmud to keep track of which room you are in and execute a script on your own. I would use the mapper. |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Mon Nov 16, 2009 2:50 pm |
Actually, if you are using the mapper, the easiest thing would be to use the UsrStr value in the map room. This can be set or retrieved with the %roomflags() function. Use that instead of your @herbs.
If you aren't using the mapper, it will depend on how you are determining what room you are in. |
|
|
|
knuffel Wanderer
Joined: 12 Jul 2002 Posts: 73
|
Posted: Mon Nov 23, 2009 9:14 pm |
Thanks a lot for the answers.
I now went with a mixed approach using the variable and the %roomflags() approach and it works perfect, but it seems I am fighting with my #IF statement.
And since the #IF blocks the execution, I rather as the experts.
This is what I have come up with in a button approach to test:
Code: |
#var herbs %roomflags()
#if {@herbs} {} {#var herbs herbs}
search here for @herbs |
Line 1 and 3 works.
2 is giving me a hiccup, and what I try to do is just say IF there is no definition in the %roomflags, eg it is empty, I want to use the generic word herbs instead.
And I fail ;-(
Any help to this silly prob, greatly appreciated.
B. |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Mon Nov 23, 2009 9:25 pm |
Well, first, I would use a local variable, $herbs, instead of a global variable. It is faster, and it disappears after the trigger is done.
Second, you can use "!" to indicate the boolean negative.
Third, you need to put the #if condition in parentheses, (), instead of braces, {}.
Just for clarity and a bit of speed, I will use #send, as well.
Try this:
Code: |
$herbs = %roomflags()
#if (!$herbs) {$herbs = "herbs"}
#send search here for $herbs
|
|
|
|
|
knuffel Wanderer
Joined: 12 Jul 2002 Posts: 73
|
Posted: Tue Nov 24, 2009 7:21 pm |
Perfect !
Works like a charm. Thanks a lot ! |
|
|
|
|
|