Difference between revisions of "SHIP:Data Types"

From Serious Documentation
Jump to: navigation, search
(Box Model and Text Model Alignment)
(Box Model and Text Model Alignment)
Line 33: Line 33:
 
{{DataTypeTableStart|Alignment Data Types}}
 
{{DataTypeTableStart|Alignment Data Types}}
 
|{{:SHIP:Data_Types:HALIGN}}
 
|{{:SHIP:Data_Types:HALIGN}}
 +
|{{:SHIP:Data_Types:VALIGN}}
 
|}
 
|}
  

Revision as of 10:51, 30 January 2013

SHIP supports numerous data types for variables, constants, link variables, and port variables.

Note that, where relevant, all values within the SHIP Sail scripting and virtual machine environment are little Endian, regardless of the underlying MCU on the SIM.

Boolean

Booleans SHIP are 1-bit values.

Data Type Description
Boolean A true or false value.

Byte

Bytes in SHIP are 8-bit signed numbers.

Data Type Description
Byte Signed number that fits in the range -128 to +127.

Integer

Integers in SHIP are 32-bit signed numbers.

Data Type Description
Integer Signed number that fits in the range -2^31 to +(2^31-1).

Short

Short Data Types in SHIP are 16-bit signed numbers.

Data Type Description
Short Signed number that fits in the range -32768 to +32767.

String

Stings in SHIP are a sequence of UTF8 characters terminated in an implicit end-of-string character.

Data Type Description
String A sequence of UTF8 characters terminated in an implicit end-of-string character.

Time

Time Type Variables

Time type variables are a unique complex data type with several Integer subfields:

  • timevar.year -- the year, for example, 2016; this should be >= 2000
  • timevar.month -- the month 1..12 for Jan...Dec
  • timevar.day -- the day of the month 1..31
  • timevar.hour -- the hour in the day 0..23
  • timevar.minute -- the minute of the hour 0..59
  • timevar.second -- the second of the minute 0..59

In addition, there is an aggregate subfield:

  • timevar.value -- the number of seconds since 0:00:00 on January 1, 2000.

Auto-Translation Between .value and the other Subfields

When you assign the .value field with a number, the system will automatically translate this value to the other fields and vice versa. For example, assigning timevar.value = 10 will automatically set the year subfield to 2000, month to 1, day to 1, hour to 0, minute to 0, and seconds to 10. Subsequently changing the timevar.minute to 1 will then add 60 seconds to the value field which would then be 70.

Auto-Rollover on Subfields

The subfields can be assigned values outside their natural ranges. This will cause a rebalancing of the various fields to put them in compliance (if possible). For example, it is obvious you could set "timevar.month -= 1;" to go back one month in time. If, say, you were starting at February 20, timevar.month-- would change the time to January 20. The rest of the subfields would be unchanged except for the .value field.

However, subsequently subtracting 1 from the month causes a rollback to the prior year (December) as expected. You do not have to manually (e.g. if timevar == 1 <handle underrun> else <normal>). SHIP handles this automatically. So if you do a timevar.month-- when .month is 1, it will subtract one from the year and timevar.month will now be 12 as expected.

Similarly, assigning timevar.month to 13, for example, will cause the rebalance to timevar.month as 1 in the incremented year.

This capability makes it extremely easy to make date/time adjustments in the GUI, with the + and - buttons on each subfield simply implementing a -- or ++ on the subfield.

Events

All subfields of Time variables can cause events. For example, changing timevar.minute will cause any listener listeningto timevar.minute to wake up and run its associated script(s).

Multiple events are often generated simultaneously when subfields are adjusted. For example, changing the .value field will often fire multiple events across the other subfields because of the auto-translation from the .value field to the other subfields (.minute, etc.).

Similarly, auto-rollover can cause multiple events. For example, using a timevar.second-- when the date is Jan 1, 2001 at 00:00 will cause every subfield to change as the date is rolled back to the very last second of the year 2000.

Copying Time Variables

If you have two Time variables, you will generally want to copy the .value property. This atomically copies all the ingredients of the complex type at one time. For example if you have two Time variables named "foo" and "bar", you can use foo.value = bar.value, which will assign the time from bar to foo.

The shiptime System Variable

The shiptime system variable tracks the current system date/time and changes once per second during operation. For more information see shiptime.

Touch

Data Type Description
Touch Contains the type of the event, x coordinate, and y coordinate of the touch.

If the name of the touch port on your platform is "TOUCH0", access the information like so:

  • TOUCH0.event.e - contains the TOUCH.UP, TOUCH.DN, or TOUCH.MV event code
  • TOUCH0.event.x - contains the last x coordinate detected
  • TOUCH0.event.y - contains the last y coordinate detected
  • TOUCH0.event.value (or just TOUCH0.event) - used to detect whenever any sub-property (e, x, or y) changes.

CodepointRangeList

SHIP:Data Types:CodepointRangeList

Box Model and Text Model Alignment

The horizontal alignment (halign) property of any Box Model node positions a container within its parent to the left edge, center, or right edge within the inner area of the parent.

Alignment Data Types
Data Type Description
HALIGN Horizontal alignment of a box model or text model node within its parent. VALIGN Vertical alignment of a box model or text model node within its parent.

VALIGN

The vertical alignment (valign) property of any Box Model node positions a container within its parent to the top, center, or bottom of the inner area of the parent.

VALIGN||Vertical alignment of a box model or text model node within its parent.