Oxygen Basic
Programming => Bugs & Feature Requests => Topic started by: Brian Alvarez on November 20, 2018, 01:56:10 PM
-
This is not a priority but i would like default values for types to be supported, for example:
type rgbacolor
red as byte = 35
green as byte
blue as byte
alpha as byte
end type
rgbacolor r
print str(r.red)
I noticed that this already compiles fine, but the value remains 0. I would also
like a way to reset to default empty values and a way to reset to predefined values.
-
Hi Brian,
o2 uses curly braces to assign default values:
'DEFAULT MEMBER VALUES
type color
byte r=0x10
byte g=0x20
'g as byte =0x20
byte b=0x30
byte a=0x40
end type
color d 'sets all to null
print hex(d.r) ", " hex(d.g) ", " hex(d.b) ", " hex(d.a)
d={} 'sets all to default values
print hex(d.r) ", " hex(d.g) ", " hex(d.b) ", " hex(d.a)
d={g=0x25,b=0x35} 'default values with overrides
print hex(d.r) ", " hex(d.g) ", " hex(d.b) ", " hex(d.a)
-
Awesome Charles! Thanks!
-
Sorry about reviving an old post... but i was playing with dfault values for TYPE and apparently it doesnt work when
there is a previous CHAR member. Even worse... it crashes after not setting the default values:
'DEFAULT MEMBER VALUES
type color
char cls[200] ' adding this makes it fail and crash.
byte r=0x10
byte g=0x20
'g as byte =0x20
byte b=0x30
byte a=0x40
end type
color d 'sets all to null
print hex(d.r) ", " hex(d.g) ", " hex(d.b) ", " hex(d.a)
d={} 'sets all to default values
print hex(d.r) ", " hex(d.g) ", " hex(d.b) ", " hex(d.a)
d={g=0x25,b=0x35} 'default values with overrides
print hex(d.r) ", " hex(d.g) ", " hex(d.b) ", " hex(d.a)
-
Okay, I'm recoding this feature, including multi-assignments. It has become too complex with low level code, so I'll use recursive decomposition, and hope to save about 400 lines of o2 source code in the process :)
-
Thanks charles, i also noticed it didnt work for CHAR or WCHAR elements... in fact no string types were working.