Arrays no longer global

Report any Designer bugs here
Post Reply
amigaoneproductions
Posts: 32
Joined: Mon Feb 15, 2010 4:14 pm
Location: Nottinghamshire, UK
Contact:

Arrays no longer global

Post by amigaoneproductions »

In Designer 2, if I set up an array in the Page Code eg.

Code: Select all

dim apple[10]
apple[1]=1
apple[2]=2
fred="Hello"
debugprint(apple[1])
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

debugprint(fred)
debugprint(apple[1])
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
User avatar
airsoftsoftwair
Posts: 5425
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Arrays no longer global

Post 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
amigaoneproductions
Posts: 32
Joined: Mon Feb 15, 2010 4:14 pm
Location: Nottinghamshire, UK
Contact:

Re: Arrays no longer global

Post 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 ;-)
Post Reply