Welcome to CWG Project Home
Search
Home · Topics · Downloads · Your Account · Forums · Top 10
 
 


 
 
Who is Online

There are currently, 99 guest(s) and 17 member(s) that are online.

You are Anonymous user. You can register for free by clicking here
 
 

 
 
Modules

· Home
· Content
· Downloads
· FAQ
· Feedback
· Forums
· Journal
· Members List
· Private Messages
· Recommend Us
· Reviews
· Search
· Statistics
· Stories Archive
· Submit News
· Surveys
· Top 10
· Topics
· Web Links
· Your Account
 
 

 
 
Search



 
 

 
  cwg.lazuras.org :: View topic - TBA Trigger of the Day 070407 Beginner Switch Example
 Forum FAQForum FAQ   SearchSearch   UsergroupsUsergroups   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TBA Trigger of the Day 070407 Beginner Switch Example

 
Post new topic   Reply to topic    cwg.lazuras.org Forum Index -> Builder Lounge
View previous topic :: View next topic  
Author Message
Rumble
CWG - Honored Elder


Joined: Jan 09, 2004
Posts: 781
Location: Monterey, CA USA

PostPosted: Sat Apr 07, 2007 8:38 pm    Post subject: TBA Trigger of the Day 070407 Beginner Switch Example Reply with quote

All these trigger posts sparked a few ideas, so as the topic implies here is the plan:

Every day anyone who wants to can post or request a trigger of the day (just make sure trigger of the day is in the topic, also include beginner, intermediate, advanced). Now the point of this is to demonstrate common ways to use trigedit AND explain how it is done.

Again, anyone can post an example or if they have a trigger idea they want implemented they can post it for others to write a trigger for. This is meant as a community project so the more participation we have the more ideas everyone can come up with. We still have builders on TBA dreaming up new ways to use trigedit all the time.

Some Example Requests:
Give me the best object trigger that incorporates case/switch that you can.
I want a weapon that levels up as it is used, give me a way to do this.

This will be a free for all. First person to post for the day wins. But, there is nothing saying we can't post more than one a day. Also, please reply to the post with feedback if you have another idea or way to do the trig.
_________________
Rumble
The Builder Academy
tbamud.com 9091


Last edited by Rumble on Sun Apr 08, 2007 12:23 pm; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Rumble
CWG - Honored Elder


Joined: Jan 09, 2004
Posts: 781
Location: Monterey, CA USA

PostPosted: Sat Apr 07, 2007 8:39 pm    Post subject: Reply with quote

Quote:
Always use names that explain your trigger and include the VNUM for the
mob/obj/room the trigger is going to be attached to. It is important to give
your trigger a name you and others can understand. This way others can search
"vnum trigger <keyword>." This will also make it easier when using tlist and
tstat. Allowing others to quickly comprehend what the trigger does. Here are
some good examples:

Princess Shout for Help - M2229 --> Trigger 2204 attached to mob 2229.
Tutorial Example Quest Offer - M14 --> Trigger 1 attached to mob 14.
No Recall - R0 --> Trigger 1201 attached to room 0.


Code:
Name: 'Obj Command Magic Eight Ball - O47',  VNum: [    6], RNum: [    6]
Trigger Intended Assignment: Objects
Trigger Type: Command , Numeric Arg: 2, Arg list: shake
Commands:
* By Rumble of The Builder Academy builderacademy.net 9091
* Numeric Arg: 2 means in character's carried inventory.
* Command trigs do not work for level 32 and above.
* There are 20 possible answers that the Magic Eight Ball can give.
* Of these, nine are full positive, two are full negative, one is
* mostly positive, three are mostly negative, and five are abstentions.
*
* Check arguments if they match. /= checks abbreviations.
if ball /= %arg% || eightball /= %arg%
  * Echo text to everyone else in the room and the actor.
  %echoaround% %actor% %actor.name% shakes %self.shortdesc% vigorously.
  %send% %actor% You shake %self.shortdesc% vigorously.
* Use a switch to choose a random response (1-20).
  switch %random.20%
      * Send the answer! %self% is the 8ball, or whatever the trig is attached to.
      * Only the actor sees the answer.
    * Case is what we are trying to match. Does %random.20% == 1?
    case 1
      %send% %actor% %self.shortdesc% reveals the answer: Outlook Good
    * We are done with this case so check the next one.
    break
    case 2
      %send% %actor% %self.shortdesc% reveals the answer: Outlook Not So Good
    break
    case 3
      %send% %actor% %self.shortdesc% reveals the answer: My Reply Is No
    break
    case 4
      %send% %actor% %self.shortdesc% reveals the answer: Don't Count On It
    break
    case 5
      %send% %actor% %self.shortdesc% reveals the answer: You May Rely On It
    break
    case 6
      %send% %actor% %self.shortdesc% reveals the answer: Ask Again Later
    break
    case 7
      %send% %actor% %self.shortdesc% reveals the answer: Most Likely
    break
    case 8
      %send% %actor% %self.shortdesc% reveals the answer: Cannot Predict Now
    break
    case 9
      %send% %actor% %self.shortdesc% reveals the answer: Yes
    break
    case 10
      %send% %actor% %self.shortdesc% reveals the answer: Yes, definitely
    break
    case 11
      %send% %actor% %self.shortdesc% reveals the answer: Better Not Tell You Now
    break
    case 12
      %send% %actor% %self.shortdesc% reveals the answer: It Is Certain
    break
    case 13
      %send% %actor% %self.shortdesc% reveals the answer: Very Doubtful
    break
    case 14
      %send% %actor% %self.shortdesc% reveals the answer: It Is Decidedly So
    break
    case 15
      %send% %actor% %self.shortdesc% reveals the answer: Concentrate And Ask Again
    break
    case 16
      %send% %actor% %self.shortdesc% reveals the answer: Signs Point To Yes
    break
    case 17
      %send% %actor% %self.shortdesc% reveals the answer: My Sources Say No
    break
    case 18
      %send% %actor% %self.shortdesc% reveals the answer: Without A Doubt
    break
    case 19
      %send% %actor% %self.shortdesc% reveals the answer: Reply Hazy, Try Again
    break
    case 20
      %send% %actor% %self.shortdesc% reveals the answer: As I See It, Yes
    break
    * Every switch should have a default. A catch-all if the cases do not match.
    default
      %send% %actor% %self.shortdesc% explodes since your question is unanswerable.
    break
  * Every switch must have a done! Just like every if needs an end!
  done
* The actor didn't use the command shake with arg ball or eightball.
else
* Return 0 allows the command to continue through to the MUD. The player will
* get the Huh!?! response or the shake social if you have one.
  return 0
end

_________________
Rumble
The Builder Academy
tbamud.com 9091
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Shamra
CWG - Member


Joined: Mar 29, 2007
Posts: 89
Location: Virginia, USA

PostPosted: Sat Apr 07, 2007 10:39 pm    Post subject: Reply with quote

I hope everyone gets involved with this nomatter how simple or complex they think their trigger is. I will be posting a few things I have made over the years hope the other regulars will do the same so we can get the rolling.
Back to top
View user's profile Send private message
Jamdog
CWG - Honored Elder


Joined: Jun 18, 2006
Posts: 1685
Location: Halesowen, England

PostPosted: Sun Apr 08, 2007 6:37 am    Post subject: Reply with quote

This is a great idea!

I have learned over the years that one of the fastest ways to learn is by example. When I learned coding, a lot of what I did was copy/pasting chunks of code and altering them slightly.

I do not yet have the skills needed to just write a trigger without referring to references and examples, and as an experienced C coder, I find this frustrating, so I want to learn everything there is to know about triggers.

In many ways it is a lot like C (if statements, and switch statements), but in many ways is very different (enclosing variables in %% and the set command) - I need to learn when it appropriate to use set, and when to use eval. These things come naturally to anyone who has been scripting for a while, but to me, it's like learning C when all I knew was BASIC!

I have seen some fabulous scripts (I love the Sorceress of the Underworld in the Memlin Caverns - when attacked, turns into a staff, which can't be picked up, for 5 mins) and can see the immense possibilities for a wonderfully interactive MUD. I'm sure I'll be using scripts MUCH more in future...
_________________

Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
Shamra
CWG - Member


Joined: Mar 29, 2007
Posts: 89
Location: Virginia, USA

PostPosted: Sun Apr 08, 2007 10:52 am    Post subject: Reply with quote

As to when to use set and when to use eval...
If you are setting a variable to a specific value or string ex set is_open 1 or set name Dingodove, you use set. If you are putting an expression into a variable you use eval, for example eval damage 1 + %actor.maxhit% or eval outcome %random.10% + 100. Hope that helps.
Back to top
View user's profile Send private message
Mordecai
CWG - Honored Elder


Joined: Mar 31, 2004
Posts: 316
Location: New Zealand

PostPosted: Wed Apr 11, 2007 2:54 am    Post subject: Quick examples of switch. Reply with quote

Switch can be used in multiple ways.
For example, you may want to check if a player said a certain word in a long list of words.

Some builders may tackle this challange by using an IF statement.
Which, is the right thing to do, when you have only a few comparisons you want made.

For example:
Code:

if %actor.name% == Polly || %actor.name% == Sue
%echo% You are polly or sue!
else
%echo% You aren't polly or sue
end


If you have a lot of names, or fruit, or spells, or keywords you want to compare then using an IF statement can look messy, AND it is hard to update using the OLC editor.

Code:

switch %actor.name%
 case Polly
 case Sue
 case Mary
 case Albert
  %echo% You are a name in my first list!
  %echo% You can have a Key.
  %load% obj 123
  break
 case Eugine
  %echo% You are a different name.
  %echo% You can have a locked box that needs a Key.
  %load% obj 124
  break
 Default
  %echo% You are not on my list on names!
  %echo% You can have a small mountain of untouchable gold
  %load% obj 125
  break
done


Switch is basically used to compare one value to many values.

You can put multiple CASE statements above each other, which means that the SWITCH will compare the value to all those CASEs, as i did in the example above.

A SWITCH block is the area of a script, that starts with SWITCH and ends with DONE.

When a SWITCH finds a candidate that matches its key, it will execute the ACTIONS below the CASE's.
If the CANDIDATE has more cases below it, the SWITCH's logic will FALL THROUGH the other CASEs to the ACTIONS part, that are above a break.
Code:
Switch KEY
case CANDIDATE
case CANDIDATE
*actions
break
case CANDIDATE
*actions
break
case CANDIDATE
*actions
break
default
*actions
break
done


What happens here?


Code:
Switch apple
case pear
case orange
case pineapple
%echo% Keyboards are an input device
break
case cheese
case apple
case wine
%echo% Monitors are an output device
break
done


What you would see when this script was run is:
Code:
Monitors are an output device


You can use numbers for comparison also in switch's.
Code:
switch %random.5%
case 1
case 2
%echo% The random number landed on 1 or 2
break
case 3
%echo% The random number landed on 3
break
default
%echo% The random number wasn't 1, 2 or 3.
break
done


You may have noticed the
Code:
default

Lines in the SWITCH blocks.
The DEFAULT line is like a CASE line.
Only, it doesnt have an argument, and DEFAULT actions will be gone to if the SWITCH can't find a matching CASE candidate.

If a SWITCH block doesn't have a DEFAULT entry, then when a CASE isn't found, the SWITCH block will end.
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Shamra
CWG - Member


Joined: Mar 29, 2007
Posts: 89
Location: Virginia, USA

PostPosted: Wed Apr 11, 2007 7:08 am    Post subject: Reply with quote

wow I didn't know cases could be strings, nifty.
Back to top
View user's profile Send private message
Mordecai
CWG - Honored Elder


Joined: Mar 31, 2004
Posts: 316
Location: New Zealand

PostPosted: Thu Apr 12, 2007 7:32 am    Post subject: Reply with quote

They can be both!
Internally, the switch code basically uses EVAL to compare things Smile
But in a very efficent matter.

Love your work by the way.
J
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    cwg.lazuras.org Forum Index -> Builder Lounge All times are GMT - 4 Hours
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

Powered by phpBB © 2001, 2005 phpBB Group
 
 


 
 


All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest ? 2002 by me
You can syndicate our news using the file backend.php or ultramode.txt
PHP-Nuke Copyright © 2005 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.28 Seconds