types

BlitzMax Forums/BlitzMax Beginners Area/types

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Type TBullet
Field x:Int
Field y:Int
endtype

Global Bullet:TBullet

Function playershoot(x:Int,y:Int)

Bullet = New TBullet
Bullet.x = sx
Bullet.y = sy
EndFunction

Function draw()
DrawImage imbullet, bullet.x,bullet.y'now it says it dosnt recognize the variables "x" and "y"
EndFunction

Function update()
Bullet.x = +1
EndFunction 


You delcared it global within a function.

I think dreamora thinks the whole thing is within a type because you didnt put a end type. And if that is the case you only use global stuff within type functions.

And in that case the below should work
Type TBullet
global x:Int
global y:Int




Function playershoot(x:Int,y:Int)
TBullet.x = sx
TBullet.y = sy
EndFunction

Function draw()
DrawImage imbullet, TBullet.x,TBullet.y'now it says it dosnt recognize the variables "x" and "y"
EndFunction

Function update()
TBullet.x = +1
EndFunction 


But I should tell you now it looks like your going down the wrong direction.

You should be looking at list, methods, etc.

Editings:
Heres what i would do...
Type TBullet

	Field x%, y%
	
	Function Create:TBullet(_x%, _y%)
	
		Local b:TBullet = New TBullet
		b.x = _x
		b.y = _y
		Return b
		
	End Function
	
	Method Draw()
	
		DrawRect x, y, 10, 10
		
	End Method
	
	Method Update()
	
		x:+ 10
			
	End Method
	
End Type

Type TPlayer

	Field x%, y%
	Field bulletList:TList
	
	Function Create:TPlayer(_x%, _y%)
	
		Local p:TPlayer = New TPlayer
		p.bulletList = CreateList()
		p.x = _x
		p.y = _y
		Return p
		
	End Function
	
	Method Update()
	
		If MouseDown(1) Then
		
			bulletList.AddLast ( TBullet.Create(x, y) )
			
		EndIf
		
		For Local b:TBullet = EachIn bulletList
		
			b.Update()
			If b.x > GraphicsWidth() + 10 Then 
				bulletList.Remove(b)
				b = Null
			EndIf
			
		Next
		
	End Method
	
	Method Draw()
	
		DrawOval x, y, 20, 20
		
		For Local b:TBullet = EachIn bulletList
		
			b.Draw()
			
		Next
		
	End Method
	
End Type

Graphics 800, 600

Local player:TPlayer = TPlayer.Create(MouseX(), MouseY())

While Not KeyHit(KEY_ESCAPE)

	Cls
	
	player.x = MouseX()
	player.y = MouseY()
	
	player.Update()
	player.Draw()
	
	Flip
	
Wend

End


Tho that dose work I would suggest reading and understanding the tutorials that have been written about the subject of OOP design and BMax OOP.