Page 1 of 1

Arrays no longer global

Posted: Fri Feb 11, 2011 2:28 pm
by amigaoneproductions
In Designer 2, if I set up an array in the Page Code eg.

Code: Select all

dim apple[10]
If I then tried to access this variable inside the On Mouse Key Click of an object, i.e. a box on screen. it would work perfectly eg.

Code: Select all

When the program is run, it outputs "1", and then "hello" and "2" when I click on the button.

In Designer 3, exactly the same program fails as the On Mouse Key Click code no longer knows about the dimmed variable, but it knows the string called fred

When run, it outsputs the "1" as the page loads, then clicking the button prints "hello", the contents of string "fred", then fails with:
Table apple{} not found!
file:test.hws(current line: 53 - in function: func)

In lots of my programs I initialise the vars in the page load that will be needed thoughout the program, now all those programs fail when run under Designer 3

Re: Arrays no longer global

Posted: Sat Feb 12, 2011 12:31 pm
by airsoftsoftwair
This is not a bug, but a feature of Designer's new optimized script system which tries to save memory by using as many local variables as possible.

You can work-around this by manually creating the table without using Dim(). I.e. try the following instead of the Dim:

Code: Select all

apple = {}
If you need to initialize all table fields to zero, you have to add the following:

Code: Select all

Local tablesize = 10
For Local k = 0 To tablesize - 1 Do apple[k] = 0

Re: Arrays no longer global

Posted: Sat Feb 12, 2011 1:21 pm
by amigaoneproductions
Thanks, that seems to work :-)

Now on to the next reason my program is failing, I'm getting a

Function p_hidelayer() not found! error, I'll see if I can see what is going on.

Seems this update is going to break quite a ffew of my older programs ;-)