POV-Ray : Newsgroups : povray.newusers : Problem with #switch Server Time
24 Nov 2024 15:33:24 EST (-0500)
  Problem with #switch (Message 1 to 7 of 7)  
From: Archpawn
Subject: Problem with #switch
Date: 11 Feb 2008 18:50:01
Message: <web.47b0ded4bd25e05c9c37dbc40@news.povray.org>
When I try to compile the following code, it says there should be a ) after X+1.
Am I doing this right? It's supposed to return X+1 if Dir = 0 or 1, X if it's 2
or 5, and X-1 if it's 3 or 4.
#macro NextX(X,Dir)
   #switch(Dir)
      #case(0)
      #case(1)
         X+1
      #break
      #case(2)
         X
      #break
      #case(3)
      #case(4)
         X-1
      #break
      #case(5)
         X
      #break
   #end
#end


Post a reply to this message

From: Mike the Elder
Subject: Re: Problem with #switch
Date: 11 Feb 2008 19:05:01
Message: <web.47b0e2672c0eb44373e406e60@news.povray.org>
"Archpawn" <nomail@nomail> wrote:
> When I try to compile the following code, it says there should be a ) after X+1.
> Am I doing this right? It's supposed to return X+1 if Dir = 0 or 1, X if it's 2
> or 5, and X-1 if it's 3 or 4.
> #macro NextX(X,Dir)
>    #switch(Dir)
>       #case(0)
>       #case(1)
>          X+1
>       #break
>       #case(2)
>          X
>       #break
>       #case(3)
>       #case(4)
>          X-1
>       #break
>       #case(5)
>          X
>       #break
>    #end
> #end

I think you need to specify where the returned value is to be stored:

#macro NextX(X,Dir)

   #switch(Dir)
      #case(0)
      #case(1)
         #declare RetXVal = X+1;
      #break
      #case(2)
         #declare RetXVal = X;
      #break
      #case(3)
      #case(4)
         #declare RetXVal = X-1;
      #break
      #case(5)
         #declare RetXVal = X;
      #break
   #end
#end


Post a reply to this message

From: Tim Attwood
Subject: Re: Problem with #switch
Date: 11 Feb 2008 19:48:05
Message: <47b0ecc5$1@news.povray.org>
> When I try to compile the following code, it says there should be a ) 
> after X+1.
> Am I doing this right? It's supposed to return X+1 if Dir = 0 or 1, X if 
> it's 2
> or 5, and X-1 if it's 3 or 4.

#macro NextX(X,Dir)
   #switch(Dir)
      #range(0,1)
         #local result = X+1;
      #break
      #case(2)
         #local result = X;
      #break
      #range(3,4)
         #local result = X-1;
      #break
      #case(5)
         #local result = X;
      #break
   #end
   (result)
#end


Post a reply to this message

From: Tim Attwood
Subject: Re: Problem with #switch
Date: 11 Feb 2008 19:53:07
Message: <47b0edf3@news.povray.org>
Oh, and #case doesn't need to be in order...

#macro NextX(X,Dir)
   #switch(Dir)
      #range(0,1)
         #local result = X+1;
      #break
      #range(3,4)
         #local result = X-1;
      #break
      #case(2)
      #case(5)
         #local result = X;
      #break
   #end
   (result)
#end


Post a reply to this message

From: Archpawn
Subject: Re: Problem with #switch
Date: 11 Feb 2008 19:55:01
Message: <web.47b0ee232c0eb4439c37dbc40@news.povray.org>
"Mike the Elder" <nomail@nomail> wrote:
> I think you need to specify where the returned value is to be stored:
> ...
On http://www.povray.org/documentation/view/3.6.1/243/ , it gives the example
#macro Interpolate(T,T1,T2,P1,P2)
   (P1+(T1+T/(T2-T1))*(P2-P1))
#end
Which essentially replaces Interpolate(T,T1,T2,P1,P2) with
(P1+(T1+T/(T2-T1))*(P2-P1)).


Post a reply to this message

From: Chris B
Subject: Re: Problem with #switch
Date: 12 Feb 2008 03:28:46
Message: <47b158be@news.povray.org>
"Archpawn" <nomail@nomail> wrote in message 
news:web.47b0ded4bd25e05c9c37dbc40@news.povray.org...
> When I try to compile the following code, it says there should be a ) 
> after X+1.
> Am I doing this right? It's supposed to return X+1 if Dir = 0 or 1, X if 
> it's 2
> or 5, and X-1 if it's 3 or 4.
> #macro NextX(X,Dir)
>   #switch(Dir)
>      #case(0)
>      #case(1)
>         X+1
>      #break
> ... snip ...

I cut and pasted your macro into a new empty file and added the one line
#debug concat("AAAAA: ",str(NextX(1,0),3,0),"\n")

I ran it with a couple of different parameters and it worked as expected 
(Black image, but a number returned to the message stream).

Are you sure you don't have an error in the main body of your code?
If you've got an open bracket out of place before any of the macro 
invocations, then that would explain the message.

Regards,
Chris B.


Post a reply to this message

From: Warp
Subject: Re: Problem with #switch
Date: 12 Feb 2008 11:27:06
Message: <47b1c8da@news.povray.org>
Mike the Elder <nomail@nomail> wrote:
> #macro NextX(X,Dir)
>    #switch(Dir)
>       #case(0)
>       #case(1)
>          #declare RetXVal = X+1;
>       #break
>       #case(2)
>          #declare RetXVal = X;
>       #break
>       #case(3)
>       #case(4)
>          #declare RetXVal = X-1;
>       #break
>       #case(5)
>          #declare RetXVal = X;
>       #break
>    #end
> #end

  No, not like that. Use #local and put the identifier name at the end
of the macro.

-- 
                                                          - Warp


Post a reply to this message

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