Tlist Help
BlitzMax Forums/BlitzMax Programming/Tlist Help
| ||
Sorry if this has been asked before, but couldn't find in the search resulsts. Im looking for something that is almost like Handle(Object) be nice to have something that is for _Bullet:tBullet = eachin lBullets if(conditiona = conditionb) return _Bullet.Index next to THIS affect? Thanks in advance.... |
| ||
Can you provide a complete example? I think you may be failing to cast the object to its class... ? This is a sample application: Local list:TList = New TList list.AddLast("Hello") list.AddLast("world") For Local Text:String = EachIn list Print Text.ToLower() Next |
| ||
Ah i see what you mean lol.. actually im struggling with a few things, but... Global ltxt:TList = New TList Type tTxt Field text:String Field id:Int End Type Function AddTest(tt:String) Local nTxt:tTxt = New tTxt nTxt.text = tt nTxt.id = Rnd(2000) ltxt.AddLast(nTxt) End Function AddTest("ello") AddTest("world") AddTest("all") AddTest("your") AddTest("base") AddTest("are") AddTest("belong") AddTest("to") AddTest("us") Function FindText:ttxt(txt$) For Local stxt:ttxt = EachIn ltxt If stxt.text=txt Return stxt Next End Function For itxt:ttxt = EachIn ltxt Print itxt.text + " with value : " + itxt.id Next Print "FIND: 'base' = " + FindText("base").id (THIS actually works and its what i wanted!) sorry i wasted your time! .. |
| ||
FindText("base").id =5 WOW this is a NEAT feature! able to use function to return the type and then change?? Have i been programming Microcontrollers too long?!? lol |
| ||
Nop worries! As a side note, according to your example, if you're going ot make searches on the list, a TMap would be much more appropriated and performant. You may be interested in taking a look to TMaps |
| ||
actually i dont know anything about TMaps at all! the blitzmax code is very new to me, sorry to ask, is ther a chance you could do a small example? please? (plus are you advertising Blide or the creator of?) Last edited 2012 |
| ||
Very small sample:Global map:TMap = New TMap Type ExampleClass Field Value:String End Type Local Example:ExampleClass 'Create objects: Example = New ExampleClass Example.Value = "Hello!" map.Insert("MyFirstItem", Example) Example = New ExampleClass Example.Value = "world" map.Insert("AnotherItem", Example) Example = New ExampleClass Example.Value = "Something" map.Insert("TheThirdItem", Example) 'Now to get an item from its key: Local getItem:ExampleClass getItem = ExampleClass(map.ValueForKey("TheThirdItem")) If getItem <> Null Then Print "the item was found and has a vlue of: " + getItem.Value End If 'We can also iterate them For Myitem:ExampleClass = EachIn map.Values() Print Myitem.Value Next I'm the creator of BLIde :) EDIT: This line is very important to understand the example: getItem = ExampleClass(map.ValueForKey("TheThirdItem")) This does the following: map.ValueForKey("TheThirdItem") --> This looks for an object stored with the key "TheThirdItem" inside the map (and this is internaly indexed and its fast) then this: ExampleClass(........) --> Is a cast operation, it converts the contained ..... expression into an ExampleClass object. If it fails, it returns null.. so the whole sentence: ExampleClass(map.ValueForKey("TheThirdItem")) Is searching for "TheThirdItem" into the map and converting it back (casting it) to an ExampleClass instance, so it can be assigned to an ExampleClass variable. Last edited 2012 |
| ||
DOUBLE POST. Last edited 2012 |
| ||
Blide is awesome, though i have to say, there is a slight spelling mistake, "Becouse" should be "Because" i only used Blide for about 2 or 3 hours before i purchased a copy! Fantastic bit of kit! it makes sence, the greatest advantages are numerious! and BlitzMax native IDE cant seem to compile the modules, stays greyed out, however blide... sees right through it and WORKS!!! TMaps can do Methods too right? since i think its time to replace the Lists with tMaps! |
| ||
@Neochrome: Thanks! I'm Spanish so I have several spelling mistakes on BLIde. If you know where this "bocuse" was, I'll gladly correct it... EDIT: Yes, maps have a very nice set of methods, such as Contains(key) that return true or false if a given key stores an object into the map, Clear, etc... I'm not sure they're all documented, but BLIde will show them for you properly on intelliprompt, and are prety self explanatory on their names and parameters. Last edited 2012 |
| ||
if you wish, i'll be using the system alot, so i'll make a list of where these are? it looks like anything that reports with the "Becouse", nearly every where says it... can you believe it, i cant find it!! lol BlIDE makes programming so much mroe fun! and keeps my code nice and tidy EDIT: I've noticed that Blide's intellprompt is just amazing! fast too! Last edited 2012 |
| ||
Don't worry about the "becouse" thing. I've just done a find&replace on the BLIde source code to see it's in several places. I've fixed for the next update but I'm sure you'll find some more small spelling or language issues in the future, as it's a bit complicated for me to write everything in (sort of) English. |
| ||
It looks like that tMap is too narrow, i need something that can return the entire type lol... trying to work out the TMAP though |
| ||
It can return the entire type. In fact, it's what it does. |
| ||
Yes, i just found that out my self! lol... sorry about the late reply! its starting to look like that Tlist and Tmap do VERY much the same thing!.. for the game Loads and LOADS of particals are used, so Lists are used, but for pickable stuff. TMAPS would be used! !! Again.. THANK YOU FOR BLIDE! lol |
| ||
You're welcome! :D I just jope you enjoy BlitzMax as much as I do :) It's a joy to code with it. |
| ||
it seems to be VERY easy to code, i've got C++, and Microchips C under my belt, but to actually do code to make GAMES as easy as this... its a relief as all that coding just to make a graphics driver or string converter!! NO THANK YOU! lol |
| ||
this is interesting! the list seems to be sorted into alphabetical order on the insert time! no wonder the look up speed is AWESOME speeds! Last edited 2012 |
| ||
TMap is what other libraries - or more helpfully, Wikipedia - might usually call a "self-balancing binary tree". (But C++ STL calls it "map" too.) That means that if you have a million objects and wanted to find one, on average a TList would need to make a half-million comparisons, while a TMap could do it in under 20. Pretty useful. Just remember that because it defers that complexity onto the insert time, you might want to avoid modifying TMaps in the middle of high-performance loops. |
| ||
You know, i did something like thie back in the Amiga Days! its sad, but since computers seem so quick now, some programmers miss this now! Tlist is, 4,1,7,6,9,2,3,8 (in order of insertion) TMap inserts into the orderslot... tlist great for multiple bullets, Network Players, Tmap would you say this ia a good practice? |