now a beginer TYPE question
BlitzMax Forums/BlitzMax Beginners Area/now a beginer TYPE question
| ||
In this type,there is a globaltype score global list:tlist=creatlist() end type Will list creat a list everytime I create an object?Or is it a one time deal?Just wondering about the global and if it has an effect on it. And if I don't create an object...will there be a created list? Thanks, mudcat |
| ||
globals in a type declaration are only initialized once. |
| ||
o.k., Then why does all the codes samples (well, not all)show this in a create function? If list=Null list=CreateList() Couldn't you just use my first example?And be done with it? |
| ||
there was a point where you couldn't initialize a global variable like that, so the code was written in a different manner. |
| ||
real question is. Why are you initializing a Global list inside a type declaration.Type score Field list:tlist=CreateList() Method add_score(score:String) ListAddLast(list,score) End Method Method show() Print "Score Table" For Local i$ = EachIn list Print i Next End Method End Type foo:Score = New score foo.add_score("100") foo.add_score("200") foo.show() |
| ||
real question is. Why are you initializing a Global list inside a type declaration. I can think of reasons. You might want to hold a list of all instances of that type, emulating Blitz Plus/3D's type lists. |
| ||
Another Example for Global lists in types would be this:Type Tparticle Global particle_list:TList Field x,y Field Emitter ... Function create() Particle_List.Addlast(Particle) End Function Function Render() For Local p:Tparticle = EachIn particle_list p.Update() Next End Function Method Update() ... End Method End Type While Not KeyHit(Key_Escape) TParticle.Render() Wend |
| ||
real question is. Why are you initializing a Global list inside a type declaration. well,maybe I not getting a hand on OOP programming.I was thinking so I can use score.list without an instance.Or is that bad programming? |
| ||
Not saying I used good programming techniques either but that's why I do it and I follow the method posted by Klepto2. |
| ||
I am certainly not saying that my way is better, good or even 'right' I just don't understand why you would want to use a GLobal. I was under the impression that Locals are more efficient. anyway. all of the methods work. That's the beauty of programming with Max, there is more than one way to do it! |
| ||
I was under the impression that Locals are more efficient. A list will not work well as a local anyway since it's going to be too big to be held in registers. A global list in the type is useful for keeping things neat and tidy. |
| ||
I've been wracking my brain cells (all 3 ;o) to work out why I wouldn't do it this way as I don't and I guess I need to justify why I don't! So here goes my thoughts... 1. You can only ever have one container class. 2. You could find that extending the class to deal with new features may be more complex than needed, for example Sorting the list, ToString. 3. Encapsulating changes is a good way to work with OO this approach might get in the way of this (see 2). Apart from that I kind of like it as it obeys the K.I.S.S. rule "Keep It Simple Stupid" which for some bizarre reason I often forget! |
| ||
1. You can only ever have one container class. What do you mean by this? |