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 4:56 pm   

Variable In Script By Alias Command
 
Hi again. :) Imma take over the first page of these forums eventually.

So I finished that script, and it's awesome and a bunch of people like it(I posted it on the MUD I play's main forums). I even got a thank you from the game's creator/owner, which is awesome.

Since people like it and all, I decided to make it better. Right now it displayes a whole slew of stats that it gathers over time. Now I'm making three of these displays so you can keep your main stats running and have like.. a micro-sampling or two of stats running beside it, in case you wanted to check/test something. And that's easy enough to handle. And I have 5 "copy" displays you can copy your stats to and keep them there/switch them back to your main(and updatable) display. You know, in case you wanted to stop gathering stats because you're switching characters, etc. and then switch them back because you got on the original character again.

The problem is the display itself. I'm running at 20+ variables per display, which is a lot but not *super* important(though I feel there may be a way to consolidate all the like variables), and each display is just.. a behemoth amount of script. Having 8 of them is.. beastly.

I was wondering if, say, for the copy displays, you could type 'copyview 1' or, as I have it now, 'copyview1' and have it show the only copy display coded(instead of me having to do all 5 individually with the specified variables) along with all the variables for copy displays ending in the number 1. Is there a way to use an alias to alter the variables displayed based on the command input without resorting to a rather large if statement for each instance of a variable in the script?

As a newbish side note, using spaces in alias names doesn't seem to be working for me unless the thing after the space is, in the script, %-1. Any way around that? I mean so I can use 'copyview 1' instead of 'copyview1'.
Reply with quote
shalimar
GURU


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

PostPosted: Mon May 30, 2011 7:37 pm   
 
you could use the argument you are passing to the alias (in this case '1') determine which section of code is copied with a #SWITCH command

Code:
#SWITCH (%1)
  (1) {copy this section}
  (2) {copy that section}
  {copy all sections}


oh right... zMUD... not sure if #SWITCH exits for you, but the same think could be done with a series of #IF statements
_________________
Discord: Shalimarwildcat
Reply with quote
Nethran
Novice


Joined: 25 Apr 2011
Posts: 32

PostPosted: Mon May 30, 2011 8:07 pm   
 
I don't think zMUD does support Switches. I was hoping to avoid the possibility of a series of ifs. Hmm. Even were I to use them, how would I get it to add the 1 or oher number to the end of the variable name? Like @kills1/@kills2/@kills3, etc.
Reply with quote
shalimar
GURU


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

PostPosted: Mon May 30, 2011 8:33 pm   
 
@{kills1} works in CMUD, nos sure if it does in zMUD

If not maybe you can fool around with the below to get it to reference your variable

#LOOP 5 {#EXEC {#SAY %concat("@kill",%i)}}
_________________
Discord: Shalimarwildcat
Reply with quote
Nethran
Novice


Joined: 25 Apr 2011
Posts: 32

PostPosted: Mon May 30, 2011 10:18 pm   
 
Awesome sauce. I'm using:
%exec(%concat(@,kills,%1)).

Works great. :)

So say in my script I have:
Code:

#ALIAS {copyview}
{
#IF (%1=1 OR %1=2 OR %1=3 OR %1=4 OR %1=5)
  {
    #echo You have %exec(%concat(@,kills,%1)) kills.
  }
  {
    #echo %ansi(bright,red)That Copy Info board does not exist.
  }
}


Prollem is, though, that it's allowing me to type 'copyview' without a number after it and is still showing the script. Is there a way to adjust for if no %1 is being used in the command and display 'That Copy Info board does not exist.'?
Reply with quote
shalimar
GURU


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

PostPosted: Mon May 30, 2011 10:39 pm   
 
try this

#IF (%1>0 AND %1<6)


P.S. aliasname does not need to be in braces
_________________
Discord: Shalimarwildcat
Reply with quote
Nethran
Novice


Joined: 25 Apr 2011
Posts: 32

PostPosted: Mon May 30, 2011 10:56 pm   
 
I had what you have first, but still copyview all by itself was allowing the script to work. If it works like that, then it will display the stats without applicable variables(all the variables have been canged to have numbers after them, so if there's no number in the alias command, then there will be no values for the stats displayed).
Reply with quote
Nethran
Novice


Joined: 25 Apr 2011
Posts: 32

PostPosted: Mon May 30, 2011 11:17 pm   
 
And another problem:
Code:

%exec(%concat(@,copystats,%1,"."ckills,%1)) = @kills


I have an alias to do this, to test. Anyway, it's not working.

I've tried it without the @, and I've tried it with
Code:

#VAR %exec(%concat(@,copystats,%1,"."ckills,%1)) {@kills}


None work.

I also have:
Code:

#echo %exec(%concat(@,copystats,%1,"."ckills,%1))


And that works fine.

Any suggestions?
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: Mon May 30, 2011 11:22 pm   
 
Try using the #EXEC command instead of beginning the line with an %exec() function.
Reply with quote
Nethran
Novice


Joined: 25 Apr 2011
Posts: 32

PostPosted: Mon May 30, 2011 11:27 pm   
 
That, of course, worked. Thank you sir.

Still this, though:
Nethran wrote:
I had what you have first, but still copyview all by itself was allowing the script to work. If it works like that, then it will display the stats without applicable variables(all the variables have been canged to have numbers after them, so if there's no number in the alias command, then there will be no values for the stats displayed).
Reply with quote
Taz
GURU


Joined: 28 Sep 2000
Posts: 1395
Location: United Kingdom

PostPosted: Tue May 31, 2011 5:50 pm   
 
#if (%1=%null) {#say no go} {#say ya ya}
_________________
Taz :)
Reply with quote
Nethran
Novice


Joined: 25 Apr 2011
Posts: 32

PostPosted: Tue May 31, 2011 7:56 pm   
 
Ahh, sweet. Thanks, man.
Reply with quote
Nethran
Novice


Joined: 25 Apr 2011
Posts: 32

PostPosted: Wed Jun 08, 2011 10:36 pm   
 
Been tweaking some stuff. If I wanted %1 to default to 1 if it in fact is equal to %null... How would I do that? I have some code saying:
Code:

#ALIAS cinfo {#IF (%1=%null) {%1=1};#IF (%1>0 AND %1<4) {combat info;#SAY %repeat(" ",2);#SAY %ansi(bright,blue)Combat Information for sessions starting: %ansi(white)%exec(%concat(@,comstats,%1,".",comtime));#SAY %ansi(bright,blue)Defensive Statistics:;#SAY %repeat(" ",2)%ansi(bright,blue)%format("&5s", "Dodge:")%repeat(" ",2)%ansi(white)%format("&10.0n", %exec(%concat(@,comstats,%1,".",dodges)))%ansi(bright,blue)%format("&24s", "Acro:")%repeat(" ",3)%ansi(white)%format("&10.0n", %exec(%concat(@,comstats,%1,".",acros)));#SAY %repeat(" ",2)%ansi(bright,blue)%format("&5s", "SBlock:")%repeat(" ",1)%ansi(white)%format("&10.0n", %exec(%concat(@,comstats,%1,".",sblocks)))%ansi(bright,blue)%format("&24s", "Parry:")%repeat(" ",3)%ansi(white)%format("&10.0n", %exec(%concat(@,comstats,%1,".",parries)));#SAY %repeat(" ",2)%ansi(bright,blue)%format("&5s", "MFade:")%repeat(" ",2)%ansi(white)%format("&10.0n", %exec(%concat(@,comstats,%1,".",mfades)));#SAY %ansi(yellow)* %ansi(bright,blue)You are currently using %ansi(white)%exec(%concat(@,comstats,%1,".",comdefense)) %ansi(bright,blue)to defend yourself.;#SAY %ansi(yellow)* %ansi(bright,blue)You have used a proficiency-based defense %ansi(white)%exec(%concat(@,comstats,%1,".",totaldefs)) %ansi(bright,blue)times and have been hit %ansi(white)%exec(%concat(@,comstats,%1,".",hitstaken)) %ansi(bright,blue)times, with a defense rate of %ansi(white)%format("&.0n",%eval(%exec(%concat(@,comstats,%1,".",totaldefs))*100/(%exec(%concat(@,comstats,%1,".",totaldefs))+%exec(%concat(@,comstats,%1,".",hitstaken)))).%mod(%exec(%concat(%,comstats,%1,".",totaldefs))*1000/(%exec(%concat(@,comstats,%1,".",totaldefs))+%exec(%concat(@,comstats,%1,".",hitstaken))),10))"%"%ansi(bright,blue).;#SAY %ansi(yellow)* %ansi(bright,blue)Evade is %ansi(white)%exec(%concat(@,comstats,%1,".",isevade))%ansi(bright,blue) and you have evaded %ansi(white)%exec(%concat(@,comstats,%1,".",evades)) %ansi(bright,blue)attacks.;#SAY %ansi(bright,blue)Offensive Statistics:;#SAY %repeat(" ",2)%ansi(bright,blue)Damage Types Dealt:;#SAY %repeat(" ",2)%ansi(bright,blue)%format("&5s", "Pierce:")%repeat(" ",1)%ansi(white)%format("&10.0n", %exec(%concat(@,comstats,%1,".",pierces)))%ansi(bright,blue)%format("&24s", "Bash:")%repeat(" ",3)%ansi(white)%format("&10.0n", %exec(%concat(@,comstats,%1,".",bashes)));#SAY %repeat(" ",2)%ansi(bright,blue)%format("&5s", "Slash:")%repeat(" ",2)%ansi(white)%format("&10.0n", %exec(%concat(@,comstats,%1,".",slashes)))%ansi(bright,blue)%format("&24s", "Exotic:")%repeat(" ",3)%ansi(white)%format("&10.0n", %exec(%concat(@,comstats,%1,".",exotics)));#SAY %repeat(" ",2)%ansi(bright,blue)Location Accuracy:;#SAY %repeat(" ",2)%ansi(bright,blue)%format("&5s", "Head:")%repeat(" ",3)%ansi(white)%format("&10.0n",%exec(%concat(@,comstats,%1,".",headhit)))%format("&36s",%concat(%ansi(bright,blue),"(",%ansi(white),%eval(%exec(%concat(@,comstats,%1,".",headhit))*100/%exec(%concat(@,comstats,%1,".",weaphits))),"%",%ansi(bright,blue),")"))%ansi(bright,blue)%format("&18s", "Torso:")%repeat(" ",3)%ansi(white)%format("&10.0n",%exec(%concat(@,comstats,%1,".",torsohit)))%format("&36s",%concat(%ansi(bright,blue),"(",%ansi(white),%eval(%exec(%concat(@,comstats,%1,".",torsohit))*100/%exec(%concat(@,comstats,%1,".",weaphits))),"%",%ansi(bright,blue),")"));#SAY %repeat(" ",2)%ansi(bright,blue)%format("&5s", "Arms:")%repeat(" ",3)%ansi(white)%format("&10.0n",%exec(%concat(@,comstats,%1,".",armhit)))%format("&36s",%concat(%ansi(bright,blue),"(",%ansi(white),%eval(%exec(%concat(@,comstats,%1,".",armhit))*100/%exec(%concat(@,comstats,%1,".",weaphits))),"%",%ansi(bright,blue),")"))%ansi(bright,blue)%format("&18s", "Legs:")%repeat(" ",3)%ansi(white)%format("&10.0n",%exec(%concat(@,comstats,%1,".",leghit)))%format("&36s",%concat(%ansi(bright,blue),"(",%ansi(white),%eval(%exec(%concat(@,comstats,%1,".",leghit))*100/%exec(%concat(@,comstats,%1,".",weaphits))),"%",%ansi(bright,blue),")"));#SAY %repeat(" ",2)%ansi(bright,blue)%format("&5s", "Tail:")%repeat(" ",3)%ansi(white)%format("&10.0n",%exec(%concat(@,comstats,%1,".",tailhit)))%format("&36s",%concat(%ansi(bright,blue),"(",%ansi(white),%eval(%exec(%concat(@,comstats,%1,".",tailhit))*100/%exec(%concat(@,comstats,%1,".",weaphits))),"%",%ansi(bright,blue),")"))%ansi(bright,blue)%format("&18s", "Wings:")%repeat(" ",3)%ansi(white)%format("&10.0n",%exec(%concat(@,comstats,%1,".",winghit)))%format("&36s",%concat(%ansi(bright,blue),"(",%ansi(white),%eval(%exec(%concat(@,comstats,%1,".",winghit))*100/%exec(%concat(@,comstats,%1,".",weaphits))),"%",%ansi(bright,blue),")"));#SAY %ansi(yellow)* %ansi(bright,blue)You are currently aiming for your opponents' %ansi(white)%exec(%concat(@,comstats,%1,".",comaim))%ansi(bright,blue).;#SAY %ansi(yellow)* %ansi(bright,blue)You have killed %ansi(white)%exec(%concat(@,comstats,%1,".",perskills)) %ansi(bright,blue)creatures have been involved in %ansi(white)%exec(%concat(@,comstats,%1,".",kills)) %ansi(bright,blue)total kills with a last-hit rate of %ansi(white)%format("&.0n",%eval(%exec(%concat(@,comstats,%1,".",perskills))*100/%exec(%concat(@,comstats,%1,".",kills))).%mod(%exec(%concat(%,comstats,%1,".",perskills))*1000/%exec(%concat(@,comstats,%1,".",kills)),10))"%"%ansi(bright,blue).;#SAY %ansi(yellow)* %ansi(bright,blue)You have landed %ansi(white)%exec(%concat(@,comstats,%1,".",weaphits)) %ansi(bright,blue)total attacks and missed a total of %ansi(white)%exec(%concat(@,comstats,%1,".",weapmisses)) %ansi(bright,blue)times with an overall accuracy of %ansi(white)%format("&.0n",%eval(%exec(%concat(@,comstats,%1,".",weaphits))*100/(%exec(%concat(@,comstats,%1,".",weapmisses))+%exec(%concat(@,comstats,%1,".",weaphits)))).%mod(%exec(%concat(%,comstats,%1,".",weaphits))*1000/(%exec(%concat(@,comstats,%1,".",weapmisses))+%exec(%concat(@,comstats,%1,".",weaphits))),10))"%"%ansi(bright,blue).;#SAY %ansi(yellow)* %ansi(bright,blue)You have landed %ansi(white)%exec(%concat(@,comstats,%1,".",backstabs)) %ansi(bright,blue)backstabs and missed with %ansi(white)%exec(%concat(@,comstats,%1,".",backstabmiss)) %ansi(bright,blue)backstabs, with a success rate of %ansi(white)%format("&.0n",%eval(%exec(%concat(@,comstats,%1,".",backstabs))*100/(%exec(%concat(@,comstats,%1,".",backstabmiss))+%exec(%concat(@,comstats,%1,".",backstabs)))).%mod(%exec(%concat(%,comstats,%1,".",backstabs))*1000/(%exec(%concat(@,comstats,%1,".",backstabmiss))+%exec(%concat(@,comstats,%1,".",backstabs))),10))"%"%ansi(bright,blue).;#SAY %ansi(yellow)* %ansi(bright,blue)You have landed %ansi(white)%exec(%concat(@,comstats,%1,".",bashhit)) %ansi(bright,blue)bashes and missed with %ansi(white)%exec(%concat(@,comstats,%1,".",bashmiss)) %ansi(bright,blue)bashes, with a success rate of %ansi(white)%format("&.0n",%eval(%exec(%concat(@,comstats,%1,".",bashhit))*100/(%exec(%concat(@,comstats,%1,".",bashhit))+%exec(%concat(@,comstats,%1,".",bashmiss)))).%mod(%exec(%concat(%,comstats,%1,".",bashhit))*1000/(%exec(%concat(@,comstats,%1,".",bashmiss))+%exec(%concat(@,comstats,%1,".",bashhit))),10))"%"%ansi(bright,blue).;#SAY %ansi(yellow)* %ansi(bright,blue)You have landed %ansi(white)%exec(%concat(@,comstats,%1,".",kickhit)) %ansi(bright,blue)kicks and missed with %ansi(white)%exec(%concat(@,comstats,%1,".",kickmiss)) %ansi(bright,blue)kicks, with a success rate of %ansi(white)%format("&.0n",%eval(%exec(%concat(@,comstats,%1,".",kickhit))*100/(%exec(%concat(@,comstats,%1,".",kickhit))+%exec(%concat(@,comstats,%1,".",kickmiss)))).%mod(%exec(%concat(%,comstats,%1,".",weaphits))*1000/(%exec(%concat(@,comstats,%1,".",weapmisses))+%exec(%concat(@,comstats,%1,".",weaphits))),10))"%"%ansi(bright,blue).;#SAY %ansi(yellow)* %ansi(bright,blue)Your combat mode is set to %ansi(white)%exec(%concat(@,comstats,%1,".",commode))%ansi(bright,blue).;#SAY %ansi(yellow)* %ansi(bright,blue)You are %ansi(white)%exec(%concat(@,comstats,%1,".",handed))%ansi(bright,blue)-handed.;#SAY %ansi(yellow)* %ansi(bright,red)You are viewing Combat Info board %ansi(white)%1%ansi(bright,red).;#SAY {%ansi(yellow)* %ansi(bright,red)To view additional commands, type '%ansi(white)ccom%ansi(bright,red)'.}} {#SAY %repeat(" ",2);#SAY %ansi(bright,red)That Combat Info board does not exist. Please specify 1, 2, or 3.;#EXEC "  "} {#SAY %repeat(" ",2);#SAY %ansi(bright,red)That Combat Info board does not exist. Please specify 1, 2, or 3.;#EXEC " "}}


I know that's a big-ass block of code. What's important about it is that:
A: The value of %1 is paramount. Equalling nothing is not an option, and I'd like to be able to type cinfo all by itself to activate cinfo 1 and the variables that would match with %1 being equal to 1.
B: The if statement trying to establish a value for %1 at the very beginning of the script doesn't work.


Is this possible?
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: Thu Jun 09, 2011 12:50 am   
 
%1 can't be defined within the alias. Its value has to be passed to the alias. The simplest fix for this code would be to use two aliases, such that the first alias is calling the second.
To accomplish that, change your current 'cinfo' alias to instead be called 'do_cinfo' and then make a new cinfo alias like so:

Code:
#ALIAS cinfo {#IF %null(%1) {do_cinfo 1} {do_cinfo %1}}

With that, you should be able to use the cinfo alias and have it behave as desired. There are tidier ways to accomplish the same thing, but I think this solution will require the fewest changes to your code.
Reply with quote
Taz
GURU


Joined: 28 Sep 2000
Posts: 1395
Location: United Kingdom

PostPosted: Thu Jun 09, 2011 1:50 pm   
 
Alternatively change this part #IF (%1=%null) {%1=1};#IF (%1>0 AND %1<4)

to

#IF (%1=%null) {cinum=1} {cinum=%1};#IF (@cinum>0 AND @cinum<4)

that way you don't need an extra calling alias.

Feel free to also change (%1=%null) to %null(%1) they're the same but some people would say the second is more correct from a programming point of view.
_________________
Taz :)
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: Thu Jun 09, 2011 2:39 pm   
 
Nethran references %1 in a few dozen places throughout that alias, Taz, not just the #IF in the first line. For your solution to work, all those instances of %1 would need to be replaced with @cinum.
Reply with quote
Taz
GURU


Joined: 28 Sep 2000
Posts: 1395
Location: United Kingdom

PostPosted: Thu Jun 09, 2011 7:35 pm   
 
*slaps wrists* I really should have read past the first little bit of the alias.

Nethran unless you really, really only want the one alias I suggest using DraxDrax's approach, otherwise search and replace %1 with @cinum except for those first two instances.
_________________
Taz :)
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Sun Jun 12, 2011 12:47 am   
 
I think the easiest way would actually be to make the alias call itself, similar to DraxDrax's solution but not requiring a second alias. It would look something like this:
Code:
#ALIAS cinfo {#IF %null(%1) {cinfo 1} {the rest of your code here}}

This way you only need to make one small change to the first line of your alias.
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