Creating The Ruleset
First things first, you need to create a ruleset. You can either do that through the KRL Ruby Gem or through AppBuilder. For everything after this point, I'll be using the KRL Gem, and I suggest you do too.
Once you've installed the KRL Gem installed, run
to create an app. It will create a directory with a name corresponding the RID of the new app. A file with RID and a extension will be in the directory. You can rename the directory to anything you want. In my case, I changed mine from
Modifying the Ruleset
Next, modify the ruleset to respond to the CloudOS events. Open your ruleset in your favorite editor. You should be greeted by a ruleset that looks like the following:
This is the default ruleset that the KRL command line tool creates. Since we're writing this app to run inside the CloudOS we'll be modifying it quite a bit. If you're not at all familiar with KRL, be sure to read all of the children of the Rulesets page. These will help explain the different parts of the ruleset.
Responding to the cloudAppSelected event
The first task is to remove the placeholder rule (the rule named
first_rule). Then create a new rule named
The select statement defines the event conditions under which this rule will be selected. The CloudOS raises the
web:cloudAppSelected event whenever a user clicks on an app to run it. So, we want our HelloWorld app to be looking for that event and respond to it. With the select statement added, your rule should look like this:
Rules have preludes for calculating values used later in the rule. Our prelude is merely going to define some HTML to display and bind it to a variable
Everything inside the
<< >>'s are assigned to the variable
Next, add an action block. Inside the action block, paste the following three lines:
The first action,
inject_styling(), makes the styling of our app compatible with SquareTag. The second,
createLoadPanel() creates a panel in the CloudOS dashboard with the title "Hello World!" and loads the HTML we defined in the prelude into the panel we just created.
These are actions are defined within the
CloudRain modules. Note that we have not yet imported these modules. Let's go import those modules now.
Importing the CloudRain and SquareTag modules
KRL modules can be defined and imported into other rulesets. A module is literally just a ruleset that provides functions and actions for you to use. See the Modules page for more info on modules. We have two modules that we are trying to use (
SquareTag) that have not been imported yet. To import these two modules, add the following two lines into the meta block:
Commiting and Deploying the Ruleset
After all of these changes, your ruleset should now look like this except that the RID after
ruleset will be yours instead of a41x216 (I've also deleted some comments from the code):
You can make any changes to the author and description portions of the meta section that you like.
Open up your terminal and navigate to the directory that your ruleset is located.
krl commit. You should get "Committed version: 1" back.
krl deploy. You should get "Deployed version: 1" back from this command. If you did, everything worked correctly!
krl checkto check the syntax. It will provide line and character numbers of any syntax errors.
Running the App
After you've created, commited, and deployed the ruleset, the next step is to run your app!
- Log in to SquareTag.
- Open up your Settings (click on your profile image and click Settings).
- Select "myCloud" from the list of settings. Change your Cloud Type from
cloudTypeDeveloper. Save your changes. (Note: you only need to set this once. From now on, you can follow the following steps to deploy an app.)
- Go to "myApps".
- Click the gear in the app panel and select "Add devApp". Enter your app's
RID, Name, and upload an image if you want. Save your app.
- Go back to "myApps".
- Click on your application to run it.
If everything worked, you should see the following:
If you don't see this, check the preceding steps. The information on debugging KRL rulesets might also be helpful.
Once you've got your CloudOS app running, you might want to know how to make it run when someone scans it. The Creating a SquareTag application tutorial builds on this one to say hello to you every time you scan a tag.