PDA

View Full Version : Array chokes on values of 08 and 09??


drexle
08-16-2007, 07:38 PM
Hello,

I'm using AS2 on Flash MX2004 and I've encountered a perplexing problem. I'm making a tile-based game and am using a 2D array to store information about what images the tiles should display when they load. For your perusal is an error message relating to a line of code:


**Error** Scene=Scene 1, layer=a, frame=1:Line 224: ']' or ',' expected
var Arr_cg:Array = [01,10,08,10,01,10,10,10,10,10,10,80];

The problem is in array location [2]. It's when I use the value 08 (and also 09) that I get this problem.

this...

var Arr_cg:Array = [01,10,07,10,01,10,10,10,10,10,10,80];

compiles perfectly, as does anything that isn't 08 or 09 that I have thusfar attempted.



So.... is there something that flash just really hates about the values 08 and 09? Have any of you encountered anything like this before? I just tried it with a brand new empty file and still get the same error when I attempt to assign 08 to an array location. Can this be remedied, or does it require a workaround?

Noct
08-16-2007, 07:48 PM
Well, I've never run into it myself, but if I had to take a guess it would be that since you aren't enclosing these values in quotes it thinks they are either numbers or objects, neither of which can start with a 0.

drexle
08-16-2007, 08:16 PM
Hmm... You do have a point with that, but it simply leads me to the question of "If it does not allow numbers to start with 0, then why does it have no problem doing this with 00 through 07?" It seems to treat them like numbers when I pass them along into other functions, in fact.

I guess if worse came to worst I could just reassign my values and not use the 00 - 09 range at all.

Scuba_Steve
08-16-2007, 08:20 PM
that's friggin weird...

Noct
08-16-2007, 08:33 PM
Oh duh, I musta been sleeping, I wasn't realizing you were saying it would parse fine with 00-07...
But, like I said, I was just taking a guess anyways...

Upon further exploration:
jbum@FlashKit explains:
In most C-like languages (including more recent versions of actionscript), when you put leading zeros in front of a number, it is assumed to be in Octal (a number base which uses the digits 0-7).

The equivalent of 8 in octal is "010".

"08" is an illegal octal number, thus the error. And yes, Flash is doing a crappy job of telling you what's wrong with the code.

To avoid the error, leave off the leading zeros.

* * *

In my opinion, Octal is a historical holdover that should be removed from modern languages. I pretty much stick to decimal or hexadecimal in all my code. For example, you used to encode arbitrary ASCII characters in strings using "\OOO" in which OOO is a 3-digit octal number, but these days you can almost always use the easier-to-read "\xHH" in which HH is hexadecimal. Then again, I'll probably be *****ing and moaning about ASCII in 10 years time...

drexle
08-16-2007, 08:52 PM
Awesome find on the answer! Thanks for your assistance. :)

I think it is safe for me to just go ahead and drop the 00-09 list of tiles. I have been considering bumping it up to three digits regardless. ;)

Noct
08-16-2007, 09:38 PM
NP, it was an interesting question, thats for sure...
I actually found a couple of people calling it a bug until I stumbled on a Flash kit thread explaning the Octal issue.