Android Question [SOLVED] Default initialization state of Type?

techknight

Well-Known Member
Licensed User
Longtime User
I suppose this is more of a general question than an Android specific one, but... Is it possible to define the default initialization state of a CustomType?

for example, I have this:
B4X:
    Type GameOptionsData(HornEnable As Boolean, LightingEnable As Boolean, RetainLighting As Boolean, ShotClockEnable As Boolean, ShotClockHornEnable As Boolean, DualLink As Boolean, ClockPreset1 As String, ClockPreset2 As String, ClockPreset3 As String, TeamFoulLimit As Int, ShotClockLightingEnable As Boolean, _
        TimeoutSide As Int, TimeoutVisible As Boolean, PlayerFoulSide As Int)

Public GameOptions As GameOptionsData

Instead of doing .Initialize and then setting up all the variables of the values that they are supposed to be manually, like TimeoutVisible = True. its initialized as False by default of course

Any way to set/change this behavior? Like when you do something such as Dim XYZ as Boolean = True

Thanks
 

LucaMs

Expert
Licensed User
Longtime User
If you call
B4X:
GameOptions.Initialize

each field will be initialized with default values, then TimeoutVisible will be set to False.


P.S. obviously unless the fields are of a particular type, your custom types, for example.
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
If you call
B4X:
GameOptions.Initialize

each field will be initialized with default values, then TimeoutVisible will be set to False.


P.S. obviously unless the fields are of a particular type, your custom types, for example.

I know that, but I am trying to see if theres any potential to shorten the number of lines of code. because "Defaults" for me mean something different. I need to set some options to true, while others false, some of the Ints to specific values.

Im trying to avoid 473853473847 lines of code to do that, just curious if there was a way to "define" default values so when initialized itll set to what i had them specified.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
You can use the "Generate 'Create Type' Sub" method to generate the sub. You can edit the sub like you need to have it.
Setting some defaults to true, others to false, what ever.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I know that, but I am trying to see if theres any potential to shorten the number of lines of code. because "Defaults" for me mean something different. I need to set some options to true, while others false, some of the Ints to specific values.

Im trying to avoid 473853473847 lines of code to do that, just curious if there was a way to "define" default values so when initialized itll set to what i had them specified.
Then @Chris2' and @DonManfred's answers are the solution.
 
Upvote 0
Top