Difference between revisions of "ObjectType:exists"
Jump to navigation
Jump to search
(3 intermediate revisions by 2 users not shown) | |||
Line 53: | Line 53: | ||
echo We dont know how many watermelons we have! | echo We dont know how many watermelons we have! | ||
} | } | ||
+ | |||
+ | |||
+ | == Operates On == | ||
+ | ''none'' | ||
== See Also == | == See Also == | ||
− | + | {{LavishScript:ObjectType}} | |
− | |||
− | |||
− |
Latest revision as of 16:40, 8 July 2018
Overview
This type exists for one reason and one reason only: To determine if the data sequence is still continuing. In a data sequence, the moment any object or member is not accessible, the sequence ends and becomes NULL. Casting to this type will demonstrate that the sequence is still continuing.
Members
(none)
Methods
(none)
Returns
TRUE
Examples
Example 1
We will demonstrate a collection of int objects, representing the number of different fruits we have. Mind that it is perfectly acceptable to have 0 of a fruit.
DeclareVariable Fruits collection int Fruits:Set[Apple,2] Fruits:Set[Strawberry,10] Fruits:Set[Banana,4] Fruits:Set[Watermelon,0] echo We have ${Fruits.Element[Apple]} apples echo We have ${Fruits.Element[Blueberry]} blueberries ; Uh oh, we have NULL blueberries! if "${Fruits.Element[Blueberry]}" { ; This technically works to determine if we have blueberries, but that's ; because int is fair game in a calculation. If this were a collection ; of strings, we would absolutely need something else! echo We have ${Fruits.Element[Blueberry]} blueberries ; This will not echo, because NULL is equal to 0, and this will only execute ; when the formula given to if is non-zero } else { ; This "else" will execute both when there is no Blueberry entry in the ; collection, AND when there are 0 blueberries. So the following statement ; is actually not true when we know we have 0 blueberries! echo We dont know how many blueberries we have! } ; The correct way to do so is as follows: if "!${Fruits.Element[Blueberry](exists)}" { ; The following statement will always be correct. It will ONLY be displayed ; when there is no Blueberry entry! echo We dont know how many blueberries we have! } if "!${Fruits.Element[Watermelon](exists)}" { ; The following statement will also always be correct. Even though we have 0 ; watermelons, the "exists" type gives TRUE, which is equal to 1. This means ; the only time this executes is when the data sequence is aborted before ; getting to the exists cast (when there is no entry!) echo We dont know how many watermelons we have! }
Operates On
none
See Also
LavishScript Object Types
- Text
- string - mutablestring - unistring
- Numbers
- byte - float - float64 - int - uint - int64
- Boolean (TRUE/FALSE)
- bool
- Pointers
- boolptr - byteptr - floatptr - float64ptr - intptr - uintptr - int64ptr - rgbptr - stringptr
- Containers
- objectcontainer - array - index - collection - queue - stack - set - variablescope
- JSON
- jsonobject - jsonarray - jsonvaluecontainer - jsonvalue
- Iteration
- iterator - jsoniterator
- Date/Time
- time
- File Handling
- filepath - file - filelist - filelistentry
- Tasks
- lavishmachine - Accessed via the Top-Level Object LMAC
- task - tasklibrary - taskmanager - tasktype - taskpulseargs - elmactaskstate