Welcome to the Builder Academy

Question Trigger of the Day - Basic Switch

More
31 Mar 2014 13:09 #4790 by Rumble
Code:
Name: 'Switch Echo Example', VNum: [ 18], RNum: [ 18] Trigger Intended Assignment: Rooms Trigger Type: Enter , Numeric Arg: 100, Arg list: None Commands: * By Rumble of The Builder Academy builderacademy.net 9091 * put a wait in here so it doesn't fire before the player enters the room wait 1 switch %random.3% case 1 * only the person entering the room will see this. %send% %actor% You trip over a root as you walk into the room. * everyone in the room except the actor will see this. %echoaround% %actor% %actor.name% trips on a root while walking into the room. * everyone in the room will see this. %echo% The root suddenly springs to life and attacks! * let everyone in the zone hear about this. %zoneecho% %self.vnum% %actor.name% is a clutz. break case 2 %send% %actor% You strut into the room. %echoaround% %actor% %actor.name% Seems to have a big head.. %echo% A strong breeze kicks some leaves up into the air. break case 3 %echo% A light breeze picks up, causing the leaves to rustle quietly. break default * this should be here, even if it's never reached %echo% This is the default case, just in case I missed something. Get it? Just in case! break done
If this was helpful please vote or leave a review for TBA.

Rumble
The Builder Academy
tbamud.com 9091
rumble@tbamud.com

Please Log in or Create an account to join the conversation.

More
02 Apr 2014 23:16 #4794 by Parnassus
Parna's watch list:

Pay special note to that wait at the beginning.

Keep in mind that the switches do not need to be random. For example, I've used words and vnums as switches. Don't forget the breaks!

I'd like to know what the difference is between a random switch and a random if. I generally use the switch for cases with lots of ifs but I don't know if that's accurate.

Watch how the messages are sent and for which conditions. This trigger has excellent notes on the use of echos and messages.

The default is especially good for beginning triggerwriters since it makes it easier to tell if there's a weakness in your switches.

Please Log in or Create an account to join the conversation.

More
06 Apr 2014 22:56 #4816 by Fizban

Parnassus wrote: I'd like to know what the difference is between a random switch and a random if.


You mean how the script Rumble posted differs from the one below?

Code:
Name: 'Switch Echo Example', VNum: [ 18], RNum: [ 18] Trigger Intended Assignment: Rooms Trigger Type: Enter , Numeric Arg: 100, Arg list: None Commands: wait 1 set num %random.3% if %num% == 1 * only the person entering the room will see this. %send% %actor% You trip over a root as you walk into the room. * everyone in the room except the actor will see this. %echoaround% %actor% %actor.name% trips on a root while walking into the room. * everyone in the room will see this. %echo% The root suddenly springs to life and attacks! * let everyone in the zone hear about this. %zoneecho% %self.vnum% %actor.name% is a clutz. elseif %num% == 2 %send% %actor% You strut into the room. %echoaround% %actor% %actor.name% Seems to have a big head.. %echo% A strong breeze kicks some leaves up into the air. elseif %num% == 3 %echo% A light breeze picks up, causing the leaves to rustle quietly. else * this should be here, even if it's never reached %echo% This is the default case, just in case I missed something. Get it? Just in case! end

If so there's no difference, none that particularly matter anyway, just a matter of personal preference, and a potential difference in the amount of cpu time needed to run them both (I think the if check route actually uses less cpu time, but really, it's negligible).

Often switch cases are shorter, but in this instance it's actually less verbose to use the if check route.
The following user(s) said Thank You: Parnassus

Please Log in or Create an account to join the conversation.

More
06 Apr 2014 23:11 #4817 by Parnassus
Thanks, Fizban. That's exactly what I meant! You confused me a bit though because I thought he'd written two triggers that did the same thing until I noticed they were both Name: 'Switch Echo Example', VNum: [ 18], RNum: [ 18].

I think that Fizban's example makes this an even better lesson because it shows that things can be done in different ways and that there isn't necessarily a better or worse between them.

Please Log in or Create an account to join the conversation.

Time to create page: 0.198 seconds