POV-Ray : Newsgroups : povray.beta-test : Error in insert menu: #switch example : Error in insert menu: #switch example Server Time
5 Nov 2024 01:22:17 EST (-0500)
  Error in insert menu: #switch example  
From: Tor Olav Kristensen
Date: 10 Sep 2001 18:58:30
Message: <3B9D4556.3B893291@hotmail.com>
This is what one get when one choose the 
Insert->Misc. Directives->switch example
menu item:

// Let's make some constant names
#declare CS_Easy   = 1
#declare CS_Medium = 3
#declare CS_Hard   = 5

// Let the user choose the method to use
#declare Complexity_Switch = CS_Medium // or CS_Easy or CS_Hard

// Do something dependent on the user's choice
#switch (Complexity_Switch)
  #case (CS_Easy)
  // This statement is done if (Complexity_Switch = CS_Easy)
  #declare MyShape = box{-1,+1}
  #break // end of CS_Easy
  #case (CS_Medium, CS_Hard)
  // This statement is done if Complexity_Switch is CS_Medium
  // or CS_Hard or anything in between
  #declare MyShape = torus{1, 0.5}
  #break // end of CS_Hard
  #else
  // This statement is done if none of the above match
  #declare MyShape = sphere{0,1}
#end

The code above contains several errors:

Semicolons should be added after 4 of the
declarations.

And in this line:

#case (CS_Medium, CS_Hard)

case is used instead of range.


This line has a wrong comment:

#break // end of CS_Hard


Some indentation would also make it all clearer.
And a little whitespace makes it easier to read !

Below is my suggestion for this menu item.

Tor Olav


// Let's make some constant names
#declare CS_Medium = 1;
#declare CS_Hard = 3;
#declare CS_Easy = 5;

// Let the user choose the method to use
#declare Complexity_Switch = CS_Medium; // or CS_Easy or CS_Hard

// Do something dependent on the user's choice
#switch (Complexity_Switch)

  #case (CS_Easy)
    // This statement is done if Complexity_Switch is CS_Easy
    #declare MyShape = box { -<1, 1, 1>, <1, 1, 1> }
  #break // End of this case section

  #range (CS_Medium, CS_Hard)
    // This statement is done if Complexity_Switch is CS_Medium
    // or CS_Hard or anything in between
    #declare MyShape = torus { 1, 0.5 }
  #break // End of this range section

  #else
    // This statement is done if none of the above match
    #declare MyShape = sphere { <0, 0, 0>, 1 }

#end // End of switch statement


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.