discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

aren't global arrays possible?

JJ
Johan Jonker
Sat, Jan 30, 2016 8:44 PM

It get an error on this attempt to use a global array.
Is it not possible to use a global array in a function?
Is there another way to use the interpolation in a function?

/A_table = [
[ 0, 0.01h_tip],
[0.1, 0.12
h_tip],
[0.2, 0.24h_tip],
[0.3, 0.28
h_tip],
[0.4, 0.32h_tip],
[0.5, 0.4
h_tip],
[0.6, 0.45h_tip],
[0.7, 0.52
h_tip],
[0.8, 0.64h_tip],
[0.9, 0.77
h_tip],
[1,1*h_tip]
];
B_table = nSpline(A_table,1000);

function tip(procent) =
B_table[round(procent*10)][1]*h_tip;/

--
View this message in context: http://forum.openscad.org/aren-t-global-arrays-possible-tp15984.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

It get an error on this attempt to use a global array. Is it not possible to use a global array in a function? Is there another way to use the interpolation in a function? /A_table = [ [ 0, 0.01*h_tip], [0.1, 0.12*h_tip], [0.2, 0.24*h_tip], [0.3, 0.28*h_tip], [0.4, 0.32*h_tip], [0.5, 0.4*h_tip], [0.6, 0.45*h_tip], [0.7, 0.52*h_tip], [0.8, 0.64*h_tip], [0.9, 0.77*h_tip], [1,1*h_tip] ]; B_table = nSpline(A_table,1000); function tip(procent) = B_table[round(procent*10)][1]*h_tip;/ -- View this message in context: http://forum.openscad.org/aren-t-global-arrays-possible-tp15984.html Sent from the OpenSCAD mailing list archive at Nabble.com.
M
MichaelAtOz
Sat, Jan 30, 2016 8:58 PM

Should work, what error message? (I have not looked at nSpline)


Newly minted Admin - PM me if you need anything, or if I've done something stupid...

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.

The TPP is no simple “trade agreement.”  Fight it! http://www.ourfairdeal.org/  time is running out!

View this message in context: http://forum.openscad.org/aren-t-global-arrays-possible-tp15984p15985.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Should work, what error message? (I have not looked at nSpline) ----- Newly minted Admin - PM me if you need anything, or if I've done something stupid... Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above. The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out! -- View this message in context: http://forum.openscad.org/aren-t-global-arrays-possible-tp15984p15985.html Sent from the OpenSCAD mailing list archive at Nabble.com.
JJ
Johan Jonker
Sat, Jan 30, 2016 9:47 PM

unknown variable

--
View this message in context: http://forum.openscad.org/aren-t-global-arrays-possible-tp15984p15986.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

unknown variable -- View this message in context: http://forum.openscad.org/aren-t-global-arrays-possible-tp15984p15986.html Sent from the OpenSCAD mailing list archive at Nabble.com.
CA
Carsten Arnholm
Sat, Jan 30, 2016 10:17 PM

On 30. jan. 2016 22:47, Johan Jonker wrote:

unknown variable

From your script it is quite clear the unknown variable is 'h_tip', it
isn't defined, but used.

Also the function nSpline is undefined as written.

Carsten Arnholm

On 30. jan. 2016 22:47, Johan Jonker wrote: > unknown variable From your script it is quite clear the unknown variable is 'h_tip', it isn't defined, but used. Also the function nSpline is undefined as written. Carsten Arnholm
M
MichaelAtOz
Sat, Jan 30, 2016 10:27 PM

This works for me

use <splines.scad>
h_tip=1;
A_table = [
[ 0, 0.01h_tip],
[0.1, 0.12
h_tip],
[0.2, 0.24h_tip],
[0.3, 0.28
h_tip],
[0.4, 0.32h_tip],
[0.5, 0.4
h_tip],
[0.6, 0.45h_tip],
[0.7, 0.52
h_tip],
[0.8, 0.64h_tip],
[0.9, 0.77
h_tip],
[1,1h_tip]
];
echo(A_table=A_table);
B_table = nSpline(A_table,1000);
echo(B_table=B_table);
function tip(procent) =
B_table[round(procent
10)][1]*h_tip;

I suspect a typo in your code?


Newly minted Admin - PM me if you need anything, or if I've done something stupid...

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.

The TPP is no simple “trade agreement.”  Fight it! http://www.ourfairdeal.org/  time is running out!

View this message in context: http://forum.openscad.org/aren-t-global-arrays-possible-tp15984p15988.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

This works for me use <splines.scad> h_tip=1; A_table = [ [ 0, 0.01*h_tip], [0.1, 0.12*h_tip], [0.2, 0.24*h_tip], [0.3, 0.28*h_tip], [0.4, 0.32*h_tip], [0.5, 0.4*h_tip], [0.6, 0.45*h_tip], [0.7, 0.52*h_tip], [0.8, 0.64*h_tip], [0.9, 0.77*h_tip], [1,1*h_tip] ]; echo(A_table=A_table); B_table = nSpline(A_table,1000); echo(B_table=B_table); function tip(procent) = B_table[round(procent*10)][1]*h_tip; I suspect a typo in your code? ----- Newly minted Admin - PM me if you need anything, or if I've done something stupid... Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above. The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out! -- View this message in context: http://forum.openscad.org/aren-t-global-arrays-possible-tp15984p15988.html Sent from the OpenSCAD mailing list archive at Nabble.com.
JJ
Johan Jonker
Sun, Jan 31, 2016 12:47 PM

Strange, when I paste your codes in an empty file, there is not problem.
When I paste the code on the top of file with modules and functions it
reports errors:

/Saved backup file: C:/Users/Eigenaar/Documents/OpenSCAD/backups/mouthpiece
outside v12-backup-gqHp6640.scad
Compiling design (CSG Tree generation)...
WARNING: Ignoring unknown variable 'B_table'.
WARNING: Ignoring unknown variable 'B_table'.
ECHO: "lchamber", 39, 45.7074, 2.4, 45.7666, 15.6531
ECHO: "chamber", 6.00436, 6.10407, 2.9133, 5.76755, 17.0867, 15.6531,
6.17938/

But it computes the tables and echoes them as expected.

--
View this message in context: http://forum.openscad.org/aren-t-global-arrays-possible-tp15984p15989.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Strange, when I paste your codes in an empty file, there is not problem. When I paste the code on the top of file with modules and functions it reports errors: /Saved backup file: C:/Users/Eigenaar/Documents/OpenSCAD/backups/mouthpiece outside v12-backup-gqHp6640.scad Compiling design (CSG Tree generation)... WARNING: Ignoring unknown variable 'B_table'. WARNING: Ignoring unknown variable 'B_table'. ECHO: "lchamber", 39, 45.7074, 2.4, 45.7666, 15.6531 ECHO: "chamber", 6.00436, 6.10407, 2.9133, 5.76755, 17.0867, 15.6531, 6.17938/ But it computes the tables and echoes them as expected. -- View this message in context: http://forum.openscad.org/aren-t-global-arrays-possible-tp15984p15989.html Sent from the OpenSCAD mailing list archive at Nabble.com.
R
runsun
Sun, Jan 31, 2016 4:58 PM

Johan Jonker wrote

Strange, when I paste your codes in an empty file, there is no problem.
When I paste the code on the top of file with modules and functions it
reports errors:

This is one thing about OpenScad that troubles users in debugging. See the
following and refer to my  earlier post
http://forum.openscad.org/Ignoring-unknown-variable-issue-tp13156p13321.html
for more detailed explanation:

runsun wrote

whenever you see :

WARNING: Ignoring unknown variable X 

It could be one of the following two conditions :

  1. A=X but X is not defined in any place prior to that line,
    means the issue is on X;

  2. A=X but A is already defined prior to that line, before
    X is defined.

In case 1), the issue is on X, but in 2), A is the problem.

So besides checking if X is pre-defined, remember to also
check if A is pre-defined.


$  Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), runscad.py( 1 , 2 , git ), synwrite( 1 , 2 );  $ tips: hash( 1 , 2 ), sweep , var( 1 , 2 ), lerp , animGif , prodVid , precision( 1 , 2 ), xl-control

--
View this message in context: http://forum.openscad.org/aren-t-global-arrays-possible-tp15984p15994.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Johan Jonker wrote > Strange, when I paste your codes in an empty file, there is no problem. > When I paste the code on the top of file with modules and functions it > reports errors: This is one thing about OpenScad that troubles users in debugging. See the following and refer to my earlier post <http://forum.openscad.org/Ignoring-unknown-variable-issue-tp13156p13321.html> for more detailed explanation: runsun wrote > whenever you see : > > WARNING: Ignoring unknown variable X > > It could be one of the following two conditions : > > 1) A=X but X is not defined in any place prior to that line, > means the issue is on X; > > 2) A=X but A is already defined prior to that line, before > X is defined. > > In case 1), the issue is on X, but in 2), A is the problem. > > So besides checking if X is pre-defined, remember to also > check if A is pre-defined. ----- $ Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), runscad.py( 1 , 2 , git ), synwrite( 1 , 2 ); $ tips: hash( 1 , 2 ), sweep , var( 1 , 2 ), lerp , animGif , prodVid , precision( 1 , 2 ), xl-control -- View this message in context: http://forum.openscad.org/aren-t-global-arrays-possible-tp15984p15994.html Sent from the OpenSCAD mailing list archive at Nabble.com.