DAS Script Custom Objects with NewUserObj
Group configuration, observations and status into explicit objects.
From scattered globals to a record
Prerequisite: object access and shared variables. NewUserObj creates a user-defined object whose properties you can assign. A record lets a reader see which values belong together. It does not enforce a schema, create a class or make its contents durable. Start with one owner and a documented shape.
Create a complete observation record
Advanced Script · local object state only. Run the complete example as one manual script. All values are invented test inputs.
Working example
$feObservation = NewUserObj();
$feObservation.schema = 1;
$feObservation.symbol = "MSFT";
$feObservation.bid = 20.10;
$feObservation.ask = 20.14;
$feObservation.valid = 0;
$feObservation.spread = 0;
if ($feObservation.bid > 0) {
if ($feObservation.ask >= $feObservation.bid) {
$feObservation.spread = $feObservation.ask - $feObservation.bid;
$feObservation.valid = 1;
}
}
$feObservation.ShowObject();
Read, write and replace
schema describes your own record format. It is not a DAS version flag. valid becomes one only after the dependent fields are populated. Consumers check valid before using spread. Assigning a fresh NewUserObj to $feObservation replaces the object referenced by that global; it does not promise to clear every other reference to the old object. The guide does not fully specify object aliasing or deep-copy behavior, so do not treat $b=$a as a documented clone operation.
Methods and schema evolution
obj.field is convenient when a key is fixed. Set(key,value) and Get(key) are useful when the key is data. Del(key) removes one property, while Del("*") clears the object’s properties. A schema change from spread to spreadDollars should either update all consumers together or use a new schema revision. Missing-property behavior is not a substitute for a migration rule. Keep configuration and live observations in separate objects if they have different reset policies.
Exercise and worked answer
Add a quantity field and a notional field to a hypothetical record with price 8.25 and quantity 40. Answer: initialize valid=0 and notional=0, validate positive price and quantity, calculate 330, then publish valid=1. An invalid second run must not leave the prior 330 marked valid. Test a full reinitialization and a field-only update separately.