Types question

BlitzMax Forums/BlitzMax Beginners Area/Types question

Eikon(Posted 2005) [#1]
I am now using type functions and methods to do things, and have come across a problem. When I call my type.CreateType function, I do a check inside to determine whether or not I actually want to create the type. If the check passes, I return the type, If not, I am creating a dummy type that is immediately deleted. I've tried returning Null instead, but that crashes whenever I go to remove it. Is there a way to cancel the addition to my list after I've already called AddLast?

Example:
Type myType
     Field X, Y
     
     Function CreateType:myType()
          If Rand(1, 2) = 1 then
               Local m:myType = New myType
               Return m
          else
               ' What can I return at this point that
               ' will not cause a crash when I go
               ' through my list, besides creating a
               ' dummy type that is marked for deletion.
          endif
     End Function
End Type

typeList.AddLast myType.CreateType()



FlameDuck(Posted 2005) [#2]
You should either: a) Return null (and have a check that only adds non-null references to the list), or b) throw an exception.

In your particular case, however I would add the Type to the List in the Create function instead.


Eikon(Posted 2005) [#3]
In your particular case, however I would add the Type to the List in the Create function instead.

Thanks FlameDuck, that will do nicely.