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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Nethran
Novice


Joined: 25 Apr 2011
Posts: 32

PostPosted: Mon May 30, 2011 5:33 pm   

Something Someone Asked Me
 
Shinde on the MM forums wrote:
Just a few critiques:

Does cMud/zMud support named array fields/associative arrays? I think you could clean things up with those. ie: only have one variable (say comstats) with a member for each value. eg: comstats[kills], comstats[bashhit], comstats[bashmiss], etc. Even using just a basic array would make comclear easier (just a for loop).

Also probably a good idea to anchor those triggers and use a match less permissive than *.


As stated several times, I am a newb. This person is obviously more knowledgable than I.

Here are my variables/triggers:

Code:

#VAR kills {0}
#VAR bashhit {0}
#VAR bashmiss {0}
#VAR kickhit {0}
#VAR kickmiss {0}
#VAR evades {0}
#VAR totaldefs {0}
#VAR armhit {0}
#VAR leghit {0}
#VAR headhit {0}
#VAR torsohit {0}
#VAR tailhit {0}
#VAR winghit {0}
#VAR perskills {0}
#VAR parries {0}
#VAR sblocks {0}
#VAR mfades {0}
#VAR acros {0}
#VAR pierces {0}
#VAR bashes {0}
#VAR slashes {0}
#VAR exotics {0}
#VAR hitstaken {0}
#VAR backstabmiss {0}
#VAR backstabs {0}
#VAR weaphits {0}
#VAR weapmisses {0}
#VAR dodges {0}
#TRIGGER {You attempt to stab*in the back with *, but miss.} {#ADD backstabmiss 1}
#TRIGGER {You stab * in the back with *.} {#ADD backstabs 1}
#TRIGGER {You fail to hit * with your*attack.} {#ADD weapmisses 1}
#TRIGGER {You deliver a roundhouse kick to *, connecting solidly.} {#ADD kickhit 1}
#TRIGGER {You attempt to kick * but miss.} {#ADD kickmiss 1}
#TRIGGER {You bash a * over the head with *.} {#ADD bashhit 1}
#TRIGGER {You attempt to bash * over the head with *, but miss.} {#ADD bashmiss 1}
#TRIGGER {*lunges towards you, but you dodge out of the way.} {#ADD evades 1}
#TRIGGER {You are * on the * by a * causing * damage.} {#ADD hitstaken 1}
#TRIGGER {*is*on the %1 with your %2 causing %3 damage.} {#ADD weaphits 1;#IF (%1=arm) {#ADD armhit 1};#IF (%1=leg) {#ADD leghit 1};#IF (%1=tail) {#ADD tailhit 1};#IF (%1=head) {#ADD headhit 1};#IF (%1=wing) {#ADD winghit 1};#IF (%1=torso) {#ADD torsohit 1};#IF (%2=bash) {#ADD bashes 1};#IF (%2=slash) {#ADD slashes 1};#IF (%2=pierce) {#ADD pierces 1};#IF (%2 != bash AND %2 != slash AND %2 != pierce) {#ADD exotics 1};#IF (%3=lethal) {#ADD perskills 1}}
#TRIGGER {*causing lethal damage.} {#ADD kills 1}
#TRIGGER {You {nimbly|skillfully|carefully} {backflip|sidestep|leap} out of the way*attack.} {#ADD acros 1;#ADD totaldefs 1}
#TRIGGER {You catch*on*.} {#ADD sblocks 1;#ADD totaldefs 1}
#TRIGGER {You skillfully parry*attack.} {#ADD parries 1;#ADD totaldefs 1}
#TRIGGER {You dodge out of the way of*attack.} {#ADD dodges 1;#ADD totaldefs 1}
#TRIGGER {You slip between planes for a moment, evading*attack.}  {#ADD mfades 1;#ADD totaldefs 1}

(I know shalimar keeps telling me not to use %1, %2, etc. but I don't really understand the alphabetical versions(%d, %w) and how they differ in function)

Any ideas as to her suggestions? :x
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: Mon May 30, 2011 6:40 pm   
 
What you are looking for are called record variables in zMud and Cmud. These variables consist of 'keys' each of which can be given a unique value. You define record variables with the syntax <recordvar>.<key> = <value> syntax or with the command #ADDKEY <recordvar> <key> <value> To retrieve the value associated with a record variable key, you use the syntax @<recordvar>.<key> or %db(@<recordvar>, <key>) Using a record variable will make it much easier for you to keep all of this data organized efficiently, since it would let you replace the twenty-eight variables in your current script with just one record variable that contains twenty-eight key/value pairs.

In your case, you could define the suggested 'comstats' variable like so:
comstats.kills = 0
comstats.bashhit = 0
comstat.bashmiss = 0

OR

#ADDKEY comstats kills 0
#ADDKEY comstats bashhit 0
#ADDKEY comstats bashmiss 0

OR

#ADDKEY comstats {kills=0|bashhit=0|bashmiss=0}

That's three different methods of defining the same single record variable, called 'comstats' so that it contains three key/value pairs. More key/value pairs can be added as needed.

Then to retrieve these values you might use code something like this:
#SAY You have made @comstats.kills kills.
#SAY You have missed %db(@comstats, bashmiss) bashes.

The %d %w patterns Shalimar is suggesting you use in your trigger patterns are called wild cards in zMud and Cmud. You can find a list of what they do in the help files under wild cards, or look on this page for the online help for pattern matching.

Hope that helps
Reply with quote
Nethran
Novice


Joined: 25 Apr 2011
Posts: 32

PostPosted: Mon May 30, 2011 7:19 pm   
 
Badass, man. That'll help me a ton! :)

What do you make of Shinde's thoughts on using * as a basic catch-all wildcard in my triggers?
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: Mon May 30, 2011 7:56 pm   
 
Anchoring the patterns means using the ^ character and the $ character in your trigger patterns where the line would begin and end. This is a very good idea and something you should try to do whenever possible. It will prevent your triggers from being 'tricked' by invalid lines and also allows the triggers to be checked more efficiently (with less lag/latency).

So, for example, you might change the trigger:
#TRIGGER {You attempt to stab*in the back with *, but miss.} {#ADD backstabmiss 1}
to instead be:
#TRIGGER {^You attempt to stab*in the back with *, but miss.$} {#ADDKEY comstats backstabmiss %eval(@comstats.backstabmiss + 1)}
I've almso incorporated the code to increment a comstats.backstabmiss key/value pair so you can get an idea of how you'd want to do that.

Using a wildcard other than * is also a good idea whenever possible. * matches absolutely anything, which can create issues. Generally, you want to use as precise a wildcard as possible, but it's difficult to recommend better patterns without knowing what the possibilities are for each of the echoes you want to recognize. If you look through the list of wild cards you'll see all of the patterns zMud can recognize. Combine those as needed, and try to favor the more precise wild cards over the more permissive ones.
Reply with quote
Nethran
Novice


Joined: 25 Apr 2011
Posts: 32

PostPosted: Mon May 30, 2011 8:00 pm   
 
But in the case of where a player's name or an npc's name would be, it would be best to use * because the names can be multiple words and thousands of possibilities, right?
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: Mon May 30, 2011 8:01 pm   
 
That's probably true, yes.
Reply with quote
Nethran
Novice


Joined: 25 Apr 2011
Posts: 32

PostPosted: Mon May 30, 2011 11:55 pm   
 
I'm just curious if something like this:
Code:

#VAR copystats
{kills=@kills|bashhit=@bashhit|bashmiss=@bashmiss|kickhit=@kickhit|kickmiss=@kickmiss|evades=@evades|totaldefs=@totaldefs|armhit=@armhit|leghit=@leghit|torsohit=@torsohit|headhit=@headhit|winghit=@winghit|tailhit=@tailhit|perskills=@perskills|parries=@parries|sblocks=@sblocks|mfades=@mfades|acros=@acros|pierces=@pierces|bashes=@bashes|slashes=@slashes|exotics=@exotics|hitstaken=@hitstaken|backstabs=@backstabs|backstabmiss=@backstabmiss|weaphits=@weaphits|weapmisses=@weapmisses|dodges=@dodges|comname=@comname|comtime=@comtime|comaim=@comaim|handed=@handed|isevade=@isevade}

would work to change the values of a mass amount of pre-establish record variables at once or if I'd have to use #ADDKEY again or what. >.>
Reply with quote
shalimar
GURU


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

PostPosted: Tue May 31, 2011 12:58 am   
 
use #ADDKEY not #VAR and it should, yes
_________________
Discord: Shalimarwildcat
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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