In the example script below, the first four lines just create a window with a star in it - no problem. Next however, I want to create a user-defined function ("fn_Star") to enable me to introduce parameters that will (a) modify the look of the star and (b) allow me to call it multiple times. However, when I try to do that as shown in the second part of the script, the Graph Box I create within the function doesn't recognize the variables I define earlier within that same function (the error in the log tells me that Chart2 doesn't know what X2 is).
// First part;
X1 = [0, .1, 1, .1, 0, -.1, -1, -.1];
Y1 = [1, .1, 0, -.1, -1, -.1, 0, .1];
Chart1 = GraphBox(FrameSize(300, 300), XScale(-1, 1), YScale(-1, 1), Fill Color( "green" ); Polygon( X1, Y1 ));
new window("Window1", Chart1);
// Second part;
fn_Star = function({}, {default local},
X2 = [0, .1, 1, .1, 0, -.1, -1, -.1];
Y2 = [1, .1, 0, -.1, -1, -.1, 0, .1];
Chart2 = GraphBox(FrameSize(300, 300), XScale(-1, 1), YScale(-1, 1), Fill Color( "green" ); Polygon( X2, Y2 ));
new window("Window2", Chart2);
);
fn_Star;
// End of script;
Why is this please? And what is the easiest way I can modify the function definition to make it do what I want?
Many thanks.