Arrays no longer global

Report any Designer bugs here

Arrays no longer global

Postby amigaoneproductions » Fri Feb 11, 2011 3:28 pm

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

Re: Arrays no longer global

Postby airsoftsoftwair » Sat Feb 12, 2011 1:31 pm

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
User avatar
airsoftsoftwair
 
Posts: 2198
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany

Re: Arrays no longer global

Postby amigaoneproductions » Sat Feb 12, 2011 2:21 pm

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 ;-)
amigaoneproductions
 
Posts: 32
Joined: Mon Feb 15, 2010 5:14 pm
Location: Nottinghamshire, UK


Return to Designer bugs

Who is online

Users browsing this forum: No registered users and 1 guest