  | 
	
	
	
		hpoonis2010 Adept
  
  Joined: 18 Jun 2019 Posts: 279
 
  | 
		
		  
			
			   Posted: Sun May 09, 2021 1:06 pm   
  Nested SWITCHes   | 
			 
			
				If anyone can see why the nested switch statements are not being tested, I'd appreciate it.  I cannot see anything amiss.
 
 
I inserted some write statements and the outer SWITCH is being tested fine.  I am certain I have used such a structure in the past.
 
 
 
	  | Code: | 
	 
	
	  $charLev=@char_VARS/charLev
 
$potBag=aardbag4
 
$batch=25
 
#LOCAL $num
 
#LOCAL $shop
 
#LOCAL $object
 
#LOCAL $keyword
 
#LOCAL $potLev
 
 
#IF ((%numparam()=1) OR (%param(2)=1)) {$num=$batch} {$num=(%param(2) * $batch)}
 
 
#SWITCH (%1)
 
  ("arm") {$keyword="resistance";$shop=26331;$potLev=10}
 
  ("bls") {
 
    #SWITCH ($charLev)
 
      ($charLev<15) {$keyword="prayer";$shop=32476;$potLev=7}
 
      ($charLev<25) {$keyword="blessing";$shop=32172;$potLev=15}
 
      ($charLev<57) {$keyword="special";$shop=26275;$potLev=25}
 
      ($charLev>=57) {$keyword="embrace";$shop=32408;$potLev=57}
 
    }
 
  ("fly") {$keyword="griffon";$shop=32476;$potLev=1}
 
  ("hp") {
 
    #IF (@baseLev<201) {
 
      #SWITCH ($charLev)
 
        ($charLev<10) {$keyword "relief";$shop=32476;$potLev=1}
 
        ($charLev<20) {$keyword "elixir";$shop=37894;$potLev=10}
 
        ($charLev<40) {$keyword "serious";$shop=32476;$potLev=20}
 
        ($charLev<60) {$keyword "care";$shop=32476;$potLev=40}
 
        ($charLev>=60) {$keyword "duff";$shop=23160;$potLev=60}
 
      } {$keyword="strawberry";$shop=52684;$potLev=201}
 
    }
 
  ("invis") {$keyword="beyond";$shop=32476;$potLev=1}
 
  ("mn") {
 
    #SWITCH ($charLev)
 
      ($charLev<20) {$keyword="rush";$shop=32476;$potLev=1}
 
      ($charLev<40) {$keyword="lotus";$shop=49497;$potLev=20}
 
      ($charLev<60) {$keyword="penguin";$shop=14696;$potLev=40}
 
      ($charLev<80) {$keyword="raspberry";$shop=52684;$potLev=60}
 
      ($charLev<100) {$keyword="hukomana";$shop=52871;$potLev=80}
 
      ($charLev<120) {$keyword="vodka";$shop=23160;$potLev=100}
 
      ($charLev<150) {$keyword="cupcake";$shop=52684;$potLev=120}
 
      ($charLev<175) {$keyword="vitae";$shop=52143;$potLev=150}
 
      ($charLev<200) {$keyword="phyltre";$shop=45179;$potLev=175}
 
      ($charLev>=200) {$keyword="jack";$shop=23160;$potLev=200}
 
    }
 
  ("mv") {
 
    #SWITCH ($charLev)
 
      ($charLev<10) {$keyword="tea";$shop=32476;$potLev=1}
 
      ($charLev<30) {$keyword="cactus";$shop=5924;$potLev=10}
 
      ($charLev<60) {$keyword="cocoa";$shop=14696;$potLev=30}
 
      ($charLev<80) {$keyword="wind";$shop=50238;$potLev=60}
 
      ($charLev<90) {$keyword="yellow";$shop=52871;$potLev=80}
 
      ($charLev>=90) {$keyword="moonshine";$shop=23160;$potLev=90}
 
    }
 
  ("sanc") {$keyword="goose";$shop=50290;$potLev=30}
 
  ("str") {
 
    #SWITCH ($charLev)
 
      ($charLev<40) {$keyword="strike";$shop=31123;$potLev=25}
 
      ($charLev<60) {$keyword="strength";$shop=26321;$potLev=40}
 
      ($charLev<80) {$keyword="prowess";$shop=14141;$potLev=60}
 
      ($charLev<100) {$keyword="noble";$shop=14141;$potLev=80}
 
      ($charLev>=100) {$keyword="handbook";$shop=14141;$potLev=100}
 
    }
 
    
 
#ADDKEY $object keyword $keyword
 
#ADDKEY $object level $potLev
 
#ADDKEY Pot_VARS/currentPotions %1 $object
 
 
#WAL %roomkey($shop)
 
buy $num $keyword
 
 
#SWITCH (%1)
 
  ("hp") {qmn}
 
  ("mn") {qmn}
 
  ("mv") {qmv}
 
   | 
	 
 
 | 
			 
		  | 
	
	
	  | 
		  
		 | 
	
	
		  | 
	
	
		hpoonis2010 Adept
  
  Joined: 18 Jun 2019 Posts: 279
 
  | 
		
		  
			
			   Posted: Mon May 10, 2021 3:55 pm      | 
			 
			
				In the cold light of day, and minus the copious amount of vodka I consumed, I spotted that i left '=' out of a bunch of assignments.
 
 
However, even after correcting this, inside switches are still being ignored.
 
 
I have also tried 
 
 
(eg)
 
	  | Code: | 
	 
	
	  
 
#SWITCH
 
  ("mn") {
 
      #SWITCH ($charlev<20) {<commands>}
 
        ($charLev<40) {<commands>}
 
        etc
 
 | 
	 
 
 | 
			 
		  | 
	
	
	  | 
		  
		 | 
	
	
		  | 
	
	
		shalimar GURU
  
  Joined: 04 Aug 2002 Posts: 4774 Location: Pensacola, FL, USA
  | 
		
		  
			
			   Posted: Mon May 10, 2021 7:43 pm      | 
			 
			
				Nested switches do work:
 
 
$a=1
 
$b=2
 
#SWITCH ($a) (1) {#SWITCH ($b) (2) {#SAY hi}}
 
 
As far as the error in your script... did you try using the syntax checker? it might be able to find it for you.
 
ctrl +k is the shortcut, or you can select it from the editor menu of the settings editor | 
			 
		  | 
	
	
	  
		  
		    
			  _________________ Discord: Shalimarwildcat | 
			       | 
			 
		   
		 | 
	
	
		  | 
	
	
		hpoonis2010 Adept
  
  Joined: 18 Jun 2019 Posts: 279
 
  | 
		
		  
			
			   Posted: Tue May 11, 2021 5:38 am      | 
			 
			
				Syntax check raised no errors.
 
 
Incidentally, a couple of weeks ago I had to also modify this:
 
 
#IF ($charLev<20) {cast 'cure critical';#EXIT}
 
#IF ($charLev>=20)  {cast 'heal'}
 
 
as it would not work written as:
 
 
#IF ($charLev<20) {cast 'cure critical'}  {cast 'heal'}
 
 
I have checked the state of $charLev and it DOES have a value.  I also tried using the permanent version, AND using a set figure (in this case 73) but the inner SWITCHes are just not playing ball despite all variations producing the same figure. | 
			 
		  | 
	
	
	  | 
		  
		 | 
	
	
		  | 
	
	
		hpoonis2010 Adept
  
  Joined: 18 Jun 2019 Posts: 279
 
  | 
		
		  
			
			   Posted: Tue May 11, 2021 10:33 am      | 
			 
			
				I tried using IF instead of the nested switch.  Problem now is that #BREAK or #EXIT will end the entire script, anything else just runs through all the remaining IF, executing each one in turn and thereby changing the potion matching a character level for a higher level potion...which cannot be used.
 
 
It is going to be messy to have to fully quantify every IF
 
 
#IF (($charLev>1) AND ($charLev<20) {}
 
etc
 
 
 
UPDATE: 
 
 
	  | Code: | 
	 
	
	  
 
#SWITCH ($charLev)
 
...
 
  ("mn") {
 
    #IF (($charLev>=1) AND ($charLev<20)) {$keyword="rush";$shop=32476;$potLev=1}
 
    #IF (($charLev>=20) AND ($charLev<40)) {$keyword="lotus";$shop=49497;$potLev=20}
 
    #IF (($charLev>=40) AND ($charLev<60)) {$keyword="penguin";$shop=14696;$potLev=40}
 
    #IF (($charLev>=60) AND ($charLev<80)) {$keyword="raspberry";$shop=52684;$potLev=60}
 
    #IF (($charLev>=80) AND ($charLev<100)) {$keyword="hukomana";$shop=52871;$potLev=80}
 
    #IF (($charLev>=100) AND ($charLev<120)) {$keyword="vodka";$shop=23160;$potLev=100}
 
    #IF (($charLev>=120) AND ($charLev<150)) {$keyword="cupcake";$shop=52684;$potLev=120}
 
    #IF (($charLev>=150) AND ($charLev<175)) {$keyword="vitae";$shop=52143;$potLev=150}
 
    #IF (($charLev>=175) AND ($charLev<200)) {$keyword="phyltre";$shop=45179;$potLev=175}
 
    #IF ($charLev>=200) {$keyword="jack";$shop=23160;$potLev=200}
 
    }
 
... | 
	 
 
 
does not work either. Definitely something screwy going on. | 
			 
		  | 
	
	
	  
		  
		    
			  
  Last edited by hpoonis2010 on Tue May 11, 2021 11:21 am; edited 1 time in total | 
			       | 
			 
		   
		 | 
	
	
		  | 
	
	
		shalimar GURU
  
  Joined: 04 Aug 2002 Posts: 4774 Location: Pensacola, FL, USA
  | 
		
		  
			
			   Posted: Tue May 11, 2021 11:08 am      | 
			 
			
				This might be a situation where a dbVar comes in handy.
 
 
#LOCAL $this
 
$pot=%db(@potions, %1)
 
#FORALL %dbkeys($pot) {#IF (($charLev >= %i) AND ($charLev <= %db(%db($pot, %i), Max)) {$this=%db($pot, %i}}
 
#WALK %roomkey(%db($this, Shop))
 
etc | 
			 
		  | 
	
	
	  
		  
		    
			  _________________ Discord: Shalimarwildcat | 
			       | 
			 
		   
		 | 
	
	
		  | 
	
	
		hpoonis2010 Adept
  
  Joined: 18 Jun 2019 Posts: 279
 
  | 
		
		  
			
			   Posted: Tue May 11, 2021 11:23 am      | 
			 
			
				I tried something similar initially...ran into problems trying to sort out logic for:
 
 
if I already have a batch of potions at a previous level, continue using those
 
 
...and it also started to get a bit logically messy. | 
			 
		  | 
	
	
	  | 
		  
		 | 
	
	
		  | 
	
	
		shalimar GURU
  
  Joined: 04 Aug 2002 Posts: 4774 Location: Pensacola, FL, USA
  | 
		
		  
			
			   Posted: Tue May 11, 2021 11:30 am      | 
			 
			
				It would likely be easier to fix that than the nested switch scenario (especially given that syntactically it should work already.)
  | 
			 
		  | 
	
	
	  
		  
		    
			  _________________ Discord: Shalimarwildcat | 
			       | 
			 
		   
		 | 
	
	
		  | 
	
	
		Tarn GURU
 
  Joined: 10 Oct 2000 Posts: 873 Location: USA
  | 
		
		  
			
			   Posted: Tue May 11, 2021 6:48 pm      | 
			 
			
				This seems like what the database is for.
 
 
You're trying to search for a value by two fields (category like "arm" or "invis" and level).
 
 
Could you make a table with those values and then use %query to get the matching record?
 
 
You might need a min level and max level column for each row to make it easy.
 
 
http://forums.zuggsoft.com/modules/mx_kb/kb.php?page=3&mode=doc&k=2348 | 
			 
		  | 
	
	
	  | 
		  
		 | 
	
	
		  | 
	
	
		hpoonis2010 Adept
  
  Joined: 18 Jun 2019 Posts: 279
 
  | 
		
		  
			
			   Posted: Thu May 13, 2021 2:05 pm      | 
			 
			
				We avoid the databases as that is not a completely useful module.
 
 
Using dbvars also has it's downside in that I am also using the lookups to populate buttons which is best done with proper vars.  Furthermore, I already had a dbvar looking like:
 
 
bls="7="keyword=prayer|shop=32476"|15="keyword=blessing|shop=32172"|25="keyword=special|shop=26275"|57="keyword=embrace|shop=32408""
 
 
but I could NOT make it cough up the proper sub-key pair for love nor money.
 
 
In the end I simplified the entire thing by splitting each potion out to its own var
 
 
eg.,
 
 
blsPotTbl
 
 
1=data
 
10=data
 
35=data
 
 
and just looped around inside it with @{%1PotTbl}.%i.key
 
 
and dropped the data into button-use variables
 
 
So client is currently is happy with
 
 
forall
 
  if
 
 
but not
 
 
switch
 
  switch
 
 
or
 
 
switch
 
  if | 
			 
		  | 
	
	
	  | 
		  
		 | 
	
	
		  | 
	
	
		Tarn GURU
 
  Joined: 10 Oct 2000 Posts: 873 Location: USA
  | 
		
		  
			
			   Posted: Thu May 13, 2021 8:00 pm      | 
			 
			
				
 
	  | hpoonis2010 wrote: | 
	 
	
	  We avoid the databases as that is not a completely useful module.
 
...
 
So client is currently is happy with
 
 
forall
 
  if
 
 
but not
 
 
switch
 
  switch
 
 
or
 
 
switch
 
  if | 
	 
 
 
 
Ok on the db.
 
 
So far as nested switches, I did manage to get this to work:
 
<func name="nested" id="53">
 
  <value>#switch ($cat1=1) { #switch ($cat2 = 1) {#return (1)} ($cat2 = 2) {#return (2)}} {#switch ($cat2 = 1) {#return (3)} ($cat2 = 2) {#return (4)}}</value>
 
  <arglist>$cat1,$cat2</arglist>
 
</func>
 
 
 
#echo %nested(1,1)
 
returns 1 as expected
 
#echo %nested(1,2)
 
returns 2 as expected
 
#echo %nested(2,1)
 
returns 3 as expected
 
#echo %nested(2,2)
 
returns 4 as expected
 
 
But it was extremely fiddly to get right: spacing, and the editor got a bit upset if I split it onto multiple lines. | 
			 
		  | 
	
	
	  | 
		  
		 | 
	
	
		  | 
	
	
		| 
		
		 | 
	
	
		 |