POV-Ray : Newsgroups : povray.advanced-users : Undefined variables Server Time
23 Nov 2024 10:21:16 EST (-0500)
  Undefined variables (Message 1 to 6 of 6)  
From: Mike Horvath
Subject: Undefined variables
Date: 5 Feb 2018 17:46:55
Message: <5a78dedf$1@news.povray.org>
I am trying to create a macro:

   #macro BlurredReflection(InPigment, InFinish, InNormal)
     ...
   #end

But I don't want to *always* pass a value to the macro. Is there a way 
to pass a "null" or "nil" value to the macro, and then check for it 
using a conditional statement?

Thanks.

Mike


Post a reply to this message

From: Alain
Subject: Re: Undefined variables
Date: 5 Feb 2018 17:58:31
Message: <5a78e197$1@news.povray.org>
Le 18-02-05 à 17:47, Mike Horvath a écrit :
> I am trying to create a macro:
> 
>    #macro BlurredReflection(InPigment, InFinish, InNormal)
>      ...
>    #end
> 
> But I don't want to *always* pass a value to the macro. Is there a way 
> to pass a "null" or "nil" value to the macro, and then check for it 
> using a conditional statement?
> 
> Thanks.
> 
> Mike

Not any that I'm aware of.
What you can do is define the macro with only a single, or no, parameter 
and use some global variable and #if statements to assign defaut values 
it any variable is not already defined.


Post a reply to this message

From: Bald Eagle
Subject: Re: Undefined variables
Date: 5 Feb 2018 18:10:00
Message: <web.5a78e3f58fda426b5cafe28e0@news.povray.org>
Mike Horvath <mik### [at] gmailcom> wrote:

> But I don't want to *always* pass a value to the macro. Is there a way
> to pass a "null" or "nil" value to the macro, and then check for it
> using a conditional statement?

I know what you mean.
I just came up with this idea 5 sec ago:

What if you "always" pass a vector to the macro - one that is reset to default
"null" values, and then you can re-#declare the vector before  calling the macro
with the vector as an argument.

That way the vector need not always have the same number of components, but it's
always ONE vector.


Post a reply to this message

From: dick balaska
Subject: Re: Undefined variables
Date: 5 Feb 2018 20:46:40
Message: <5a790900$1@news.povray.org>
On 02/05/2018 05:47 PM, Mike Horvath wrote:
> I am trying to create a macro:
> 
>    #macro BlurredReflection(InPigment, InFinish, InNormal)
>      ...
>    #end
> 
> But I don't want to *always* pass a value to the macro. Is there a way 
> to pass a "null" or "nil" value to the macro, and then check for it 
> using a conditional statement?
> 
> Thanks.
> 
> Mike

There are optional parameters, which may help you out.
http://news.povray.org/povray.beta-test/thread/%3Cweb.58d3f1da55c5eb5fc437ac910%40news.povray.org%3E/

I had a similar need, but I ended up not using optionals, because the 
caller still needs to be aware of the missing parameters via comma 
count; i.e. BlurredReflection(Red,,)

I ended up just creating a mostly duplicate, different named macro with 
the optional parameter.
#macro BlurredReflection(InPigment, Infinish) #end
#macro BlurredReflectionWithNormal(InPigment, InFinish, InNormal) #end

-- 
dik
Rendered 920576 of 921600 pixels (99%)


Post a reply to this message

From: clipka
Subject: Re: Undefined variables
Date: 6 Feb 2018 08:10:18
Message: <5a79a93a$1@news.povray.org>
Am 05.02.2018 um 23:47 schrieb Mike Horvath:
> I am trying to create a macro:
> 
>   #macro BlurredReflection(InPigment, InFinish, InNormal)
>     ...
>   #end
> 
> But I don't want to *always* pass a value to the macro. Is there a way
> to pass a "null" or "nil" value to the macro, and then check for it
> using a conditional statement?

In the new versions, you can use e.g.

    #macro Fnord(A, optional B, C)
      #ifdef(local.B)
        #debug "Got a value for B.\n"
      #else
        #debug "B was left empty.\n"
      #endif
    #end

    Fnord(A,,C)


Post a reply to this message

From: Mike Horvath
Subject: Re: Undefined variables
Date: 6 Feb 2018 08:16:54
Message: <5a79aac6$1@news.povray.org>
On 2/6/2018 8:10 AM, clipka wrote:
> Am 05.02.2018 um 23:47 schrieb Mike Horvath:
>> I am trying to create a macro:
>>
>>    #macro BlurredReflection(InPigment, InFinish, InNormal)
>>      ...
>>    #end
>>
>> But I don't want to *always* pass a value to the macro. Is there a way
>> to pass a "null" or "nil" value to the macro, and then check for it
>> using a conditional statement?
> 
> In the new versions, you can use e.g.
> 
>      #macro Fnord(A, optional B, C)
>        #ifdef(local.B)
>          #debug "Got a value for B.\n"
>        #else
>          #debug "B was left empty.\n"
>        #endif
>      #end
> 
>      Fnord(A,,C)
> 

Interesting, thanks.


Mike


Post a reply to this message

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