Array of type handles
BlitzMax Forums/BlitzMax Beginners Area/Array of type handles I'm getting this error when I compile the code:
BlitzMax Application
Compile Error
Syntax error in user defined type declaration
[OK]
and places the cursor on this line:
BlitzMax Application
Compile Error
Syntax error in user defined type declaration
[OK]
and places the cursor on this line:
Field ver[9]:vertex
Global entities=0 Type Entity Global list:tlist=CreateList() Field id Field vertex_count Method Scale(x#,y#,z#) 'find center (average xyz of the vertecies) Local avgx#=0,avgy#=0,avgz#=0 For scal=1 To vertex_count avgx:+ver[scal].x avgy:+ver[scal].y avgz:+ver[scal].z Next avgx:/vertex_count avgy:/vertex_count avgz:/vertex_count 'scale it For scal=1 To vertex_count ver[scal].x=((ver[scal].x-avgx)*x)+avgx ver[scal].y=((ver[scal].x-avgy)*y)+avgy ver[scal].z=((ver[scal].x-avgz)*z)+avgz Next End Method End Type Type Cube Extends Entity Field ver[9]:vertex Field trig[13]:tri Function Create:Cube(x#,y#,z#) Local s=1,sx=0,sy=0,sz=0 c:Cube=New Cube ver[1]=vertex.Create(s+sx,s+sy,s+sz) ver[2]=vertex.Create(s+sx,-s+sy,s+sz) ver[3]=vertex.Create(-s+sx,s+sy,s+sz) ver[4]=vertex.Create(-s+sx,-s+sy,s+sz) ver[5]=vertex.Create(s+sx,s+sy,-s+sz) ver[6]=vertex.Create(s+sx,-s+sy,-s+sz) ver[7]=vertex.Create(-s+sx,s+sy,-s+sz) ver[8]=vertex.Create(-s+sx,-s+sy,-s+sz) trig[1]=tri.Create(ver[4],ver[3],ver[2]) trig[2]=tri.Create(ver[1],ver[3],ver[2]) trig[3]=tri.Create(ver[6],ver[7],ver[8]) trig[4]=tri.Create(ver[7],ver[6],ver[5]) trig[5]=tri.Create(ver[4],ver[8],ver[7]) trig[6]=tri.Create(ver[4],ver[3],ver[7]) trig[7]=tri.Create(ver[5],ver[6],ver[2]) trig[8]=tri.Create(ver[5],ver[1],ver[2]) trig[9]=tri.Create(ver[5],ver[3],ver[1]) trig[10]=tri.Create(ver[7],ver[3],ver[5]) trig[11]=tri.Create(ver[8],ver[6],ver[2]) trig[12]=tri.Create(ver[4],ver[8],ver[2]) c.vertex_count=8 entities:+1;c.id=entities Return c:Cube End Function End Type
Alright, saw brucey's post and fixed that.
Now I get this error:
Compile Error
Expression of type 'Int' cannot be indexed
on this line:
Now I get this error:
Compile Error
Expression of type 'Int' cannot be indexed
on this line:
avgx:+ver[scal].x
That means your reference to 'ver' has not been defined as an array. Its still default (Int).
Offtopic: Sorry for the rude offtopic, but I really need a guru to look at my "Noob Tlist" thread. I'm at a total stand still with that. Thanks.
Gfk, how do I fix that?
Offtopic: Sorry for the rude offtopic, but I really need a guru to look at my "Noob Tlist" thread. I'm at a total stand still with that. Thanks.
For being so rude, I'm not going to look.I *think* you might need to use 'super' fix it. Not 100% because I don't use extended types that much.
avgx:+super.ver[scal].x
You should think about using SuperStrict. It forces you to define all your variable types.
It helps to get rid of certain kinds of bugs.
It helps to get rid of certain kinds of bugs.
Brucey said a mouthful. Although I'm just using Strict, at the moment.
I used to use Blitz3D and when I moved to Blitzmax I was strongly against Strict/Superstrict. However, if you start a project and type Strict before anything else, its guaranteed to save you hours of stress later. Makes the debugging process much easier.
I used to use Blitz3D and when I moved to Blitzmax I was strongly against Strict/Superstrict. However, if you start a project and type Strict before anything else, its guaranteed to save you hours of stress later. Makes the debugging process much easier.
I always thought of Strict/SuperStrict as annoyances, but it helps a lot. Thanks.
Yes, use SuperStrict. Your problem is that ver is a field of the Cube type, though, so it should be...
...and so on. You have to say which object's fields you are talking about in class functions (as it's only implicit in methods).
c.ver[1]=vertex.Create(s+sx,s+sy,s+sz)
...and so on. You have to say which object's fields you are talking about in class functions (as it's only implicit in methods).
I'm still using Strict, it saves loads of time chasing dumb bugs. I forget why superstrict is supposed to be so good (I know you have to declare ints as you can't leave a variable with no type anymore), but anything else?
And using Strict or SuperStrict results in faster compiled code. Another reason to use on or the other.
And using Strict or SuperStrict results in faster compiled code
Really? How's that? As it knows precisely what variables are what and what scope they are in, it can make a number of optimisations that otherwise the compiler could not do, as it always couldn't be sure that a new, undeclared variable might just appear out of the blue.
As far as I know Strict and SuperStrict both compile to the same code, it's just a matter of having to declare ints as such or not. But if everything apart from int has to be declared, the compiler can know without a doubt what's meant to be an int.
As far as I know Strict and SuperStrict both compile to the same code, it's just a matter of having to declare ints as such or not. But if everything apart from int has to be declared, the compiler can know without a doubt what's meant to be an int.