Search code examples
basic4android

Is there a way to set a type's attribute to a default value?


type raygun( currentCharge as int, maxDamage as int, minDamage as int)

I couldn't find any examples demonstrating how to set the type's attribute to a default value when it is initialized. For example in this instance it would make sense to default the currentCharge to 100. I understand constants aren't supported at the moment, but I was wondering if there was a way to do this that I may not have considered.


Solution

  • There is no automatic way to do it. You can however create a sub that will create the type and initialize it as required:

    Dim rg As Raygun
    rg = InitRaygun
    
    Sub InitRaygun As Raygun
     Dim r As Raygun
     r.Initialize
     r.currentCharge = 100
     Return r
    End Sub