Knowledge Base: LavishScript

From Lavish Software Wiki

Using File Paths

Background

Paths have recently been fixed in LavishScript and it has caused a little confusion. Paths can either be absolute which is an exact path that can't change, or relative compared to where a script is located that is trying to use a file.

Absolute file paths An absolute path is a path which is unchangable and doesn't take anything into account. It's absolute.

Examples:

Code:
 ui -load "/program files/inner space/interface/testUI.xml"
 runscript "C:\\MyScripts\\Dance.iss"
 extension -require /MyExtensions/Test


All these of the above examples are using absolute file paths. They would use the directories C:\Program Files\Inner Space\Interface, C:\MyScripts\, and C:\MyExtensions\Test respectively.

Relative file paths

A relative path is a path which is based on another path, which is based on the current working directory of LavishScript or the file path of the script which is executing the command.

Code:
 ;Load a ui at C:\Program Files\InnerSpace\Scripts\TestScript\Interface\ (on default installations)
 ui -load "TestScript\\Interface\\MapRadar.xml"
 ;Run a script from C:\Program Files\LuckyMonkey\
 RunScript ..\\..\\LuckyMonkey\\MonkeyDance.iss
 ;Run an extension from C:\Program Files\InnerSpace\Scripts\BluePants\BluePantsExtensions\SuperExtensionTwo
 extension ../Scripts/BluePants/BluePantsExtensions/SuperExtensionTwo/SuperExt

Obtaining path information from LavishScript

There are three commands to obtain what the current file path is for LavishScript, a specific script, or LavishScripts home directory.

Code:
 ;LavishScript home directory - will always be where Fury, Innerspace, etc. is run from
 ${LavishScript.HomeDirectory}
 ;Current working directory for the 'test' script.
 ${Script[test].CurrentDirectory}
 ;Current working directory for LavishScript
 ${LavishScript.CurrentDirectory}

Check if any given object exists

Background

There are generally several ways to determine if an individual object exists (is valid). Most of them involve comparing a string or an ID number, but this is relatively inefficient and will not work for all data types. Some ID numbers are even allowed to be 0, so checking an ID against 0 will also produce false negatives.

One way that has been used in the past is converting the result of a data sequence to a string object via the String Top-Level Object, and comparing that string to NULL. However, this is grossly inefficient and, well, would not be useful if the result could legitimately be NULL.

"exists" Data Type

LavishScript provides a data type called "exists" for the sole purpose of determining if the result of a data sequence is valid. The exists type always returns "TRUE".

This is useful because the moment a data sequence is invalid, the result is immedately NULL. Thus, if you evaluate ${Temp.Hex} and Temp is not a valid object, the result is NULL before .Hex is evaluated. Likewise, if you evaluate ${Temp(exists)}, and Temp is not a valid object, the result is NULL before (exists) is evaluated. This means that the two possible values from this data sequence are NULL if the data sequence is not valid, or TRUE if it is. NULL and TRUE are recognized by LavishScript's math processor as 0 and 1 (similarly, FALSE is 0), which means this can be legitimately used in any math sequence (such as conditions for If, While, numeric types' Set methods, math calculation members, and so on).

Example:

Code:
 if ${Me.Buff[1](exists)}
  echo Me has Buff[1]