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 :) |
| ||
Just a hint, use [codebox] instead. |