Accessing user defined types

BlitzMax Forums/BlitzMax Beginners Area/Accessing user defined types

I am trying To access a variable in a user defined Type from another user defined type.
Specifically a VehicleType Field must access the TileType Field To determine If the vehicle can enter a Tile (See simplified code below).


Type Tiles

Field TileType:Int [25, 20]

End Type


Type Vehicle

Field VehicleType:Int

End Type

Here is what I am attempting To do

If Tiles.TileType <> 1 Then
MoveVehicle()
End If

MoveVehicle() is a Method of Type Vehicle
Please give your solution using code.
Thank you For your help in this matter.

I'm not sure to understand what do you ask...

Type Tiles
	Field TileType:Int
End Type


Type Vehicle Extends Tiles
	Field VehicleType:Int
	Method MoveVehicle()
		'code here
	End Method
End Type

Global car:Vehicle = New Vehicle

If car.TileType <> 1 Then
	car.MoveVehicle()
End If


Type Tiles and Type Vehicle are two unrelated types. As
the Tiles type has many more fields, not needed by the Vehicle Type, I would prefer not to extend the Vehicle type. I only need to access the TileType field of the Tiles Type from a method in the Vehicle Type to determine if an object from Type Vehicle can enter the Tile (TileType 1 is a water Tile and cannot be accessed by a vehicle object). Is this possible without extending the Type Vehicle?

I'm not sure I understand you but...

Type TTile
	
	Field type:Int
	
	'...
EndType

Type TVehicle
	
	'...
	
	Method move(tileType:Int)
		
		If tileType <> 1 Then
			
			'Move...
		EndIf
	EndMethod
EndType

'...

Local tile:TTile	= New TTile
Local vehicle:TVechicle	= New TVechicle

'...

vechicle.move(tile.type)

'...




Nicolas.

Is this what you seek to do?

Type Tiles

	Field TileType[20,25] 'Array with mapinfo
	Field TileWidth=100,TileHeight=100
	
End Type


Type Vehicle

	Field X,Y,XTile,YTile

	Method Move()
	EndMethod

	Method CalcTile()
		XTile = Int( X / Map.TileWidth  )' Calculates which MapField or Row we are in
		YTile = Int( Y / Map.TileHeight )' Same but for Y
	EndMethod

End Type 

Const Water = 1
Global Map:Tiles = New Tiles' I guess it's a map
V:Vehicle = New Vehicle
'Later on.. ..in main loop
V.CalcTile

If T.TileType[XTile, YTile] <> Water Then V.Move()


Thanks for the help, finally got it running.