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
miegorengman
Wanderer


Joined: 05 Sep 2008
Posts: 50

PostPosted: Fri Sep 02, 2022 6:26 am   

using %switch to evaluate numerical values that fall within a range
 
I play in a mud where skill levels are textual so you have to to track the numerical values yourself. I created an alias the displays the skill, the current count, and the textual skill level as follows.

--------------------------------------------
>>>>>>>>>>>>Bob's Skill Counts<<<<<<<<<<<<
--------------------------------------------

alchemy 390 Unskilled
channelling 661 Eminent
climbing 241 Good
detect_disease 200 Proficient
--------------------------------------------

in the example above, the numerical values all match the textual reference except alchemy....for some reason it just wants to display as unskilled, no idea why. I have the same issue with several different skills with many different numerical values

here is the code for the alias that creates this output.


Code:
#show --------------------------------------------
#show >>>>>>>>>>>>Bob's Skill Counts<<<<<<<<<<<<
#show --------------------------------------------
#cr                         
#LOCAL $skillName,$skillImps,$BobRowNumber

#repeat %numitems(%countlist(@listOfSkills)) {
  $BobRowNumber=($BobRowNumber+1)
  $skillName=%item(@listOfSkills,$BobRowNumber)
  $skillImps=@{$skillName}
 
 
  #show %concat(%repeat(" ",24-%len(%concat($skillName," ",$skillImps))),$skillName," ",$skillImps," ",%switch($skillImps>0 AND $skillImps<4,"Unskilled",$skillImps>3 AND $skillImps<10,"A tyro",$skillImps>9 AND $skillImps<18,"A novice",$skillImps>17 AND $skillImps<30,"A beginner",$skillImps>29 AND $skillImps<50,"Poor",$skillImps>49 AND $skillImps<70,"Not very good",$skillImps>69 AND $skillImps<90,"Below Average",$skillImps>89 AND $skillImps<110,"Average",$skillImps>109 AND $skillImps<135,"Above Average",$skillImps>134 AND $skillImps<165,"Able",$skillImps>164 AND $skillImps<200,"Fair",$skillImps>199 AND $skillImps<240,"Proficient",$skillImps>239 AND $skillImps<285,"Good",$skillImps>284 AND $skillImps<335,"Adroit",$skillImps>334 AND $skillImps<390,"Very Good",$skillImps>389 AND $skillImps<450,"Excellent",$skillImps>449 AND $skillImps<515,"Expert",$skillImps>514 AND $skillImps<585,"Superb",$skillImps>584 AND $skillImps<660,"Master",$skillImps>659 AND $skillImps<740,"Eminent",$skillImps>739 AND $skillImps<825,"an Adept",$skillImps>824 AND $skillImps<920,"Renowned",$skillImps>919 AND $skillImps<1040,"High Master",$skillImps>1039 AND $skillImps<1200,"Consummate",$skillImps>1199 AND $skillImps<1400,"Virtuoso",$skillImps>1399 AND $skillImps<1700,"A Grandmaster",$skillImps>1699,"Legendary"))}
#cr                         
#show --------------------------------------------



with alchemy's value at 390, it should strip the switch at
Code:
$skillImps>389 AND $skillImps<450,"Excellent"
and output Excellent as the textual skill value


I also tried updating the %switch to read as follows

Code:
%switch($skillImps>=1700,"Legendary",$skillImps>=1400,"A Grandmaster",$skillImps>=1200,"Virtuoso",$skillImps>=1040,"Consummate",$skillImps>=1000,"High 0Master",$skillImps>=825,"Renowned",$skillImps>=740,"an Adept",$skillImps>=660,"Eminent",$skillImps>=585,"Master",$skillImps>=515,"Superb",$skillImps>=450,"Expert",$skillImps>=390,"Excellent",$skillImps>=335,"Very Good",$skillImps>=285,"Adroit",$skillImps>=240,"Good",$skillImps>=200,"Proficient",$skillImps>=165,"Fair",$skillImps>=135,"Able",$skillImps>=110,"Above Average",$skillImps>=90,"Average",$skillImps>=70,"Below Average",$skillImps>=50,"Not very good",$skillImps>=30,"Poor",$skillImps>=18,"A beginner",$skillImps>=10,"A novice",$skillImps>=4,"A tyro",$skillImps>=1,"Unskilled"))



the output is as follows

-------------------------
>>>Bob's Skill Counts<<<
-------------------------

alchemy 390 Legendary
channelling 661 Eminent
climbing 241 Good
detect_disease 200 Proficient

-------------------------


In this example the same skill is with the same numerical value is evaluating incorrectly, in this case on the opposite of the scale.



and ideas what I broke?

thanks for reading :)
Reply with quote
miegorengman
Wanderer


Joined: 05 Sep 2008
Posts: 50

PostPosted: Sat Sep 03, 2022 3:35 pm   
 
i think i figured it out.... the %switch was set up to evaluate integers, and the variables that were not evaluating correctly were string type variables that contained integer type values...so at first glance they look fine, but in this context could not evaluate correctly.


as a result i added a extra line to my counter trigger to guarantee all variables are integers.

Code:
#call %vartype(varname,1)


from http://forums.zuggsoft.com/modules/mx_kb/kb.php?page=3&mode=doc&k=2619

be sure not to leave out the #call if you want to change a variable type.
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