Bmx call-by-value, cant update TList objects

BlitzMax Forums/BlitzMax Beginners Area/Bmx call-by-value, cant update TList objects

I'm working on programming a "snakes" game in Blitzmax.

This is basic idea;
1. The snake can move on tile objects which represents a big chessboard. The tiles are added to a TList. Each tile itself is a Type ("class") with some properties X,Y, tilenumber etc etc.
2. When the worm moves, the tile on which it is located gets a flag set.
3. This flagged tile is (temporarily) flagged as occupied.
4. My code loops throught the Tlist-"Chessboard" calling an update on each tile, like this:

the code here was typed at work from my head in MS-Word, not in the compiler. it can contain (spelling) mistakes.
Type MySnakesGame
 Method manage()
   Graphics(800,600,0);
  '//...add about 480 tiles (32x30 pixels) on 800x600 display..
   local chessboardList:TList = new TList;
   for Local count1:int = 0 to 470
      Local chessTile:clsTile = new clsTile;
      chessTile.X = 30;  '//ofcoz increments..
      chessTile.Y = 30;  '// same here
      chessTile.TileCounter = count1;
      chessTile.tiledOcuppiedBy = enumNobody;
      chessboardList.Addlast(chessTile);
   Next

   While not keyhit(key_escape)
     cls();

    '//player moves, flag the tile as occupied
     '//handle keybord input, new X/Y is at 'tilenumber'.

     Local objOccupiedTile1:clsTile =  clsTile(ChessboardList.ValueAtIndex(tilenumber));
     objOccupiedTile1.tiledOcuppiedBy = enumPlayer; '//this is suppeds to call-by-ref, or not?

    '// the display will be filling up, visually showing where your player was.
    For Local objTile1:clsTile = EachIn ChessboardList:TList
      objTile1.Update();
    Next
    flip();
  Wend
 EndMethod

 '// here sumthing strange happens, call by value?  Call-by-reference?
endType

 type clsTile
    field myImage:TImage;
    Field x:int;
    Field y:int;
 
     '//stupid constructur emulated. call this in your code.. Blitzmax forum exmaple ;).
    function Create:clsTile()
       local objTile3:clsTile = new clsTile
       objTile3.MyImage = loadImage("snakehead1.png");
        return objTile3;
    endfunction

    method update()
       If(Self.tiledOcuppiedBy = enumPlayer)       
          DrawImage(Self.MyImage, self.x, self.y);
       EndIf
    endmethod
 end type


The above attempts to;
1. fill a tlist chessboard containing tiles.
2. aloow the player to move onto a tile.
3. Flag the tile as occupied.
4. Loop through all tiles in chessboard, updating it.

Problem:
the clsTile.Update doesnt do anything. The tile isnt rendered. The reference obtained from the Tlist (probably) dont update the object it obtained. Is that true? How can i modify a object in Tlist by reference?

This is going to be very tricky. Your clstile type doesn't have any X or Y attributes and isn't extended either. The same type doesn't have a TiledOccupiedby method or field either.
In short, I don't think the code you have posted gives much chance in suggesting anything.
How about waiting until you get home and posting the actual code?
<edit> In answer to your question you can take the clstile off the list exactly as you have done and then call its update method.

Here is the complete program code. Out of the box it wont run coz it needs a few .png files, which ofcoz can be swapped for any other image file.

TIA for any help :)

'---------------------------------------------------------------------------------------------------
' This program was written with BLIde (www.blide.org)
' Application:
' Author:
' License:
'---------------------------------------------------------------------------------------------------
SuperStrict
?MacOs
Framework brl.glmax2d
?Win32
'Framework brl.D3D7Max2D
Framework brl.glmax2d
?Linux
Framework brl.glmax2d
?

Import brl.random
Import brl.jpgloader
Import brl.pngloader
Import brl.retro

Global objMain1:clsSlangetjesMain = New clsSlangetjesMain;
Try
	objMain1 = objMain1.Create() ;
	objMain1.AppInstance = objMain1;
	objMain1.Main() ;
Catch objErr1:Object
	Throw("  STACKTRACE --> " + objErr1.toString()) 
EndTry


'// hier begint alles
Type clsSlangetjesMain
	Const CLASS_NAME:String = "clsSlangetjesMain";
	Field AppInstance:clsSlangetjesMain;
	Field MyObjects:TList;
	Field ScreenWidth:Int;
	Field ScreenHeight:Int;
	Field AppTerminated:Byte;
	Field escapePressed:Byte;
	Field AppStatus:Int;
	
	Function Create:clsSlangetjesMain() 
		Local objSlangetjesMain:clsSlangetjesMain = New clsSlangetjesMain;
		
		objSlangetjesMain.MyObjects = New TList;
		objSlangetjesMain.ScreenWidth = 800;
		objSlangetjesMain.ScreenHeight = 600;
		objSlangetjesMain.AppTerminated = False;
		objSlangetjesMain.escapePressed = False;
		
		Return objSlangetjesMain;
	End Function
	
	'// initiele opstart main loop, hier begint alles.
	Method Main() 
		Const METHOD_NAME:String = "Main";
		SeedRnd(MilliSecs()) ;
		
		Local skaakbordBeheer1:clsSkaakbordBeheerder = New clsSkaakbordBeheerder;
		skaakbordBeheer1 = skaakbordBeheer1.Create() ;
		skaakbordBeheer1.AppInstance = Self.AppInstance;

		Try
			Self.Init() ;
			Self.toonIntro() ;
		
			While(Not Self.AppTerminated And Not Self.escapePressed) 

				If(Self.AppStatus = 99) 
					Self.AppTerminated = True ;
				EndIf
				
				If(Self.AppStatus = 1) 
					Self.escapePressed = True;
				EndIf
				
				skaakbordBeheer1.ManageGameplay() ;
			Wend
			
			EndGraphics() ;
		Catch objErr1:Object
			Local strFout1:String = "  Fout in " + CLASS_NAME + "." + METHOD_NAME + "' --> " + objErr1.toString() ;
			Print(strFout1) ;
			Throw(strFout1) 
		EndTry
		
	End Method
	
'#Region 'Init() 
	Method Init() 
		Const METHOD_NAME:String = "Init";
		
		Try
			SetGraphicsDriver(GLMax2DDriver()) ;
			
			AppTitle = "slangetjes (c)10-okt-2007 GDB1.nl, pappavis@..."
			Graphics(Self.ScreenWidth, Self.ScreenHeight, 0) ;
			SetBlend(ALPHABLEND) ;
		Catch objErr1:Object
			Local strFout1:String = "  Fout in " + CLASS_NAME + "." + METHOD_NAME + "' --> " + objErr1.toString() ;
			Print(strFout1) ;
			Throw(strFout1) 
		EndTry
		
	End Method
	
'#End Region 
	'// vertoon introscherm.
'#Region 'toonIntro() 
	Method toonIntro() 
		Const METHOD_NAME:String = "toonIntro";
		
		Local IntroSkerm1:clsIntroSkerm = New clsIntroSkerm;
		Try
			IntroSkerm1.AppInstance = Self.AppInstance;
			IntroSkerm1.ManageIntroskerm() ;
			Self.AppStatus = IntroSkerm1.Status;
		Catch objErr1:Object
			Local strFout1:String = "  Fout in " + CLASS_NAME + "." + METHOD_NAME + "' --> " + objErr1.toString() ;
			Print(strFout1) ;
			Throw(strFout1) 
		EndTry
		
	End Method
	
'#End Region 
End Type


Type clsSkaakbordBeheerder
	Const CLASS_NAME:String = "clsSkaakbordBeheerder";
	Field AppInstance:clsSlangetjesMain;
	Field Status:Int;
	Field SkaakbordTegels:TList;
	Global tmpTegel:clsTegeltje;
	
	Function Create:clsSkaakbordBeheerder() 
		Const METHOD_NAME:String = "Create";
		Local objBeh1:clsSkaakbordBeheerder = New clsSkaakbordBeheerder;
		
		Try			
			objBeh1.SkaakbordTegels = New TList;
		Catch objErr1:Object
			Local strFout1:String = "  Fout in " + CLASS_NAME + "." + METHOD_NAME + "' --> " + objErr1.toString() ;
			Print(strFout1) ;
			Throw(strFout1) 
		EndTry
		
		Return objBeh1;
	End Function
	

	Method stomtoets1() 
		Const METHOD_NAME:String = "ManageGameplay";
				
		Try
			Local objSkaakbordList1:TList = New TList;
			Local tegel1:clsTegeltje = New clsTegeltje;
			Local worm4:clsSpelerSkip = New clsSpelerSkip;
			
			tegel1 = tegel1.Create() ;  '//maak een tegel.
			tegel1.SpelerSkipList = New TList;
			tegel1.CurrPosX1 = 32;
			tegel1.CurrPosy1 = 30;
			worm4 = worm4.Create() ; '// die worm plaatje inladen enz.
			worm4.CurrPosX1 = 400;
			worm4.CurrPosY1 = 120;
			tegel1.SpelerSkipList.AddLast(worm4) ; '//speler is op tegel.
			objSkaakbordList1.AddLast(tegel1) ; '// skaakbord heeft een tegel.
			
			tegel1 = tegel1.Create() ;  '//maak een tegel.
			tegel1.SpelerSkipList = New TList;
			tegel1.CurrPosX1 = 64;
			tegel1.CurrPosy1 = 60;
			worm4 = worm4.Create() ; '// die worm plaatje inladen enz.
			worm4.CurrPosX1 = 600;
			worm4.CurrPosY1 = 240;
			tegel1.SpelerSkipList.AddLast(worm4) ; '//speler is op tegel.
			objSkaakbordList1.AddLast(tegel1) ; '// skaakbord heeft een tegel.
			
			While(Self.Status <> 99 And Not Self.Status = 1) 
				Cls() ;
				DrawText("stomtoets" + MilliSecs(), 5, Self.AppInstance.ScreenHeight - 20) ;
				If(KeyHit(KEY_ESCAPE)) 
					Self.Status = 1;
				EndIf
'				DrawImage(worm4.image, 360, 260) ;
				
				For Local grid3:clsTegeltje = EachIn objSkaakbordList1
					DrawImage(grid3.image, grid3.CurrPosX1, grid3.CurrPosY1) ;
					For Local skip6:clsSpelerSkip = EachIn grid3.SpelerSkipList
						DrawImage(skip6.image, skip6.CurrPosX1, skip6.CurrPosY1) ;
					Next
				Next
				
				Flip() ;
			Wend
		Catch objErr1:Object
			Local strFout1:String = "  Fout in " + CLASS_NAME + "." + METHOD_NAME + "' --> " + objErr1.toString() ;
			Print(strFout1) ;
			Throw(strFout1) 
		EndTry
			
			
	End Method
	
	Method ManageGameplay() 
		Const METHOD_NAME:String = "ManageGameplay";
		
		Local spelerSkip1:clsSpelerSkip = New clsSpelerSkip;
		Try
			spelerSkip1 = spelerSkip1.Create() ;
			Local SkipRy1:Int = 10;
			Local SkipKol1:Int = 10;
			Self.InitialiseerSkaakbord() ;
			
'			Self.stomtoets1() ;
			
			While(Self.Status <> 99 And Not Self.Status = 1) 
				Cls() ;
				If(KeyHit(KEY_ESCAPE)) 
					Self.Status = 1;
				EndIf
				
				If(KeyHit(KEY_UP)) 
					SkipRy1:-1;
				EndIf
				If(KeyHit(KEY_DOWN)) 
					SkipRy1:+1;
				EndIf
				If(KeyHit(KEY_LEFT)) 
					SkipKol1:-1;
				EndIf
				If(KeyHit(KEY_RIGHT)) 
					SkipKol1:+1;
				EndIf

				If(SkipKol1 < 0) 
					SkipKol1 = 0;
				EndIf
				If(SkipKol1 > 24) 
					SkipKol1 = 24;
				EndIf
				If(SkipRy1 < 0) 
					SkipRy1 = 0;
				EndIf
				If(SkipRy1 > 19) 
					SkipRy1 = 19;
				EndIf
				
				Local spelerOpTegel1:clsTegeltje = Self.GetTegeltje(Self.SkaakbordTegels, SkipRy1, SkipKol1) ;				
				If(spelerOpTegel1.SpelerSkipList = Null) 
					spelerOpTegel1.SpelerSkipList = New TList;
					spelerOpTegel1.SpelerSkipList.AddLast(spelerSkip1) ;
Print(METHOD_NAME + MilliSecs() + ", spelerOpTegel1.SpelerSkipList(" + spelerOpTegel1.ItemNummer + ").count=" + spelerOpTegel1.SpelerSkipList.Count()) ;
				Else
'Print(METHOD_NAME + MilliSecs() + ", leeglijn") ;
				EndIf
				
				spelerSkip1.CurrPosX1 = spelerOpTegel1.CurrPosX1 ;
				spelerSkip1.CurrPosY1 = spelerOpTegel1.CurrPosY1 ;

				Self.Update() ;
				spelerSkip1.Update() ;
				DrawText("wormOpTegelNr=" + spelerOpTegel1.ItemNummer + ", SkipKol1=" + SkipKol1 + ", SkipRy1=" + SkipRy1, 5, Self.AppInstance.ScreenHeight - 20) ;
				Flip() ;
			Wend
		Catch objErr1:Object
			Local strFout1:String = "  Fout in " + CLASS_NAME + "." + METHOD_NAME + "' --> " + objErr1.toString() ;
			Print(strFout1) ;
			Throw(strFout1) 
		EndTry
	End Method


'#Region InitialiseerSkaakbord() 
	Method InitialiseerSkaakbord() 
		Const METHOD_NAME:String = "ManageGameplay";
		
		Local objTegel2:clsTegeltje;
		Local currX1:Int = 0;
		Local currY1:Int = 0;
		Local tegelTeller1:Int = 0;
		
		Try
			Self.SkaakbordTegels = New TList;
			
			For Local ry1:Int = 0 To 20;
				DrawText("Even wachten, intialiseren..", 5, 10) ;
				For Local kolom1:Int = 0 To 25;
					objTegel2 = New clsTegeltje;
					objTegel2 = objTegel2.Create() ;
					objTegel2.Kolomnummer = kolom1;
					objTegel2.Rynummer = ry1;
					objTegel2.CurrPosX1 = currX1;
					objTegel2.CurrPosY1 = currY1;
					objTegel2.ItemNummer = tegelTeller1;
					objTegel2.AppInstance = Self.AppInstance;
					
					DrawImage(objTegel2.image, objTegel2.CurrPosX1, objTegel2.CurrPosY1) ;
					Self.SkaakbordTegels.AddLast(objTegel2) ;
					currX1:+32;
					tegelTeller1:+1;
'Print(METHOD_NAME + ". objTegel2.ItemNummer=" + objTegel2.ItemNummer) ;
				Next
				currX1 = 0;
				currY1:+30;
				Flip() ;
			Next
		Catch objErr1:Object
			Local strFout1:String = "  Fout in " + CLASS_NAME + "." + METHOD_NAME + "' --> " + objErr1.toString() ;
			Print(strFout1) ;
			Throw(strFout1) 
		EndTry
	EndMethod
'#End Region 
	
	
'#Region GetTegeltje
	'// BlitzMax kan Properties niet in Functon benaderen, absurd, daarom SkaakbordTegelsList  param.
	Function GetTegeltje:clsTegeltje(SkaakbordTegelsList:TList, Ry:Int, Kolom:Int) 
		Const METHOD_NAME:String = "GetTegeltje";
		
		Local tegel5:clsTegeltje;
		
		Try
			For tegel5 = EachIn SkaakbordTegelsList
				If(tegel5.Rynummer = ry And tegel5.Kolomnummer = Kolom) 
					Exit;
				EndIf
			Next
		Catch objErr1:Object
			Local strFout1:String = "  Fout in " + CLASS_NAME + "." + METHOD_NAME + "' --> " + objErr1.toString() ;
			Print(strFout1) ;
			Throw(strFout1) 
		EndTry
		
		Return tegel5;
		
	End Function
	
'#End Region 

'#Region Update
	Method Update() 
		Const METHOD_NAME:String = "Update";
		
		For Local gridItem3:clsTegeltje = EachIn Self.SkaakbordTegels
			gridItem3.Update() ;
		Next
		
	End Method
End Type
'#End Region 


Type clsSpelerSkip Extends clsGameObject
	Const CLASS_NAME:String = "clsSpelerSkip";
	Field AppInstance:clsSlangetjesMain;
	
	Function Create:clsSpelerSkip() 
		Const METHOD_NAME:String = "Create";
		Local spelSk4:clsSpelerSkip = New clsSpelerSkip;
		
		Try
			spelSk4.image = LoadImage("./data/graphics/Cursor16x15.png") ;
			spelSk4.CurrPosX1 = 64;
			spelSk4.CurrPosY1 = 60;
		Catch objErr1:Object
			Local strFout1:String = "  Fout in " + CLASS_NAME + "." + METHOD_NAME + "' --> " + objErr1.toString() ;
			Print(strFout1) ;
			Throw(strFout1) 
		EndTry
		
		Return spelSk4;
	End Function
	
	Method Update() 
		Const METHOD_NAME:String = "Update";
		
		Try
			DrawImage(Self.image, Self.CurrPosX1, Self.CurrPosY1) ;
		Catch objErr1:Object
			Local strFout1:String = "  Fout in " + CLASS_NAME + "." + METHOD_NAME + "' --> " + objErr1.toString() ;
			Print(strFout1) ;
			Throw(strFout1) 
		EndTry
	End Method
End Type


Type clsTegeltje Extends clsGameObject
	Const CLASS_NAME:String = "clsTegeltje";
	Field AppInstance:clsSlangetjesMain;
	Field Rynummer:Int;
	Field Kolomnummer:Int;
	Field Breedte:Int;
	Field Wydte:Int;
	Field ItemNummer:Int;
	Field MyObjectsList:TList;
	Field BonusItemsList:TList
	Field SpelerSkipList:TList;
	Field Memotekst:String;
	
	Function Create:clsTegeltje() 
		Const METHOD_NAME:String = "Create";
		Local objTeg2:clsTegeltje = New clsTegeltje;
		
		objTeg2.ItemNummer = 0;
		objTeg2.Rynummer = 0;
		objTeg2.Kolomnummer = 0;
		objTeg2.Breedte = 32;	'//default 32px.
		objTeg2.Wydte = 30;	'//default 32px.
		objTeg2.SpelerSkipList = Null;
		objTeg2.image = TImage(LoadImage("./data/graphics/4kant16x15_2.jpg")) ;
		objTeg2.Memotekst = "";
		
		Return objTeg2;
	End Function

		
	Method Update() 
		Const METHOD_NAME:String = "Update";
		
		Try
'			DrawImage(Self.image, Self.CurrPosX1, Self.CurrPosY1) ;
			
			If(Self.SpelerSkipList <> Null) 
				For Local objWorm1:clsSpelerSkip = EachIn Self.SpelerSkipList
DrawText(METHOD_NAME + MilliSecs() + ",1 objWorm1.CurrPosX1=" + objWorm1.CurrPosX1 + ", objWorm1.CurrPosY1=" + objWorm1.CurrPosY1, 5, 565) ;
					objWorm1.Update() ;
				Next
			EndIf

If(Self.Memotekst <> "") 
	Print(METHOD_NAME + MilliSecs() + ", memotekst=" + Self.Memotekst + ", self.Rynummer=" + Self.Rynummer + ", self.Kolomnummer=" + Self.Kolomnummer) ;
EndIf

		Catch objErr1:Object
			Local strFout1:String = "  Fout in " + CLASS_NAME + "." + METHOD_NAME + "' --> " + objErr1.toString() ;
			Print(strFout1) ;
			Throw(strFout1) 
		EndTry
		
	End Method
End Type


Type clsIntroSkerm
	Const CLASS_NAME:String = "clsIntroSkerm";
	Field AppInstance:clsSlangetjesMain;
	Field Status:Int;
	
	Method ManageIntroskerm() 
		Const METHOD_NAME:String = "ManageIntroskerm";
		
		Local tijd3:Int = MilliSecs() + 40 ;
		Local posX1:Int = Self.AppInstance.ScreenWidth + 20;
		 
		While(Self.Status <> 99 And Not Self.Status = 1) 
			Cls() ;
			If(KeyHit(KEY_ESCAPE)) 
				Self.Status = 1;
			EndIf
			If(AppTerminate()) 
				Self.Status = 99;
			EndIf
			
			Local strIntro3:String = "WELKOM dit is een intro, druk esc      Jy kan verder gaan   ";
			DrawText(strIntro3, posX1, 10) ;
			
			If(MilliSecs() > tijd3) 
				tijd3 = MilliSecs() + 40 ;
				posX1:-2;
			EndIf
			
			If(posX1 < TextWidth(strIntro3) * -1) 
				posX1 = Self.AppInstance.ScreenWidth + 20;
			EndIf
			
			Flip() ;
		Wend
		
	End Method
	
	Method Update() 
		Const METHOD_NAME:String = "Update";
		
	End Method
	
End Type

Type clsGameObject
	field AppInstance:Object;
	Field CurrPosX1:Int;
	Field CurrPosY1:Int;
	Field MaxPosX1:Int;
	Field MaxPosY1:Int;
	Field MoveStepsizeX:Float;	
	Field MoveStepsizeY:Float;	
	Field image:TImage;
	Field KeyHitValue:Int;
	Field LastAnimFrameNr:Int;
	Field AnimDelayMS:Int;
	Field ObjectID:String;
	Field blnShoot:Byte;
	Field _XMoveCnt1:Int;
	Field _XMoveCnt2:Int;
	Field _XYMoveCnt1:Int;
	Field Delay1:Int;
	Field Radius:Double
	Field DistanceToTravel:Int;
	'//Field Parent:clsGameObject;
	Field intTargetX2:Int;
	Field intTargetY2:Int;
	Field GameObjectBelongsTo:Int;
	Field name:String;
	Field IsShooting:Byte;
	
	const VersionInfo:String = "1.0";

'//	Method Create:clsGameObject() abstract
'//	Method Update:clsGameObject() abstract
	
EndType

Type clsSpelGameObject Extends clsGameObject
	Field AnimFrames:Int;
	Field SGO1Coordinatelist:TList;
	Field SGO1PosisistionCounter:Int = 0;
	
	Function Create:clsSpelGameObject()
		Const METHOD_NAME:String = "Create:clsSpelGameObject";

		Local objInit1:clsSpelGameObject;
		
		Try
			objInit1 = New clsSpelGameObject;
			objInit1.CurrPosX1 = 0;
			objInit1.CurrPosY1 = 0;
			objInit1.AnimDelayMS = 10;
			objInit1.Delay1 = MilliSecs();
			objInit1.ObjectID = "SpelGameObject" + MilliSecs();
			objInit1.AnimFrames = 0;
			objInit1.SGO1Coordinatelist = New TList;
			objInit1.SGO1PosisistionCounter = 0;			
		Catch objErr1:Object	
			Throw("  Fout in '" + METHOD_NAME + "' --> " + objErr1.toString())
		EndTry
		
		Return objInit1;
		
	End Function

EndType




Just a hint, use [codebox] instead.