-
Notifications
You must be signed in to change notification settings - Fork 1
GettingStarted
- Overview
- Empty Workpace
- Running Snippets
- Editing Snippets
- Creating Snippets
- Connecting Snippets
- Passing Data
This page will provide a step-by-step guide on how to get started with using Snippet. The tutorial will not go into detail on the various topics discussed, but may provide links to pages with more information about them. The guide assumes Snippet is being run for the first time and is loaded into an empty workspace.
The first thing that is presented when the application is run is an empty workspace with a single snippet. An empty workspace means that snippets are operating out of a temporary location until one is specified. This occurs when saving the workspace. The first snippet created automatically is the 'main' snippet. This snippet cannot be renamed or deleted and is the first snippet run when the whole program is run.
The first thing to try will be to run the 'main' snippet. To do this, the editor window for the snippet will need to be opened. This can be done in two ways. The first is to right-click on the snippet to bring up the context menu and selecting the 'Edit' option. The other method is to double-click on the snippet. Once opened, you should see a text editor window appear next to the snippet. Multiple windows can be opened, but only one window per snippet can be opened at a time.
The snippet editor window allows the developer to modify the code associated with the snippet and run the code either stand-alone or as a whole program. More information about the various parts of the editor can be found here. For now, click the the 'Run' button, which is the left-most button on the snippet editor toolbar. The 'main' snippet will glow bright red to indicate the snippet has just been executed and 'hello world!' should appear in the output window.
Lets make some changes and see them applied on the next run. Change the following line of text in the snippet editor:
print("hello world!")
to:
print("hello main!")
If you run again, you should see the output text now reflects the new changes.
While more code could be added to the existing snippet, other snippets can be created which contains their own code as well that can be run independently. First, create a new snippet. This is done by right-clicking on an empty part of the workspace and selecting the 'New Snippet' option.
When a new snippet is created, the snippet will appear in the workspace along with the snippet editor window associated with this snippet. The editor window will have the title of the window editable to change the name of the snippet.
Change this to say 'Foo' and press enter. The snippet will be updated to reflect the name change. After changing the name, change the text to say 'hello foo!'. Now, instead of clicking the left-most button to run the whole program, click the 'Run Unit Test' button which is the middle button. This will run only the current snippet. The output window should now display 'hello foo!'.
Snippets can also be connected together so that they run one after another. To do this, click on the output pin of the 'main' snippet. The pin will be filled in and there will be a new connection line drawn to the mouse cursor. Click on the input pin of the 'Foo' snippet to make the connection. The workspace should match the image below.
Once connected, open up the 'Foo' snippet's editor window and click the 'Run' button, or the left-most button on the toolbar. This will run each snippet in order. The output window should contain 'hello main!' and 'hello foo!'. The snippets will also glow orange and fade back to a cool color to show how recent the snippet was executed. Finally, the connection between the snippets will animate to show that execution has moved to the next connected snippet.
Data can also be passed to connected snippets. This is done by any call to 'return' from the current snippet and returning the desired data to be passed along. Lua supports returning any number of values, with each value separated by a comma. These values are then passed to the next snippet as 'arg0, arg1, arg2... argN' where N is the number of items returned. If the incorrect argument is accessed, there will be an error displayed to the output window.
First, open the 'main' snippet window and add 'return "Return from main"' on the line below the print statement. Now open the 'Foo' snippet and add 'print(arg0)' on the line below the print statement and run the program. The output window should display the following:
hello main!
hello foo!
Return from main