POV-Ray : Newsgroups : povray.newusers : conditional statements : Re: conditional statements Server Time
6 Oct 2024 02:02:05 EDT (-0400)
  Re: conditional statements  
From: Chris B
Date: 17 Jul 2009 05:17:40
Message: <4a6041b4$1@news.povray.org>
"mysdn" <kam### [at] hotmailcom> wrote in message 
news:web.4a603abbcc998528ff025eb50@news.povray.org...
> Hi,
>
> is it possible to write
>
> #if (DoorModel == model_101)   in an if statement
>
> and  in switches
>
>
>  #switch(DoorModel)
>
>           #case (model_101)// do that
>
> I want to test for strings, is ttah possible in pov.
>

Yes.
You can test strings in both #if and #case statements, although the syntax 
is a little contrived in #case statements.

You can use the 'strcmp' function in #if statements which compares two 
strings and returns zero if the two strings are identical. So:

  #if (strcmp(DoorModel, "model_101")=0)

compares a string contained in the variable DoorModel with the literal 
scting value "model_101".


In the #case statement the value in the #switch has to be numeric, so you 
have to construct something like:

#switch (0)
  #case(strcmp(DoorModel, "model_101"))
    ...
  #break
  #case(strcmp(DoorModel, "model_102"))
    ...
  #break
  #else
    ...
#end

I also often use the 'strlwr' function to desensitize such string 
comparisons to upper and lower case.
BTW. You can also use the 'substr' and 'strlen' functions to make it accept 
abbreviations of strings during a comparison.
But this can end up with quite long expressions in the #case statement.


Regards,
Chris B.


Post a reply to this message

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