Mysterious type syntax error

BlitzMax Forums/BlitzMax Programming/Mysterious type syntax error

Pineapple(Posted 2009) [#1]
I need help on how to fix this.


my code line being highlighted:

	Field attatch:obj[8],apos%[8,4],anum%=0,atype%[8]=0,astr#[8]=10 'valid joint types would be weld and axis 


I get the error 'Compile Error Syntax error in user defined type declaration'

the rest of the type code (excluding methods)

Type obj
	Global GRAVITY=0.95,GIBVELOCITY=0.1
	Global list:TList=CreateList()
	Field img:objimage 'image to draw
	Field x#,y#,ang# 'position & orientation
	Field vel#,dir# 'velocity vector
	Field angvel# 'angular velocity - how fast it's spinning
	Field mass#=10 'determines transfer of force factors when colliding with other objects
	Field friction#=0.015 'determines how rapidly velocities decrease
	Field bounce#=0.5 'bounciness factor
	Field health#=100 'remaining hits until gib or destroy
	'handle of objects attached, pos on poth objs of attachment, number of attachments tied to obj, type of joint, str of joint
	Field attatch:obj[8],apos%[8,4],anum%=0,atype%[8]=0,astr#[8]=10 'valid joint types would be weld and axis 
	'(also technical attachments which would only prevent collision)
	Field needsgib:Byte=False 'means that if the velocity is reduced to a low number, object is gibbed
	'parentkind=0 means that the object is not parented to a bot or gun
	Field parentkind:Byte=0,botparent:bot,gunparent:gun,shotparent:shot,vital:Byte=0 'parent info; vital determines if obj break destroys parent
	'collision group - 0 are guns & bullets that collide with everything, and 1 and 2 are teams that do not collide with themselves
	Field group:Byte=0 'attached objects never collide with each other
	'vertexes determine rotation of an object when force is applied
	Field vertnum:Byte=0,vertpos:Short[32,2] 'vertnum is number of vertexes and vertpos is the offset pos of each one
	
	Function Update()
		For Local o:obj=EachIn obj.list
			o.Draw
			o.CheckParent
			o.UpdatePhysics
		Next
	End Function


        [insert a bunch of methods here]



Please help me!


Brucey(Posted 2009) [#2]
This is not valid syntax :

Field atype%[8]=0

You cannot have "=0" as part of an array definition.


Pineapple(Posted 2009) [#3]
thanks for the help


Pineapple(Posted 2009) [#4]
Now I've got another error that I'm even more confused over on the line:

plat.frame(0)=LoadImage("Floor.bmp")


part of
Type objimage
	Global list:TList=CreateList()
	Field frame:timage[16],nowframe%,framenum% 'image handles for all frames, current frame of animation, and max number of frames

	Method Free()
		ListRemove objimage.list,Self
	End Method
	Method Draw(x#,y#,rot#)
		SetRotation rot
		DrawImage frame(nowframe),x,y
		If framenum>1 Then
			nowframe=nowframe+1
			If nowframe=>framenum Then nowframe=0
		EndIf
	End Method
End Type


Global plat:objimage=New objimage
plat.framenum=1
plat.nowframe=0
plat.frame(0)=LoadImage("Floor.bmp")


I get the error 'Compile Error Expression of type 'brl.max2d.timage Array' cannot be invoked'


klepto2(Posted 2009) [#5]
it should be frame[0] instead of frame(0)


Pineapple(Posted 2009) [#6]
I apologize for all the questions, but I wrote a decent amount of code before I had the opportunity to test it.

how come when with the obj type and I try to run this method:

	Method Draw()
		SetRotation ang
		DrawImage img.frame[img.nowframe],x,y
		If img.framenum>1 Then
			img.nowframe=img.nowframe+1
			If img.nowframe=>img.framenum Then img.nowframe=0
		EndIf
	End Method


it gives me 'Unhandled Exception: Attempt to access field or method of Null object'
But when it goes over this line of code elsewhere in a different method,

If attachgrouped=1 And ImagesCollide2(img.frame[img.nowframe],x,y,0,ang,1,1,other.img.frame[other.img.nowframe],other.x,other.y,0,other.ang,1,1) Then


It executes without any errors?


grable(Posted 2009) [#7]
Litter some Assert's around your source, specifically around the failing part..
	Method Draw()
		Assert img And img.frame ' <--- like here
		SetRotation ang
		DrawImage img.frame[img.nowframe],x,y
		If img.framenum>1 Then
			img.nowframe=img.nowframe+1
			If img.nowframe=>img.framenum Then img.nowframe=0
		EndIf
	End Method

If that doesnt help, maybe you forgot to call Graphics? ie. DrawImage or SetRotation could be failing.


Mauft(Posted 2009) [#8]
I am guessing that at the moment of executing this Draw method the img variable is not yet set, or the array in it is not set :).


Pineapple(Posted 2009) [#9]
The part that makes it most confusing, is the fact that if I tell it to draw the image in my code's main loop, it doesn't complain. Also, if instead of referencing to the type's field img:objimage I put box:objimage (which is a global variable referencing to one of my objimage, it works fine for plat, the other objimage handle, too)
Additionally, I am quite certain that img is the same as plat in this instance:
Global ground:obj=New obj
ground.img=plat


And that thing about the other line working - it's just not even making it to that line of code so I doubt it really would work.

here's my entire source, and if anyone wants to take a crack at eliminating the bugs or even improving the code, please feel free. I actually have some high hopes for this game so you'll definitely get some recognition.


EDIT: Whoops, I forgot to include the code :O (It's WIP obviously. Right now I'm just trying to get some basic physics down for objects)



Pineapple(Posted 2009) [#10]
Buuump I really would appreciate some help to fix this


grable(Posted 2009) [#11]
On line 308, you set cube1.img instead of cube2.img ;)


Pineapple(Posted 2009) [#12]
Dang I can't believe I missed that, thanks