DefData and 3impact?

BlitzMax Forums/BlitzMax Programming/DefData and 3impact?

Amon(Posted 2007) [#1]
Sorry if this shouldn't be posted here. I have posted this on the 3impact forums and am awaiting an answer. I thought I'd post it here also because I believe I may be doing something wrong on the BlitzMax side of things.

I use a method to fill a tilemap array when making 2d tiled games in BlitzMax. I use the defdata command to create some data to put in to the array. This method works flawlessly when using 2d in BlitzMax. When trying to apply the same method to a 3D Tilemap where I read the data in the data statements, set the frame for each element of the array and then place a cube at the position, it fails completely.

I've narrowed it down to where i fill the array with the data statements. For some reason 3impact refuses to acknowledge the defdata command. It keeps throwing an error "attempt to access index beyond array length". I know what this error means and why it happens and I know for a fact that I'm setting everything up correctly. Like I said, this method works perfectly when making 2d games with blitzmax.

I make TileMap an element of TTile. As you can see i create the objects with TTile.CReate() and then set the corresp[onding frame ID to what is stored in the defdata commands. This is where it fails.

Below is some simple test code. It refuses to compile and throws an error.

Note that I use the command "Until" in this bit "For Local xiter:Int = 0 Until MapWidth". It loops until it reaches MapWidrth or MapHeight without the need to have a -1 at the end of it like when using "to".


SuperStrict

Framework _3impact.Lib
Import brl.blitz
Import brl.filesystem
Import brl.linkedlist
Import brl.system
Import brl.math
Import brl.keycodes
Import brl.random
Import brl.polledinput

If Not i3ImpactOpen() RuntimeError "Unable to initialize the 3Impact game engine"
If Not i3ImpactSettings(_ISETTINGS(1024,768,32,False,True)) RuntimeError "3Impact settings failed"


Local myEngine:bmx_3IEngine=New bmx_3IEngine

' begin 3Impact processing
myEngine.Start()

Global Camera:CAMERA

Global MapWidth:Int = 10
Global MapHeight:Int = 10

Global TileMap:TTile[ MAPWIDTH , MAPHEIGHT ]
Type TTile
	Field x:Int
	Field y:Int
	Field id:Int
	
	Function Create:TTile()
		Return New TTile
	End Function

	Function Fill()
		For Local yiter:Int = 0 Until MapHeight
			For Local xiter:Int = 0 Until MapWidth
				Local Data:Int
				ReadData Data
				TileMap[ xiter , yiter ] = TTile.Create()
				TileMap[ xiter , yiter ].id = Data
			Next
		Next
	End Function
	
End Type


Type bmx_3IEngine Extends _3IEngine 
' called to initialize game variables, load resources, etc
	Method _Init()
   	
		Camera = iCameracreate(0.0 , 0.0 , 1.0 , 1.0)
		iCameralocationset( Camera , _D3DXVector3( 0.0 , 5.0 , 0.0 ))
	
		TTile.Fill
		
	EndMethod

' the main game loop
	Method _Run()
		
		
	EndMethod


' called when the application exits in order to clean up
	Method _Exit()

	EndMethod 

EndType 

DefData 0,0,0,0,0,0,0,0,0,0
DefData 0,0,0,0,0,0,0,0,0,0
DefData 0,0,0,0,0,0,0,0,0,0
DefData 0,0,0,0,0,0,0,0,0,0
DefData 0,0,0,0,0,0,0,0,0,0
DefData 0,0,0,0,0,0,0,0,0,0
DefData 0,0,0,0,0,0,0,0,0,0
DefData 0,0,0,0,0,0,0,0,0,0
DefData 0,0,0,0,0,0,0,0,0,0
DefData 0,0,0,0,0,0,0,0,0,0


I know I could store the data for the tiles in a map file which I can do easily but for test sakes I wanted to prototype the idea with data statements.

Is there some reason why defdata refuses to work with 3impact?


gman(Posted 2007) [#2]
greetings :)
myEngine.Start()

is what fills the array via the init() method, but you dont define the array until after you call Start(). move the start call to after the definition of TileMap.
Local myEngine:bmx_3IEngine=New bmx_3IEngine

Global Camera:CAMERA

Global MapWidth:Int = 10
Global MapHeight:Int = 10

Global TileMap:TTile[ MAPWIDTH , MAPHEIGHT ]

' begin 3Impact processing
myEngine.Start()



Amon(Posted 2007) [#3]
OMG! gman, thanks. :)

It works like a charm. :)

I can't believe it was as simpla as that. :)

Thanks again. :)


gman(Posted 2007) [#4]
np :) if i had a $ every time i did something like that id be retired :|