Author Topic: Default Values for Types  (Read 227 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 3751
    • Oxygen Basic
Default Values for Types
« on: May 05, 2018, 04:48:50 AM »
This completes the rollout of O2's default value-setting for functions, macros and now, types.

Potentially useful for setting values in large or complex UDT variables.

A very simple example:
Code: [Select]
type Vector3dUnity
float x=1.0
float y=1.0
float z=1.0
end type

Vector3dUnity v 'initially all 0
v={}            ' v.x=1.0  v.y=1.0  v.z=1.0
v={ y=2.5 }     ' v.x=1.0  v.y=2.5  v.z=1.0

Unfortunately, this enhancement breaks the syntax of single liner unions, and though they are very rarely used, it affects a number of examples which use the aptly named in one place:

Code: [Select]
type pix     byte r,g,b,a  =  int c

 'should now be expanded to:

  type pix
    byte r,g,b,a
    int c
  end type

So I have attached the corrected below