|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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.
thank you
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"mysdn" <kam### [at] hotmailcom> wrote:
> is it possible to write
>
> #if (DoorModel == model_101) in an if statement
In POV 3.6, you can achieve this using:
#if (strcmp(DoorModel,model_101)) ...
In POV 3.7, POV-Ray's comparison operator works for strings, too, so you can
also use:
#if (DoorModel = model_101) ...
(Note the single equals sign; POV-Ray does *not* use C/C++ style operators.)
> and in switches
>
> #switch(DoorModel)
>
> #case (model_101)// do that
>
> I want to test for strings, is ttah possible in pov.
No, that's only possible with float values, even in 3.7.
Out of curiosity: Are you sure you want to use strings for the model
identifiers? A numeric id would do, I guess. After all, you can always use
those identifiers you have, like model_101, so you don't have to memorize all
the - possibly cryptic - ids.
If you absolutely need to work with strings for model identifiers, I suggest
translating them to numerical ids first, by looking them up in an array.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"Chris B" <nom### [at] nomailcom> wrote:
> #switch (0)
> #case(strcmp(DoorModel, "model_101"))
> ...
> #break
> #case(strcmp(DoorModel, "model_102"))
> ...
> #break
> #else
> ...
> #end
Ah, now *that's* an interesting idea... thanks, even I still live and learn.
I've always missed an #if ... #elseif construct in POV-Ray, but looks like this
is it.
BTW, in POV-Ray 3.7 it should also work with the comparison operator, i.e.:
#case(DoorModel = "model_101")
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"clipka" <nomail@nomail> wrote in message
news:web.4a604edd6dc58f70a4aed1130@news.povray.org...
> "Chris B" <nom### [at] nomailcom> wrote:
>> #switch (0)
>> #case(strcmp(DoorModel, "model_101"))
>> ...
>> #break
>> #case(strcmp(DoorModel, "model_102"))
>> ...
>> #break
>> #else
>> ...
>> #end
>
> Ah, now *that's* an interesting idea... thanks, even I still live and
> learn.
> I've always missed an #if ... #elseif construct in POV-Ray, but looks like
> this
> is it.
>
> BTW, in POV-Ray 3.7 it should also work with the comparison operator,
> i.e.:
>
> #case(DoorModel = "model_101")
>
Well that's good news. That simplifies the syntax. I'll have to give that a
go. It's worth noting that you'd presumably pass '1' or 'true' into the
#switch statement rather than '0' using this new syntax.
Regards,
Chris B.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
clipka <nomail@nomail> wrote:
> In POV 3.6, you can achieve this using:
> #if (strcmp(DoorModel,model_101)) ...
Actually you have to do it like:
#if(strcmp(DoorModel, model_101) = 0) ...
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"Chris B" <nom### [at] nomailcom> wrote:
> Well that's good news. That simplifies the syntax. I'll have to give that a
> go. It's worth noting that you'd presumably pass '1' or 'true' into the
> #switch statement rather than '0' using this new syntax.
Whoops - yes, of course.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Warp <war### [at] tagpovrayorg> wrote:
> > #if (strcmp(DoorModel,model_101)) ...
>
> Actually you have to do it like:
>
> #if(strcmp(DoorModel, model_101) = 0) ...
Yup. Revoco.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
> 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.
>
> thank you
>
>
If all your identifiers are of the same format as model_xxx, then, you
can extract the numerical part and test that as a numeric value.
Or
You can construct your identifiers from a "model_" string concatenated
to the numerical part.
In both cases, you'd only need to compare numeric variables, whitch is
much simpler.
Alain
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |