Lab 02 - VoltScript Project with VoltScript Library Module
Duration 15 min
What you will learn
You'll learn how to use atlas.json
and structure a VoltScript project. You'll also learn how to integrate external library modules with a Use
statement.
Prerequisites
- Lab 01 completed
Steps
atlas.json
Note
The atlas.json is the VoltScript equivalent of Node.js's package.json, Maven's pom.xml or Rust's cargo.toml. It defines metadata about your project (name, version, authors, license), dependencies, structure, and scripts. You will use this more fully in the next exercise.
- Select File → Open Folder.
- Create a new folder in your user directory called "lab-02".
- Right-click in the empty pane and select New File from the context menu.
- Name the file
atlas.json
. - Type an opening curly brace "{" and press enter. VS Code automatically adds the closing curly brace "}".
-
If the PROBLEMS view isn't visible, select View → Problems. Note the validation errors, identifying required fields.
-
Set name to "lab02".
- Set version to "1.0.0".
- Set description to "Lab Number 2".
- Add the authors array. Add an array element with your name.
- Set sourceDir as "src". Set mainScripts as
main.vss
. - Use content assist (Ctrl + space) to see other elements that can be added.
- Set libsDir as "libs".
- Save the
atlas.json
.
libs directory
Note
In the same way that you can create Script Libraries and use them in Domino Designer with the Use
instruction, the same can be done in VoltScript. The terminology used to refer to these is "VoltScript Library Module".
- Right-click in the empty pane and select New Folder from the context menu. Name the directory "src".
- Right-click in the empty pane and select New Folder from the context menu. Name the directory "libs".
- Right-click the "libs" directory and select New File from the context menu. Name the file "Lab2Functions.vss".
- In the
.vss
file, addOption Declare
andOption Public
. -
Type Sub. Snippets will offer you "Sub...". Press Enter to select the snippet. The following code will be inserted.
-
ProcedureName
is selected. Rename the sub "PrintMessage" and press tab to move to the next variable. ParameterList
is selected. Overtype it withmessage as String
.- Move down to the body of the sub, and type
Print message
. - Move out of the sub, type "fun", and select the "Function..." snippet by pressing Enter.
FunctionName
is selected. Rename the function "Square". Press tab to move to the next variable.ParameterList
is selected. Overtype it withvalue as Integer
.ReturnType
is selected. Overtype it withInteger
. Only the first instance of this will be replaced and a compilation error will remain "Variable not declared RETURNVALUE".-
On the first line of the function, type
value *= value
.Tip
Additional mathematical assignment operators have been added. As well as the obvious
++
and--
options,+=
,-=
,*=
and/=
(with its alias\=
) have been added. -
Amend the last line of the function to
Square = value
. - Save the file.
Main script
- Right-click the "src" directory and select New File from the context menu. Name the file
main.vss
. - In the
.vss
file, addOption Declare
andOption Public
. -
Add the statement
Use "../libs/Lab2Functions"
.Note
We can use relative paths in the
Use
statement. Using forward slashes make theUse
statements cross-platform. Paths to Library Modules and downstream Library Modules (modules used in other Library Modules) need to work from any script opened. So all Library Modules should be at the same level of the hierarchy. -
Add a
Sub Initialize
. - Add
Call PrintMessage("Hello World")
. - Add
Call PrintMessage("4 x 4 = " & Square(4))
. - Press Ctrl+F5. This is a shortcut to save and run the script.
- Select VoltScript: Save & Run Script. It's listed first as the most recent command used.
How to check
Print to console:
The completed lab is available on GitHub.
Things to explore
- Change the last line of Lab6Functions' Square function to
Return value
.Return
can be used to return a value from functions, and exit out of a function or sub. - Test downstream VoltScript Library Modules (one module that uses another).
- Test to understand how relative paths need to work from all levels of the hierarchy.
Next step
Proceed to Lab 03 - Using VoltScript Extensions and Dependency Management.