List problem
BlitzMax Forums/BlitzMax Programming/List problem
| ||
player_list is a :tlist p:player=player_list.last() and p:player=player_list.first() It should be fairly obvious what im trying to do, but cannot seem to get it to work :/ Wots the correct way? In b3d this is p.player=first player |
| ||
P:Player = Player(Player_list.last()) Player_list is a list of "Objetcs", which is ok, because everytype is an Object, so when you add anything to the list its OK and doesnt need to be cast or anything. However when you try and get the Object back, its ... well.. an object, so you have to cast it back to what it was when it was put on the list. Which in this case is quite easy, becuse everything on the list is a Player. Also, as some advice, give all types a prefix to distingush them from fields, methods and stuff. I would recomend TPlayer |
| ||
Think you need to cast the return to player. e.g. P:player=player(player_list.first()) but you could post the error you're getting or the code you're using to help. Local player_list:TList = CreateList() Type TPlayer Field num:Int End Type For Local x:Int = 1 To 10 temp:TPlayer = New TPlayer temp.num = x ListAddLast player_list , temp Next Local first_player:TPlayer = TPlayer(player_list.first()) Print first_player.num Local last_player:TPlayer = TPlayer(player_list.last()) Print last_player.num |
| ||
Type TPlayer Field num:Int Global List:TList = CreateList() Method New() Self.List.AddLast(Self) End Method End Type For Local x:Int = 1 To 10 Local temp:TPlayer = New TPlayer temp.num = x Next Local first_player:TPlayer = TPlayer(TPlayer.List.First()) Print first_player.num Local last_player:TPlayer = TPlayer(TPlayer.List.Last()) Print last_player.numSame code just moved arround, (Not better, just a different style, and for a different porpose and it really needs a "free" method) |
| ||
Thanks for the info, im trying to do a large scale conversion from blitz3d code (ARGH!!) so my types are named in the old way too :) Conversion's going really... really... s l o w! Another quick one while im at it, with loadmesh etc the handles returned are they just integers as per normal b3d or is it something else needed like for :timage? |
| ||
There inst a LoadMesh, so you are using one of the 3d Engines. So unless you tell us which...... (However most of them have Handle functions and Object Methods) LoadMesh(Url) 'returns Int Handle TMesh.Load (Url) 'returns Type |
| ||
lol sorry its minib3d |
| ||
Well, load in MiniB3d scroll down to LoadMesh and look ;) But I think as I said before, Handles for functions Types for methods. |