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
hpoonis2010
Adept


Joined: 18 Jun 2019
Posts: 279

PostPosted: Fri Jan 31, 2020 4:19 pm   

Multifunction alias
 
Am trying to setup a useful alias script that sends me to a relevant potion vendor to purchase items dependent on character level.

Code:
#IF (%2 < 1) {$num=1} {#MATH $num %2*30}

#SWITCH (%1)
  ("heal") {
    #SWITCH (@curlev)
      (<20) {#WALK aeler;#VAR hl "light relief";buy $num @hl;pc all.'@hl'}
      (<40) {#WALK aeler;#VAR hl "serious relief";buy $num @hl;pc all.'@hl'}
      (<60) {#WALK aeler;#VAR hl "critical care";buy $num @hl;pc all.'@hl'}
      {#WALK duff;#VAR hl "duff";buy $num @hl;pc all.'@hl'}
  }
  ("ref") {
    #SWITCH (@curlev)
      (<50) {#WALK aeler;#VAR rf "green tea";buy $num @rf;pc all.'@rf'}
      (<90) {#WALK pharm;#VAR rf "divine";buy $num @rf;pc all.'@rf'}
      {#WALK duff;#VAR rf "moonshine";buy $num @rf;pc all.'@rf'}
  }
  ("mana") {
    #SWITCH (@curlev)
      (<30) {#WALK aeler;#VAR mn "rush";buy $num @mn;pc all.'@mn'}
      (<50) {#WALK pharm;#VAR mn "beads";buy $num @mn;pc all.'@mn'}
      (<90) {#WALK duff;#VAR mn "tequila";buy $num @mn;pc all.'@mn'}
      {#WALK duff;#VAR mn "vodka";buy $num @mn;pc all.'@mn'}
  }


Am getting

ERROR: Syntax error in Alias: shop2 : illegal character in expression: <

As the error function gives no line number, I can only assume it is the first instance. If so, how do I test for the alias parameter being less than a specific value?
Reply with quote
shalimar
GURU


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

PostPosted: Sun Feb 02, 2020 3:11 am   
 
You can't use #SWITCH in that manner unless you are testing against a static value, like in the outer #SWITCH, if you want to compare the value in the nested #SWITCHes you need more explicit expressions:

Code:
#SWITCH (@curlev<30) {#WALK aeler;#VAR mn "rush";buy $num @mn;pc all.'@mn'}
      (@curlev<50) {#WALK pharm;#VAR mn "beads";buy $num @mn;pc all.'@mn'}
      (@curlev<90) {#WALK duff;#VAR mn "tequila";buy $num @mn;pc all.'@mn'}
      {#WALK duff;#VAR mn "vodka";buy $num @mn;pc all.'@mn'}
_________________
Discord: Shalimarwildcat
Reply with quote
hpoonis2010
Adept


Joined: 18 Jun 2019
Posts: 279

PostPosted: Tue Feb 04, 2020 9:54 am   
 
Thanks. I had it that way originally but some other error prompted me to alter it (just in case , or to simplify the code).

Now it functions. I had to go with a permanent count (num) variable as there appeared to be issues with the scope of the local variable that I couldn't easily pin down (but that may have been complicated by other errors)..

I am also thinking of using an indirect reference to the potion vars (rf, mn, hl, etc) to make a simpler version, such as:

buy @num @potion;pc all.@potion

and have @potion be one of @hl, @mn, @rf, etc

Code:
#VAR num
#IF (%2<1) {num=30} {#MATH num 30*%2}

#SWITCH (%1)
  ("fly") {#WALK aeler;#VAR fly "blood";buy @num @fly;pc all.@fly}
 
  ("heal") {
    #SWITCH (@curlev<20) {#WALK aeler;#VAR hl "relief";buy @num @hl;pc all.@hl}
      (@curlev<40) {#WALK aeler;#VAR hl "serious";buy @num @hl;pc all.@hl}
      (@curlev<60) {#WALK aeler;#VAR hl "critical";buy;@num @hl;pc all.@hl}
      {#WALK duff;#VAR hl "duff";buy @num @hl;pc all.@hl}
  }
 
  ("mana") {
    #SWITCH (@curlev<30) {#WALK aeler;#VAR mn "rush";buy @num @mn;pc all.@mn}
      (@curlev<50) {#WALK pharm;#VAR mn "beads";buy @num @mn;pc all.@mn}
      (@curlev<90) {#WALK duff;#VAR mn "tequila";buy @num @mn;pc all.@mn}
      {#WALK duff;#VAR mn "vodka";buy @num @mn;pc all.@mn}
  }
 
  ("ref") {
    #SWITCH (@curlev<50) {#WALK aeler;#VAR rf "tea";buy @num @rf;pc all.@rf}
      (@curlev<90) {#WALK pharm;#VAR rf "divine";buy @num @rf;pc all.@rf}
      {#WALK duff;#VAR rf "moonshine";buy @num @rf;pc all.@rf}
  }
Reply with quote
shalimar
GURU


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

PostPosted: Tue Feb 04, 2020 12:42 pm   
 
because it was defined within the #IF, it dies in the #IF unless you initialize it BEFORE the #IF.

#LOCAL $num
#IF (%2<1) {$num=30} {$num=(30*%2)}

For the indirect issue... does all.@var even work? I would use something like:

#FORALL @potion {pc %i}
_________________
Discord: Shalimarwildcat
Reply with quote
hpoonis2010
Adept


Joined: 18 Jun 2019
Posts: 279

PostPosted: Thu Apr 16, 2020 7:49 am   
 
all.@var does work.

Simpler to put 150 potions in a bag than 150 commands to put a potion in a bag.
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