Two really powerful programming tools used when creating programs in WayScript are conditionals and looping. These give users the ability to execute specific tasks automatically by simply inputting a module instead of writing code. In today’s tutorial, we’re going to look at how these two tools can be used in a simple example script. Keep reading to follow along!
For this example, we’ll use the HTTP Trigger module to create a sign-up page that uses e-mail. Using this module in the left screen toolbar, create a variable called “email” by typing it into the input box under “Outputs.” Next, the Google Sheets module is added so that the information from the HTTP sign-up page can be passed into it. In the toolbar choose which file to write the information into, and then add the “email” variable. To finish this step, add the HTTP Response module so that the program passes the results to the webpage.
Now, add a function to the script by clicking on the plus button in the upper left corner of the screen. Your tree should now look like this.
Let’s say we want to send a user an e-mail based on how much time has passed since they signed up on our created webpage. First, the Time Trigger module is added to the function. Then, we’ll use the same Google Sheet from earlier by adding the Google Sheets module and selecting the appropriate file. Next, rename and import the column headers; this then stores them as WayScript variables to be used later.
To loop over these variables the process is pretty straightforward. Simply add a Loop tool and choose the variables created from the column headers from the drop-down menu. Conditional statements are just as easy. Add the If tool below the Loop; this is an example of what that would look like.
In the toolbar, select the appropriate variable that you want to loop. This example uses the “days since signup” and the “is the same as” comparison, setting it equal to 1. Then, by adding the Gmail module underneath the If tool in the tree, an e-mail can be sent to the user that meets those criteria. Else If statements can also be added the same way as the If tool, creating another set of criteria with an attached action.
The options for using loop and conditional tools are endless, and this tutorial just provides a simple example of this. WayScript has the tools and versatility to create almost any kind of script you need, all in an easy to use format.