POV-Ray : Newsgroups : povray.advanced-users : Using arrays in functions : Using arrays in functions Server Time
28 Sep 2024 06:14:23 EDT (-0400)
  Using arrays in functions  
From: Trevor G Quayle
Date: 16 Mar 2011 12:10:01
Message: <web.4d80e040f18413e381c811d20@news.povray.org>
I want to use an array inside a function, for example:

function(x,y,z){MYARRAY[][]}

I can hard code an array index, and it is fine:

eg.  function(x,y,z){MYARRAY[2][3]}

, however I can't create an array index from a function.  I get an error "Float
expected but vector or color expression found"

e.g. function(x,y,z){MYARRAY[max(min(int(x),9),0)][max(min(int(y),9),0)]}

parsing the function inside the array indices we return valid integer indices,
but it appears that POV is not parsing it this way: rather than precalculating
the function using the "x" and "y" values from the function, it is seeing them
as x and y vectors (<1,0,0>, <0,1,0>) which gives the error.  Changing to a
different reference from x,y,z eg.

e.g. function(xx,yy,zz){MYARRAY[max(min(int(xx),9),0)][max(min(int(yy),9),0)]}

results in an undeclared indetifier 'xx' error.

I there some way I can work around this and force the function inside to be
calculated into my index value before the array tries to parse it?

-tgq


Post a reply to this message

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