Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
jfp
Newbie


Joined: 03 Oct 2012
Posts: 7

PostPosted: Wed Oct 03, 2012 6:25 pm   

General help with aliases/triggers/targetting
 
I'm totally new to MUDding and I was wondering if I could get some help on better understand how to code aliases, triggers, and targetting. I've got a couple topics on here bookmarked, as well as other sites, that sort of helped me to understand these things more, but I am looking for more help. The thing that most confuses me is using parameters in aliases. I have read through the tutorial on aliases in the CMUD help files and looked at various topics in these forums via the search function and I still don't get it.

I have looked at these topics:
http://www.zuggsoft.com/zmud/help6/Intr0179.htm
http://forums.zuggsoft.com/forums/viewtopic.php?t=37881
http://forums.zuggsoft.com/forums/viewtopic.php?t=37190
http://www.zuggsoft.com/forums/viewtopic.php?p=159267

As well as a beginner basic tutorial found here:
http://www.ironrealms.com/coding-for-newbie-vol-1

Since I'm not looking to make any specific aliases I was wondering if anyone could point me in the direction of more resources? I want to get into scripting and be able to code things, but I don't know where to start. I feel so dumb.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4662
Location: Pensacola, FL, USA

PostPosted: Wed Oct 03, 2012 7:19 pm   
 
#HELP %params

%params is the most efficient way of accessing an aliases parameters, although you can use %1-%99 instead.

While you may not have a specific use for it now, go ahead and make one anyway.
The best way to learn is through practice.
_________________
Discord: Shalimarwildcat
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Wed Oct 03, 2012 7:28 pm   
 
It really would be a lot easier if you had something specific you wanted to do. One example would probably be all you need to understand.

Here is are two examples that demonstrate how to use aliases with parameters. Enter the following lines into the command line:
Code:

#ALIAS test1 {#SHOW First parameter: %1, Second parameter %2}
#ALIAS test2 {#SHOW All parameters: %params}

Then type the following commands to test them:
Code:

test1 A B C D
test2 A B C D
Reply with quote
jfp
Newbie


Joined: 03 Oct 2012
Posts: 7

PostPosted: Wed Oct 03, 2012 8:50 pm   
 
I found something I would like to do. If I write
#ALIAS gm {get meat pouch;eat meat} where would I put the %1 and %2 parameters? Would I write it like:
#ALIAS gm {get meat pouch %1;eat meat%2} or am I doing this completely wrong? Embarassed
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4662
Location: Pensacola, FL, USA

PostPosted: Wed Oct 03, 2012 10:21 pm   
 
in your example, it looks like there are NO parametetrs
the alias looks static (as in it only does the one thing, ever)
If you want it to be variable you could do something like....

#ALIAS gm {get %1 pouch;eat %1}
_________________
Discord: Shalimarwildcat
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Wed Oct 03, 2012 10:25 pm   
 
presumably you won't always be eating "meat" nor will you always be getting your food out of a "pouch". Thus, if you typed "gm meat pouch" then %1 would equate to "meat" and %2 would equate to "pouch".

#alias gm {get %1 %2;eat %1}

In a simple alias like this, %1...%99 and similar variables are easy enough to figure out. However, if you have a really complex or otherwise long alias, you might lose track of which parameter is what or perhaps might forget what you were using each parameter for. For these, you can specify named parameters in the form of local variables (the list corresponds to the order in which you pass them):

#alias gm($food,$container) {get $food $pouch;eat $food}

Now, let's talk about the parameters themselves. Parameters are divided up by "word" (a word is defined as a continuous string of non-whitespace characters, so ";',." is a word as is "abc" and "123"). If you wish to include more than one word in a single parameter, or if you wish to pass a space character, you need to surround them in double quotes. Everything inside the quotes would be considered one parameter, and would be assigned accordingly.

There are 2 sets of parameter variables. The single-word parameters (any unquoted one-word parameter, or anything inside quotes) are assigned to the variables %1...%99. If you use named parameters, it's the same thing. Another way to refer to these is via the %param() function. The multi-word parameters (everything from position N onwards) are assigned to the %-1...%-99 variables. You can also access these values via the %params() function, but there is no local variable equivalent.

Here's an example to illustrate what's what: sentence the quick brown fox

alias: sentence
%1: the
%2: quick
%3: brown
%4: fox
%-1: the quick brown fox
%-2: quick brown fox
%-3: brown fox
%-4: fox
_________________
EDIT: I didn't like my old signature
Reply with quote
jfp
Newbie


Joined: 03 Oct 2012
Posts: 7

PostPosted: Thu Oct 04, 2012 6:30 am   
 
When I type #ALIAS gm {get %1 %2;eat %1}
Then "gm meat" into the command line I am returned with "you see no meat here" but then right after that it says "you eat dried rabbit meat" Is this normal?
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4662
Location: Pensacola, FL, USA

PostPosted: Thu Oct 04, 2012 3:33 pm   
 
you are only passing it one parameter in that example, so it attempts to get the meat from the room at large, as no container was specified

to work around this...

#ALIAS gm {$pouch=%if(%2, %2, "pouch");get %1 $pouch;eat %1}

That will test if you have supplied a second parameter, and if not, use pouch as a default
_________________
Discord: Shalimarwildcat
Reply with quote
meddlesome
Wanderer


Joined: 24 Aug 2012
Posts: 70

PostPosted: Fri Oct 05, 2012 1:00 am   
 
Lets say I want to eat. I am hungry and I have food stored in a pouch, but it gets tiresome typing... GET MEAT POUCH;EAT MEAT;PUT MEAT POUCH.

I know it's a bit befuddling so I will explain. One doesn't always eat all of the food, just what is needed to satisfy hunger, so sometimes there are leftovers.

So, to satisfy this in as simplest way possible, I would write it as such:

#ALIAS Munch {get %1 %2;Eat %1;put %1 %2}

To execute this I would type at the command line:

Munch Meat Pouch

This would take Meat and assign it to %1, then take Pouch and assign it to %2.

Is this the best way to handle this? Well, one could just assign Pouch to a variable, because as you know, there are many different containers out there and one won't always be using a Pouch. So to rewrite this it would become...

#VAR Container Pouch

Then the alias becomes:
#ALIAS Munch {get %1 @Container;Eat %1;put %1 @Container}

Then to execute the command to eat would be:
Munch Waybread

Then we need to look at other conditions. Was there really any food left over? Do we need to send a command back to the Mud that returns "I see no Waybread here."

To solve this gets a bit trickier. If, like in the MUD that I play, when I am full, the MUD will tell me by saying "You are full." This tells me when to stop eating. So I could write this as such:

#VAR Container Pouch
#TRIGGER "hungry" {You are hungry.} {#VAR Hungry 1;#PRINT {Please EAT using the Munch Command}}
#TRIGGER "stopeating" {You are full.} {#VAR Hungry 0;Put @Leftovers @Container;#UNVAR Leftovers;#UNVAR Hungry}
#ALIAS Munch {#VAR Leftovers %1;#WHILE (@Hungry) {Get %1 @Container;Eat %1}}

Then when you are hungry you could just type:
Munch Poptart

The script above would continually get poptarts from your pouch and eat them until the MUD comes back an says, "You are full."
Will that work for you? No it won't. Why? Because chances are, your pouch isn't filled with poptarts. It will have a variety of food in there. Any thing from Pigs feet to Oysters on the half shell. So how would you be able to tell the difference? Well, some MUDs have the stuff that gets consumed tagged as FOOD. You would have to cast an identify spell or what ever is used to see if all consumables are tagged as FOOD. If that is the case, then you would have to go with this code:

#VAR Container Pouch
#TRIGGER "hungry" {You are hungry.} {#VAR Hungry 1;#PRINT {Please EAT using the Munch Command}}
#TRIGGER "stopeating" {You are full.} {#VAR Hungry 0;Put Food @Container;#UNVAR Hungry}
#ALIAS Munch {#WHILE (@Hungry) {Get Food @Container;Eat Food}}

Then when hungry, you would just have to type 'Munch' without any parameters and one would eat. But... Why type Munch at all?

#VAR Container Pouch
#TRIGGER "hungry" {You are hungry.} {#VAR Hungry 1;#WHILE (@Hungry) {Get Food @Container;Eat Food}}
#TRIGGER "stopeating" {You are full.} {#VAR Hungry 0;Put Food @Container;#UNVAR Hungry}

I didn't even use an alias then.

There are a few things to note: If you can do without a variable, please do. When I created the variable 'Hungry,' I made it a type Boolean which basically defines the variable as having two values, TRUE and FALSE or 1 and 0. Once I am finished eating, there is no need to continue telling CMUD that you are no longer hungry, so I ditch the variable using the #UNVARIABLE command. But with the 'Container' variable, there is no choice but to keep it around, and there is a good chance that you will find another use for that variable somewhere else.

One final note: I have not tested any of this code to be error proof. I am sure to show kind others here will test and prove worth.
###EDIT APPEND: OH WHAT NASTINESS IS IN THAT CODE DON'T USE IT.!!!!!!
- This is a great example so I will leave it here. Perhaps some of the other guys could take this a bit further?
Godspeed with your future scripting. Don't be afraid to ask. We are friendly from what I see around here. A just itching to help.

{side note} {If the urls become an issue, I'll take them out, but with this person already admitting they are new to scripting I thought better to leave reference.}
oh, and just in case anyone else is wondering: %clip works both ways. You just thought CMUD was just for playing games.
_________________
Intel Core 2 Quad Q9450 @2.66GHz
MDAC 2.8 SP1 ON WINDOWS XP SP3
Msjet40.dll ver 4.0.9511.0 + Security Bulletin MS08-028
CMUD v237
Order number: **7829
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net