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
bishopnenar
Beginner


Joined: 20 Mar 2007
Posts: 27

PostPosted: Tue Apr 24, 2007 3:28 pm   

Alias Not Firing: Need some Advice.
 
Here is the Alias I have:

Code:

#IF ((@stunned) || (@unconscious)) {
  #SHOW %ansi( 2062)Healing Aborted
  #ABORT 1
  } {#IF (@aeon) {
    aeon
    #ABORT 1
    }} {#IF (!@awake) {
    wake
    #ABORT 1
    } {
    #IF (!@def_insomnia ) {insomnia}
    #IF ((%numitems( @affs_salves) > 0) && (@balancesalvecures)) {
      affssalves = %sort( @affs_salves)
      #EXECUTE %item( @affs_salves, 1)
      }
    #IF ((%numitems( @affs_herbs) > 0) && (@balanceherbcures)) {
      affsherbs = %sort( @affs_herbs)
      #EXECUTE %item( @affs_herbs, 1)
      }
    }}


Now, stunned and unconscious ar 0, Aeon = 0, awake = 1, so the script should be firing insomnia, which def_insomnia = 0, Right?

I tested the last three #IF seperately, they work in thier own aliases, so why not here what am I missing??


Thanks
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Tue Apr 24, 2007 4:27 pm   
 
I have no idea why this script was broken (no obvious syntax errors and if it were aborting at one of the #if statements before the insomnia one, there'd be some kind of message or command sent), but I decided to rebuild the script using the #switch command instead of those nested #ifs and that fixed it. I have no idea why, but this works:

Code:
#switch (@stunned OR @unconscious) {
  #SHOW %ansi( 2062)Healing Aborted
  #ABORT 1
  } (@aeon) {
  aeon
  #abort 1
  } (!@awake) {
  wake
  #abort 1
  } {
  #IF (!@def_insomnia) {insomnia}
  #IF ((%numitems( @affs_salves) > 0) && (@balancesalvecures)) {
    affssalves = %sort( @affs_salves)
    #EXECUTE %item( @affs_salves, 1)
    }
  #IF ((%numitems( @affs_herbs) > 0) && (@balanceherbcures)) {
    affsherbs = %sort( @affs_herbs)
    #EXECUTE %item( @affs_herbs, 1)
    }
  }
Reply with quote
bishopnenar
Beginner


Joined: 20 Mar 2007
Posts: 27

PostPosted: Tue Apr 24, 2007 4:31 pm   
 
I had no idea you could use Switch to diffent expression...

Is this "faster" then using the nested #IFs??

Also, when insomina fires, the echoed command is "insomina 1" noticed this in a few thing, I have to add #EXE to make the commands to the MUD not have that "1". Any reason why it does that?

Thanks for helping!!
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Tue Apr 24, 2007 4:43 pm   
 
It's a bug with the Auto Append option, which is on by default for aliases imported from zMUD. It's a checkbox next to the Params box - just uncheck it.

It's not necessarily faster, it's just prettier and it works :P The main speed bottleneck is going to be sorting and saving your affliction stringlists. Are you just curing in alphabetical order, or is there some kind of number priority system? It'd probably be faster to use a record variable, anyway.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
bishopnenar
Beginner


Joined: 20 Mar 2007
Posts: 27

PostPosted: Tue Apr 24, 2007 4:51 pm   
 
This is a priority system.

Not to sure on record variables.

Any advice?
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Tue Apr 24, 2007 5:17 pm   
 
Well, there's no easy way to sort recordvars and then just pop a result off, so you have two options really. If you're keeping your data as keys of the recordvar (the value's irrelevant since you're testing for the presence of the key, not its value). You're basically limited to a string of #if statements (or a single #switch statement) that each test for the presence of a key. You can either do that by having your affliction add alias do "#addkey Afflictions Paralysis 1" and then have #if (@Afflictions.Paralysis) {whatever}, or you can use #if (%iskey(@Afflictions,Paralysis)) - the latter is probably slower, but I haven't tested it. In both cases, your affliction remove alias will do "#delkey Afflictions Paralysis".

If that all went over your head, read the help files on database record variables. They'll explain better than I can how they store data.

EDIT: Oh, and fyi - I just remembered from Tech's speed tests. This:

Code:
#if (@Afflictions.something) {whatever}
#if (@Afflictions.something) {whatever}
#if (@Afflictions.something) {whatever}
#if (@Afflictions.something) {whatever}
...


is slower, especially when you have a lot of iterations, than

Code:
$Afflictions=@Afflictions
#if ($Afflictions.something) {whatever}
#if ($Afflictions.something) {whatever}
#if ($Afflictions.something) {whatever}
#if ($Afflictions.something) {whatever}
...
Reply with quote
bishopnenar
Beginner


Joined: 20 Mar 2007
Posts: 27

PostPosted: Tue Apr 24, 2007 5:48 pm   
 
Interesting, but are you able to prioritize with this? Since certain afflictions are better to heal first then others? Or I suppose you could use #SWITCH

Code:

$affliections=@afflictions
#IF  (@you_can_heal) {#SWITCH ($afflictions.really_need_to_heal) {do it} ($afflictions.kinda_need_to_heal) {do this} .. etc }}

And this would be much faster then %sort as I oringally wrote it?
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Tue Apr 24, 2007 7:01 pm   
 
Well, the #switch statement will break at the first expression that's true. If you want an affliction to be cured first, you just put it first in the list. Say you had paralysis, anorexia and slickness and you wanted them cured in that order. You'd do

#switch (@Afflictions.paralysis) {whatever} (@Afflictions.anorexia) {whatever} (@Afflictions.slickness) {whatever}

changing the priority is as easy as changing the order:

#switch (@Afflictions.paralysis) {whatever} (@Afflictions.slickness) {whatever} (@Afflictions.anorexia) {whatever}
#switch (@Afflictions.anorexia) {whatever} (@Afflictions.slickness) {whatever} (@Afflictions.paralysis) {whatever}
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
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