Question about Types

BlitzMax Forums/BlitzMax Beginners Area/Question about Types

MRaven(Posted 2004) [#1]
I don't get this about Types. When I create a type with some fields, like that:

Type Score 
	Field Score_x
	Field Score_y
End Type 


And I create a Type later on...

b = New Score 
b.Score_x = 25 


I get the error "Identifiere Score_x not foun". Shouldn't fields not be global like in Blitz3d??? I don't get it...

And how can I go trough all my types? EachIn seems not to work.

Thanks for your help


Warren(Posted 2004) [#2]
b:Score = new Score


MRaven(Posted 2004) [#3]
Ah, yes thats an error, thanks. I can now go through my types using a list, too. But how can I delete a type? "Delete" seem not to work, so dont "RemoveList"


Warren(Posted 2004) [#4]
You don't "delete", you "release". The garbage collector will free the memory when it gets around to it...


MRaven(Posted 2004) [#5]
Okay, got it.
Thanks pal, you're the best :)


Warren(Posted 2004) [#6]
I try. :)


Jolinah(Posted 2004) [#7]
Hi, is there a way to declare a field in a type as private?

In my module i am using a method for setting a field, so the field can't take wrong values. But anyone can change the field directly.. that shouldn't be possible in my case.


Drago(Posted 2004) [#8]
there are private and public commands but I'm not sure if you can use them in types.


Jim Teeuwen(Posted 2004) [#9]
you can't make fileds Private or Public

The Private and Public keywords are merely there for making sections of code accessible outside the current sourcefile or not.
Type Foo
  Field Foobar:String

  Method New()
    Foobar = MyEnum.First
  End Method
End Field

'// everything below this keyword is only accessible from within this sourcefile.
'// Calling it outside this sourcefile will generate an error.
Private 
Type MyEnum
   Const  First:String = "1", ..
          Second:String = "2" 
End Type


So the above will only work if Type Foo is in the same file as MyEnum.
The Public keyword is applied by default. So if you dont use these keywords, everything is Public automaticly.


Jolinah(Posted 2004) [#10]
thx

ok it would be a nice feature, but it's not a problem ;)


FlameDuck(Posted 2004) [#11]
ok it would be a nice feature, but it's not a problem ;)
Second that. Same with constructors.


dmoc(Posted 2004) [#12]
b:Score = new Score


I can see the convenience of specifying b's type for the compiler/translater itself but wouldn't it be more convenient for programmers if, where "new" is used, the type is inferred from the rhs?