functions or types
Blitz3D Forums/Blitz3D Programming/functions or types
| ||
which is better?. for example I am going to put lots of doors in my levels. most of them will share common properties. hope this is not a dumb question |
| ||
Arrays or Types you mean? I use arrays for easy access to things, but are less readable than types. It purely down to your preference tho :) |
| ||
yeah arrays or types. I think i was confused by something I saw the other day I think probably types are the way to go, just the syntax kind of annoys me sometimes. but they do make sense to me more or less. |
| ||
Ruz, Arrays are easy to understand and work with, Types are probably more powerful in the long run. For doors you may have quite complex options like doortype, material it is made from, key numbers, lock numbers, opens by sliding up, opens by sliding down, opens swinging on left hinge, how far? auto close.... and so it goes on. I would write the list down of ALL the options you are ever going to need in a door. Then I would do it in types. One type covers all doors, nice and simple, easy to refer to, easy to update, so fast you'll not know its there and over all a far more simplistic way to manage the data. Types would be my preference. Just make sure you give every option a name which means exactly what it refers to e.g. door\closedangle = 0 door\openangle = 110 door\numberoflocks = 2 door\key1 = 23 door\key2 = 24 door\material = 1 ; where 1 = stone, 2 = steel, 3 = wood so you know if you can break it down, blow it up or cut through it with an axe door\slidesup = 0 door\slidesdown = 0 door\swingsleft = 1 ; 0=no, 1= yes - hinged on left door\swingsright = 0 ; hinged on left side door\slidesleft = 0 door\slidesright = 0 door\hastrap = 1 door\trapnumber = 12 and so on. I hope that makes some sense to you. IPete2. |
| ||
Custom types are good for objects with the same set of properties. Arrays are good for a whole bunch of items of the exact same type. Look at it this way: P1 P2 P3 P4 Lives x x x x Score x x x x Name$ x x x x Using custom types, you use the columns, and end up with 4 players, each with 3 different fields. Type Player Field Lives Field Score Field Name$ End Type Or, with arrays, you use the rows, and end up with 3 arrays of 4 elements, and each index belongs to a player. Dim Lives(4) Dim Score(4) Dim Name$(4) In this case, it would make much more sense to go with custom types, since the objects all share the same properties. If, however, you're asking "linked lists" or "arrays", that's another question. |
| ||
Arrays are fine for things which are static, but dynamic entities like doors are perfect for Types. It gives you the ability to have a field for the door's status ( open/closed ) and it allows you to easily create and destroy doors ( that might or might not be useful, depending on the game. ) If you're looking for a little reading material to get you more comfortable with types, you could try these articles on the subject : Arrays and Types - Krylar http://www.blitzcoder.com/cgi-bin/articles/show_article.pl?f=gamekrylar10192000.html The Definitive Guide to Types - Muttering Goblin http://www.blitzcoder.com/cgi-bin/articles/show_article.pl?f=mutteringgoblin09232002232208.html |
| ||
thanks a bunch guys and thnks for those links Sybixsus, thats great.Good ideas there too IPete2 I have actually sorted out a double door using types and it works, ie opens when it should. It doesn't have a lot of properties yet, no real keys keys ,just conditional opening( which is kind of a key but I digress) seems pretty easy so far , hardest part is getting the doors in the right place I am just feeling my way in to this after sorting out my basic animation system more or less. I want to look at climbing /ladders etc climbing only on particular textures, could be a wall with ivy for example |
| ||
i would definately go with types, arrays have alot of uses but types have so much more. Actually using arrays of types is even better :) |
| ||
Well, soja. I wouldn't really doDim Lives(4) Dim Score(4) Dim Name$(4) Rather: x=4 ; number of players y=4 ; number of attributes dim stuff(x,y) Types and arrays are very much alike. I like arrays better now, because there alot easier to access. Type are easier to follow tho :) |
| ||
I find learnng stuff from the docs very confusing. I only seem to undertand something when I need to understand it for my own game . necessity and all that. |
| ||
edit... Anyone who is reading. Yes I see where you are going, but with types within types it can be an easier way to handle all that data. Krylar wrote a great explanation using spaceships, Mother ships and fighter crafts all have guns, fuel, shield, but maybe Mother ships have landing decks and hangars and lifeboats etc. Types don't have to be re-written if you add stuff either, simply add another field to ad a whole set of new stuff. They're dynamic so as far as creatures which spawn or particles go, types again are possibly the better way to manage the data. I don't know if there is a speed difference but Types are blumming quick when you have hundreds of vehicles or characters to deal with, all with tens of settings to juggle. It is a good read if you can find it. IPete2. |
| ||
@Ross, yeah, it's still pretty much the same thing, though. My point was that if you look at your data in terms of database terminology (i.e. in a table), arrays are suited for referencing the individual schema (columns), and custom types are suited for referencing the individual records (rows). (Though I wrote the table sideways in this case because it was easier, so the schema are rows and the records are columns.) Also, in general, it should be noted that when you create custom types, a linked list of each instance is created for you. There are distinct advantages (and disadvatages) to this which I won't get into. Just do a search on "linked list" versus "array" data structures. (Also, note that some people like to have the "best" of both worlds by putting their linked list elements *into* an array...) @Pete, er... are you sure you meant that for me? |