TList Problem

BlitzMax Forums/BlitzMax Beginners Area/TList Problem

Matt Vinyl(Posted 2007) [#1]
Hi all,

Type obj 'initialise the user-defined type that holds all the objects that can be in the map
	Field x:Int 'the horizontal position on the map
	Field y:Int 'the vertical position on the map
	Field item:Int 'the item that will be displayed on the map
	Field scanned:Byte 'a true / false flag to check if the item has been scanned that pass
End Type

Global map:TList=CreateList() 'initialise the list that will hold the map

For initmapx=0 To 63 'Initialise all horizontal map objects
	For initimapy=0 To 63 'initialise all vertical map objects
		Global mapobj:obj=New obj 'make a new map object
		mapobj.x=initmapx*64 'set the x value of the map object to it's correct position
		mapobj.y=initmapy*64 'set the y value of the map object to it's correct position
		mapobj.item=0 'set the item to the default blank item
		ListAddLast(map,mapobj) 'add the new object to the list
	Next
Next

Global state=0 'a game direction flag

Global finish=False 'a flag to see whether the program has ended

'---main---

Repeat 'the main game loop
	Cls
		For a=EachIn map
			DrawRect(a.x,a.y,64,64)
		Next 
	Flip
	If KeyHit(KEY_ESCAPE) Then finish=True
Until finish=True 'repeat the loop until the program has ended


I get an error on the

For a=EachIn map


line, saying that the variable type must be an object. I've trawled through time and time again, but can't work out the cause of the problem. Could anyone kindly advise?

Many thanks,
M


FlameDuck(Posted 2007) [#2]
For Local a:obj = EachIn map
Also, this line:
		Global mapobj:obj=New obj 'make a new map object
Should probably be:
		Local mapobj:obj=New obj 'make a new map object



Alden(Posted 2007) [#3]
There's also a typo in 'For initimapy=0...', should be initmapy?
I would recommend you to use Strict mode to avoid these problems. It will give you an error message if any variable is undeclared (you can catch typos that way too).


Matt Vinyl(Posted 2007) [#4]
Ah, excellent stuff. Simple when you know! Ta!


Matt Vinyl(Posted 2007) [#5]
Alden - well spotted! My next query was going to be why did it not plot my rectangles as expected. Teaching me that I should use Strict!!
:)


FlameDuck(Posted 2007) [#6]
Teaching me that I should use Strict!
Well SuperStrict actually.


Paposo(Posted 2007) [#7]
yes Flameduck!
I prefer that blitmax support only SuperStrict mode.
It is very clean and readable.

Bye,
Paposo


Matt Vinyl(Posted 2007) [#8]
Heh - true!

I've turned Strict on (at least!) and fixed a few things and all is well now.


Dreamora(Posted 2007) [#9]
Strict is not only cosmetics, but enables a few compiler and GC options.

For example local does scope as useless as in Blitz3D if you don't use strict. This means only a function is a scope that ends, nothing else.

This has a serious impact on performance.