4. Logic Dictionary: Difference between revisions

From Lifeguide Wiki
Jump to navigation Jump to search
 
(220 intermediate revisions by 2 users not shown)
Line 1: Line 1:
=A=
A quick reference guide to LifeGuide logic. For more detailed information, please refer to the '''How to...''' Guide


== <code> add </code> ==
==A==


The <code>add</code> command is used when performing calculations in the logic. This may also be written as <code>sum</code> or <code>+</code>.
= <code> add </code> =
 
This may also be written as '''sum''' or '''+'''. The '''add''' command is used when performing calculations in the logic.


'''Example 1'''
'''Example 1'''
Line 13: Line 15:
'''Example 2'''
'''Example 2'''


The <code>add</code> or <code>sum</code> commands can also be used to calculate variables that have been set earlier in the session:
The '''add''' or '''sum''' commands can also be used to calculate variables that have been set earlier in the session:
 
<code>set overallscore to sum (score1, score2, score3)</code>


<code>set overallscore to add (score1, score2, score3)</code>


== <code> after </code> ==
== <code> after </code> ==


The <code>after</code> key command is used after a page to perform functions that relate to that page.
The '''after''' command is used after a page to perform functions that relate to that page.


The <code>after</code> key command is an important command to learn. It is likely that you will use this command quite regularly in your intervention logic. The most common way of using the after key command is with the <code>if</code> and <code>goto</code> key commands in the following formula:
It is likely that you will use this command quite regularly in your intervention logic. The most common way of using the '''after''' command is with the '''if''' and '''goto''' commands, e.g.


<code>show page1</code>
<code>show page1</code>


<code>after page1 if (any_commands_you_want_to_relate_to_this_page) goto page2</code>
<code>after page1 if (any_commands_you_want_to_relate_to_this_page) goto page3</code>


'''Example'''
'''Example 1'''


<code>after page1 if (page1.interaction1 = "yes") goto page2</code>
<code>after page1 if (page1.interaction1 = "yes") goto page3
show page 2
show page3</code>


In this example the end-user will be directed to page2 if they have answered 'yes' to 'interaction1' on page1.
In the above example, the end-user will be directed to '''page3''' if they have answered '''yes''' to '''interaction1''' on '''page1'''. If they answer '''no''' to '''interaction1''', they will be directed to the next line of logic and will see '''page2'''.


As will be seen throughout this dictionary any command can be used with the <code>after</code> key command.
'''NB If you use the <code>after</code> command with the <code>goto</code> command, the page that you goto should NOT be the next page shown in your logic, it should be a page further down in your logic''' as in the example above.


As will be seen throughout this dictionary, any command can be used with the '''after''' command.


== <code> and </code> ==
== <code> and </code> ==


The <code>and</code> command can be used for a number of reasons:
Can also be written as '''&&'''.
 
The '''and''' command can be used for a number of reasons:


# If there is more than one response that is involved in presenting tailored advice to end-users, i.e. if one response and another response is needed to show feedback to an end-user.
# If there is more than one response that is involved in presenting tailored advice to end-users, i.e. if one response and another response is needed to show feedback to an end-user.
Line 48: Line 54:
<code>show page6 if (and(page3.exercise = "yes", page3.intensity = "moderate", page3.frequency = "three"))</code>
<code>show page6 if (and(page3.exercise = "yes", page3.intensity = "moderate", page3.frequency = "three"))</code>


End-users will be shown pagename6 if they selected yes to the interaction exercise on page3, moderate to the interaction intensity on page3 and three to the interaction frequency on page3.
End-users will be shown page6 if they selected '''yes''' to the interaction '''exercise''' on '''page3''', '''moderate''' to the interaction '''intensity''' on '''page3''' and '''three''' to the interaction '''frequency''' on '''page3'''.
 
 
'''Example 2'''
 
<code>after login_successful if (and( not(hasseen(username, "q_demographics")), (isempty (loadvalue(username, "baselinecomplete"))) )) goto q_intro </code>
 
End-users will be shown '''q_intro''' if they have not seen page '''q_demographics''' and if the variable '''baselinecomplete''' is empty (i.e. '''the variable baselinecomplete hasn't been saved because the end-user hasn't finished the baseline questionnaire).


== <code> append </code> ==
== <code> append </code> ==
Line 56: Line 69:
'''Example 1'''
'''Example 1'''


In this example the append function is used to attach a person's username (which has been set in a previous part of the logic) to the text used in an email message:
<code>sendemail (append(username,"email_session1"),username,"StressLess - Session 1 is ready", append("Dear ", loadvalue (username, "personsname"), "\n\n", session1_email), 10) </code>
 
In this example '''append''' is used to attach:
 
*a username (which has been set in a previous part of the logic) to the unique name of the email message
 
*a user's name to the text used in an email message. The append function here allows the content of the email message to be made of different parts.


<code>after login if sendemail ("welcomeemail", login.uname, "Welcome to the lifestyle study", append ("Thank you for registering for the study", username, "remember to chart your progress everyday"), 60) goto page1</code>
The '''\n\n''' in the logic above means a new line in the email message content.


== <code> authenticateuser </code> ==
== <code> authenticateuser </code> ==
Line 70: Line 89:
<code>after login if (authenticateuser (login.username, login.password)) goto page1</code>
<code>after login if (authenticateuser (login.username, login.password)) goto page1</code>


So in the example above the details that the end-user enters into username and password interactions on the login page will be used to check that they are a registered user.
So in the example above, the details that the end-user enters into the username and password interactions on the login page will be used to check that they are a registered user.


=B=
=B=
Line 82: Line 101:


* If you begin a section, you should always end the section.
* If you begin a section, you should always end the section.
* All the logic related to the section must be between begin sectionname and end
* All the logic related to the section must be between <code>begin</code> and <code>end</code>
* The name of the section should not be the same as any unique name that has been given to an object or page in your intervention.
* The name of the section should not be the same as any unique name that has been given to an object or page in your intervention.
* As you can only ever end the section that you are currently in you do not need to write the section name after end.
* As you can only ever end the section that you are currently in, you do not need to write the section name after end.


'''Example 1'''  
'''Example 1'''  
Line 120: Line 139:
<code>end </code>
<code>end </code>


This will begin the section stress.  
This will begin the section '''stress'''.  
The section causes will then begin and page1 and page2 in the section causes will be shown.  
The section '''causes''' will then begin and '''page1''' and '''page2''' in the section '''causes''' will be shown.  
he first end will end the section causes.  
The first <code>end</code> will end the section '''causes'''.  
The section relieve will then begin and page3 and page4 will be shown.  
The section '''relieve''' will then begin and '''page3''' and '''page4''' will be shown.  
The next end will end the ection relieve. The final end will end the section stress.
The next <code>end</code> will end the section '''relieve'''. The final <code>end</code> will end the section '''stress'''.
=D=
 
=C=
 
== <code> cancelemail </code> ==
 
Used to cancel an email that has been set up earlier in the logic.
 
You may want to:
* cancel emails to end-users (e.g. if you set up email reminders for end-users to login to upcoming sessions, you will need to cancel them if they login before the email is due to be sent.
* cancel emails to the study coordinator (e.g. if you set up email reminders to notify the study coordinator when end-users do not complete study questionnaires, you will need to cancel them if they complete the questionnaires.


== <code> divide </code> ==
This command uses the same basic formula:


This is used when performing calculations. The symbol <code>/</code> can also be used.
<code> after pagename if cancelemail ("unique name for email", e-mail address) goto nextpage</code>


'''Example 1'''
'''Example 1'''


<code> set score1 to (page1.interaction1 / page1.interaction2)</code>
<code>cancelemail(append(username, "email_session2r"), username)</code>


score1 would be the result of dividing the response given in interaction 1 by the response given in interaction 2.
This will cancel the email '''email_session2r''' for an end-user. The '''append''' function links an end-user's '''username''' to the name of the email ('''email_session2r''') to give each email a unique name.


'''Example 2'''
'''Example 2'''


<code> set overallscore to (score1 / score2)</code>
<code>cancelemail(append(username,"q1_notcomplete"), "study@test.ac.uk")</code>
 
This will cancel the email '''q1_notcomplete''' that was due to be sent to '''study@test.ac.uk'''. The '''append''' function links an end-users '''username''' to the name of the email ('''q1_notcompleteto''') to give each email a unique name.
 
== <code> cancelsms </code> ==
 
This command cancels an SMS message that has already been set up earlier on in the logic.
 
It uses a similar basic formula that is used for cancelling emails except it uses the <code>cancelsms</code> command and a phone number:
 
<code> after pagename if cancelsms ("unique name for sms message", phonenumber) goto nextpage</code>


In this example the overallscore is calculated by dividing score1 by score2 where score1 and score2 have already been calculated elsewhere in the logic.
== <code> changepassword </code> ==


=E=
Enables end-users to change their password.


== <code> end </code> ==
Please see the LifeGuide Community Website for a tutorial intervention that shows how to create the pages and write the logic for this.


See <code>begin</code>
'''Example 1'''


=F=
<code> after passworddetails if changepassword (username, passworddetails.old, passworddetails.new) goto confirmchange</code>


== <code> for </code> ==
This will allow a password to be changed if the old password is correctly entered into the interaction called '''old''' on page '''passworddetails''', and a new password is entered into the interaction called '''new''' on page '''passworddetails'''.


The <code>for</code> key command is used with the <code>save</code> and <code>graph</code> key commands.
== <code> checkemailvalidity </code> ==


=G=
Checks that the e-mail address a user has entered contains an @ symbol.


== <code> goto </code> ==
This command is used with an error message and is written in the  '''Error Messages''' tab (please refer to [[Adding Error Messages]] for information about writing error messages).


The <code>goto</code> key command always follows the <code>after</code> key command. See above.
'''Example 1'''


== <code> graph </code> ==
<code> show invalidemail if (not (checkemailvalidity (email)))</code>


The <code>graph</code> key command is used when you have used the graph interaction. It is used to plot the information given by end-users to the graph.
'''invalidemail''' is the name of an error message and '''email''' is the name of the interaction on this page where the end-user would enter their e-mail address.


This key command always follows the same formula and requires users to set up a user account.
== <code> checkphonenumbervalidity </code> ==


<code>graph value to "data variable determined on the graph interaction" for unique_identifier_for_the_end-user_e.g._a_username</code>
Checks that the mobile number a user has entered begins with '''+44''' or ''''0'''.


Another line of logic is then needed for the page where the graph occurs. This will also always follow the same formula:
This command is used with an error message (please see [[Adding error messages]] for more information.


<code>set pagename.graph-1 to graph "data variable determined on the graph interaction" for username</code>
'''Example 1'''


Here, pagename.graph-1 is the automatically generated name of the graph that has been put on the page where the graph occurs.
<code> show invalidnumber if (not (checkphonenumbervalidity (phone)))</code>


''' Example1'''
In this example '''invalidnumber''' is the name of the error message and '''phone''' is the name of the interaction on this page where the end-user would enter their phone number.


In this example the number entered in the interaction ‘kg’ on the page ‘progresschart’ will be used as the data for the “weight” variable for the graph. The variable username has been set earlier in the logic as the unique identifier for the end-user (see the <code>set</code> key command for more information).
Please note that this logic is only set up to work with UK based numbers. Researchers will need to create their own error messages to check the correct numbers are entered for international numbers.


<code>show progresschart
== <code> checkuserenabled </code> ==
graph progresschart.kg to "weight" for username</code>


Later in the logic the following line is needed after the page where the graph occurs:
== <code> checkuserexists </code> ==


<code>show weightgraph
This command would check whether an email address or username has already been registered for the intervention (i.e. if the details that have been entered is already registered with another user). This command is often used with an error message (please refer to the [http://www.lifeguideonline.org/releases/documentation researcher help manual] for details of writing error messages).
set weightgraph.graph-1 to graph "weight" for username</code>


A full tutorial for using graphs will soon be available.
'''Example'''


=I=
<code>show registeredemail if (checkuserexists (email))</code>


== <code> if </code> ==
In this example registeredemail is the name of the error message that would show if what they person enters in the 'email' interaction has already been registered.


The <code>if</code> key command is always used with the <code>set</code> or <code>after</code> key commands.
== <code> comparetimes </code> ==
This command can be used to compare two points in time.


=L=
'''Example 1'''


== <code> load </code> ==
This example shows how <code>comparetimes</code> can be used to control users’ access to different sessions or pages within an intervention.


The <code>load </code> command is always used with the save command.


=N=
In your logic, you will first need to create a new variable (e.g. "username") which will tell the intervention which user times need to be compared for: 


== <code> named </code> ==
<code>set</code> username <code>to</code> login.name


Use this key command to re-show a page you have already shown.
<code>if</code> ( <code>not</code> ( <code>isempty</code> ( signup.name ) ) ) <code>set</code> username to signup.name


For example, if you had a page that you need to keep showing back to your end-users you could use the <code>named</code> key command as so (note that in the example below the line [etc, etc] has been used to indicate that there would be other lines of logic here):
(For this logic to work, you will need to have already created “login” and “signup” pages which contain free text interactions to allow the user to enter their name or other identifier such as an email address – see also [[1.12 set]])
 


'''Example'''
The order of your logic is very important when using the <code>comparetimes</code> function:
 


<code>show page1</code>
'''1.''' You first need to show the page users see before they are directed to particular sessions (e.g. "mainpage"):


[etc, etc]
<code>show</code> mainpage


<code>show page1 named page2</code>


[etc, etc]
'''2.''' Using the <code>comparetimes</code> function you now need to write the logic which directs the user to a particular session or page of the intervention:   


<code>show page1 named page3</code>
<code>after</code> mainpage <code>if</code> ( <code>comparetimes</code> ( <code>loadvalue</code> ( username, <code>"session4time"</code>) , <code>currenttime</code> ( ), <code>"seconds"</code> ) <code>>=</code> 120 ) <code>goto</code> endpage


=S=
This tells the intervention that the user can continue to the end of the website if the difference between the current time, and the time the user completed session4, is more than or equal to two minutes.  <code>“seconds”</code> may be replaced by <code>“minutes”</code>, <code>“hours”</code>, <code>“days”</code>, <code>“weeks”</code> or <code>“months”</code> (Don’t forget to end each with an ‘'''s'''’!) 


== <code> save </code> ==
The <code> save </code> key command allows you to save the responses that an end-user enters on a page. This can then be loaded using the <code> load </code> key command onto another page to re-show it to your end-user. The save and load commands can be used across sessions and requires end-users to have registered a user account.


Example:
<code>after</code> mainpage <code>if</code> ( <code>comparetimes</code> ( <code>loadvalue</code> ( username, <code>"session3time"</code> ), <code>currenttime</code> ( ), <code>"seconds"</code> ) <code>>=</code> 120 ) <code>goto</code> session4


<code> show page1</code>
This line tells the intervention that the user can continue to session4 of the intervention if it has been at least two minutes since they completed session3


<code> save page1 for username</code>


Then, later on in the logic (either in the same session or a later session) the following logic would be used:
<code>after mainpage if ( comparetimes ( loadvalue ( username, "session3time" ), currenttime ( ), "seconds" ) <= 120 ) goto waitpage</code>


<code> show page20</code>
This line of logic tells the intervention that the user cannot continue to session 4 because it has been less than two minutes since they completed session 3.  Users are directed to a “waitpage” instead.


<code> set default page20.interaction2 to load page1.interaction1 for username</code>
Repeat this process for the various sessions or pages contained within your intervention, for which you want to control access.  The variables <code>"session3time"</code> and <code>"session4time"</code> are created in step 3.


So, in the first part of this logic page1 is saved for the end-user. Then when they get to page20 in the intervention the response that they entered on interaction1 on page1 will be reshown to them on interaction2 on page20.
'''3.''' Finally, using the <code>show</code> function you need to display the individual pages or sessions of your intervention, e.g.:


== <code> saveandload </code> ==
<code>show</code> waitpage


This key command can be used after a page that includes interactions so that if an end-user moves away from that page and then comes back to it, the page will automatically show them what they entered the last time they were on that page. This line of logic would simply be written as so:
<code>show</code> session3


<code> show page1</code>
<code>after</code> session3 <code>if</code> ( <code>savevalue</code> ( username, <code>“session3time”</code>,
<code>currenttime</code> ( ) ) )<code>goto</code> session3end


<code>saveandload page1 for username </code>
<code>show</code> session3end


Any interaction on page1 would then be saved and loaded each time the end-user comes back to that page.
Using the <code>currenttime function</code> (see [[2.15 currenttime]]), this logic instructs the intervention to save a new variable <code>“session3time”</code>.  This new variable records the time at which the user completed session3. 
 
So, in this example, the intervention compares the time at which the user completed a given section of the intervention, with the current time, to determine whether enough time has elapsed to allow them to continue on to the next session.


== <code> set </code> ==
== <code> contains </code> ==


The <code>set</code> key command can be used to set variables within the logic or for performing calculations.
Used with multiple-choice interactions. It is used to show tailored information based on a specific response an end-user has given.


'''Example 1'''
'''Example 1'''


The most common use of setting variables will be to set a username for the user. Many of the logic commands such as <code>save</code> will need a username to be set. This will need to be done at the start of your logic file.
<code> after page1 if (page1.exercise contains "none") goto page4</code>


<code>Set username to login.loginuname</code>
In this example, the end-user will be directed to '''page4''' if they had selected '''none''' to the interaction '''exercise''' on '''page1'''.


This will set the variable username to whatever the end-user enters into the interaction uniquely named loginuname on the login page. The word username can then be used any time throughout the logic to mean whatever the person entered in that interaction.


'''Example 2'''
'''Example 2'''


The <code>set</code> key command can also be used to set a variable based on how end-users respond to certain interactions. This can then be used to tailor the intervention based on this variable.
<code> after page1 if (or( page1.exercise contains "1day", page1.exercise contains "2days" )) goto page4</code>
 
An end-user will be shown '''page4''' if they selected '''1day''' or '''2days''' to the interaction '''exercise''' on '''page1'''.
 
== <code> countif </code> ==
 
This command can be used to count how many interactions an end-user has filled in.
 
'''Example'''
 
<code>after page1 if (countif (not (isempty (page1.interaction1))), (not (isempty (page1.interaction2))), (not (isempty (page1.interaction3))), (not (isempty (page1.interaction4)))) <3) goto page4</code>
 
This example counts how many interactions on page1 that the enduser fills in. If they respond to less than 3 of the interactions they will be directed to page4 of the interaction.
 
== <code> currenttime </code> ==
 
This command instructs the intervention logic to load or save the time as it is at that particular moment. 
 
The <code>currenttime</code> function can be used to create new variables which save the time at which users completed a particular session of the intervention. 
 
'''1.''' In your logic, you will first need to create a new variable (e.g. “username”) which will tell the intervention which particular user a time is being saved for: 
 
<code>set username to login.name</code>
 
<code>if ( not ( isempty ( signup.name ) ) ) set username to signup.name</code>
 
(For this logic to work, you will need to have already created “login”, “signup” pages which contain free text interactions to allow the user to enter their name or other identifier such as an email address – see also [[1.12 set]])
 
'''2.''' Using the “username” variable you have just created, you can then save the time at which each user completes a particular section of your intervention, in this case ‘session 3’: 
 
<code>show session3</code>
 
<code>after session3 if ( savevalue ( username, “session3time”, currenttime ( ) ) )goto session3end</code>
 
<code>show session3end</code>


<code>show page1</code>
Here, the logic instructs the intervention to save the time at the particular moment a user completes the session 3 page.  The saved time is represented as a new variable called <code>"session3time".</code>


<code>set condition1 to and (page1.chooseoptions contains "optiona", page1.chooseoptions contains "optiond")</code>
'''3.''' The <code>currenttime</code> function can also be used as a comparison or reference point.  This is particularly useful if you want to put time controls on when users can access particular sessions of the website (see also [[2.12 comparetimes]]):   


<code>after page1 if condition1 goto page3</code>
<code>after mainpage if ( comparetimes ( loadvalue ( username, "session3time" ), currenttime ( ), "minutes" ) >= 120 ) goto session4</code>  


So in example 2, the variable ‘condition1’ is set if end-users select options a and d from the interaction ‘chooseoptions’ on page1. Then those that are in this condition are sent to page 3 where they will receive tailored information based on the options they selected.
This line tells the intervention that the user can continue to session 4 of the intervention if it has been at least two hours since they completed session 3


'''Example 3'''
<code>after mainpage if ( comparetimes ( loadvalue ( username, "session3time" ), currenttime ( ), "minutes" ) <= 120 ) goto waitpage</code>


In this example, the <code>set</code> key command is used to set a score based on the calculation that follows. In this calculation the number that the end-user selects in the interaction ‘dailyexercise’ on page1 is multiplied by 5 to create their exercise score
This line of logic tells the intervention that the user cannot continue to session 4 because it has been less than two hours since they completed session 3. Users are directed to a “waitpage” instead.


<code>set exercisescore to (page1.dailyexercise * 5)</code>
You may have noticed that the <code>currenttime</code> function is always followed by (). These empty brackets tell the intervention that <code>currenttime</code> should act as a logic function rather than an intervention variable that you have created yourself.


== <code> show </code> ==
=D=


The <code>show</code> key command is the first and most important logic command you will need to know.  It is also probably the most common one that you will use.
== <code> divide </code> ==


This key command shows each of the pages that you have created. Pages will be shown in the order they are mentioned in the logic. When an end-user clicks on a Next button on a page, they will be moved to the next page written in the logic.
The symbol <code>/</code> can also be used. The command <code>divide</code> is used when performing calculations.  


'''Example 1'''
'''Example 1'''


<code>show page1</code>
<code> set score1 to (page1.interaction1 / page1.interaction2)</code>
 
'''score1''' would be the result of dividing the response given in '''interaction1''' by the response given in '''interaction2'''.
 
'''Example 2'''
 
<code> set overallscore to (score1 / score2)</code>
 
In this example, '''overallscore''' is calculated by dividing '''score1''' by '''score2''', where '''score1''' and '''score2''' have already been calculated elsewhere in the logic.
 
=E=


<code>show page2</code>
== <code> end </code> ==


<code>show page3</code>
Please see <code>begin</code> for details of how to use <code>end</code>. The <code>end</code> command is always used with the <code>begin</code> command.


<code>show page4</code>
=F=


In the example above the end-user will first be presented with the page uniquely named ‘page1’. Then, when they click on the next button on page1 they will see the page called ‘page2’. This is followed by ‘page3’ and finally ‘page4’.
== <code> for </code> ==


'''Note:''' Before you can preview your intervention you will need to have the show key command in the logic file for each page you want to view.
The <code>for</code> key command is used with the <code>save</code> and <code>graph</code> key commands.


As the logic requires you to use unique names for each page in your logic, you can only use the show key command once for each page. However, see the <code>named</code> key command above for how to re-show the same page to users.
=G=


You can also reshow pages to your end-user by using a jump button on a previous page.
== <code> getuserid </code> ==


=T=
This function gives you the database ID for a user, which is a number that is unique to each LifeGuide server. This number is automatically generated and can be used to uniquely identify a user without having to refer to their identifier (i.e. username). This number can also be included in your data export by ticking the '''User Number''' box when you export your data.


== <code> timesincelogin </code> ==
'''Example 1'''


This command can be used to show users how much time has passed since they last logged into the intervention.
<code>getuserid(username)</code>


'''Example'''
== <code> goto</code> ==


Using the <code> timesincelogin </code> command involves 3 basic steps: 
The <code>goto</code> command is always used with the <code>after</code> command. It tells the logic which page the user should '''goto''' after that line. See <code>after</code> for details.


'''1.''' In your logic, show the page (e.g. “time”) where you want to display how long it has been since the user last logged into the website: 
== <code> graph </code> ==


<code> show </code> time
The <code>graph</code> key command is used when you have used the graph interaction. It is used to plot the information given by end-users to the graph.


'''2.''' In your logic, create a new variable (e.g. “username”) to tell the intervention, which user, time since login data should be displayed for:
This key command always follows the same formula and requires users to set up a user account.


<code> set </code> username <code> to </code> login.name
<code>graph value to "data variable determined on the graph interaction" for unique_identifier_for_the_end-user_e.g._a_username</code>
<code> if </code> (<code>not</code>(<code>isempty</code> (signup.name))) <code> set </code> username <code> to </code> signup.name


(For this logic to work, you will need to have already created “login” and “signup” pages which contain free text interactions to allow the user to enter their name or other identifier such as an email address – see also [[1.12 set]])
Another line of logic is then needed for the page where the graph occurs. This will also always follow the same formula:


'''3.''' On your “time” page, create a new variable to represent where the time since login data should be displayed to the user (e.g. “secs”).  (This is done using the ‘set as variable’ function).  Then, in your logic, set this variable to display the desired time since login for a particular user, using the <code> timesincelogin </code> command.   
<code>set pagename.graph-1 to graph "data variable determined on the graph interaction" for username</code>


<code> set </code> time.secs to <code> timesincelogin </code> (username, <code> "seconds"</code>)
Here, pagename.graph-1 is the automatically generated name of the graph that has been put on the page where the graph occurs.


So, in this example, on the page named “time” you have shown the user the time in seconds since they last logged into the intervention.
''' Example1'''


The third step can be repeated to show the user the time in “minutes”, ”hours”, “days”, “weeks” or “months” since they last logged into the intervention.
In this example the number entered in the interaction ‘kg’ on the page ‘progresschart’ will be used as the data for the “weight” variable for the graph. The variable username has been set earlier in the logic as the unique identifier for the end-user (see the <code>set</code> key command for more information).


== <code> to </code> ==
<code>show progresschart
graph progresschart.kg to "weight" for username</code>


The <code>to</code> key command is used with the <code>set</code> key command to set variables.
Later in the logic the following line is needed after the page where the graph occurs:


=Commands (pink)=
<code>show weightgraph
set weightgraph.graph-1 to graph "weight" for username</code>


A full tutorial for using graphs will soon be available.


=H=
== <code> hasseen </code> ==
== <code> hasseen </code> ==


Line 356: Line 441:
<code>show s3welcome if (not(hasseen (usernme, "s3welcome")))</code>
<code>show s3welcome if (not(hasseen (usernme, "s3welcome")))</code>


This would mean that the first time they login they would see the session 1 welcome page which is labelled s1welcome. The next time they log in, because they have already seen the s1welcome page the logic will skip that line of logic and show them s2welcome because they have not yet seen the s2welcome page.
This would mean that the first time they login they would see the page '''s1welcome'''. The next time they log in, because they have already seen the '''s1welcome''' page, the logic will skip that line and show '''s2welcome''' because they have not yet seen the '''s2welcome''' page.


If you want the <code>hasseen</code> function to include the pages end-users have seen in the session they are currently in, you will need to add<code>"true"</code> to the line of logic:
'''Example 2'''
 
The hasseen logic can also be used without <code>not</code>, to tailor the intervention for users.
 
For example, you may want to show a page only if an end-user has seen a previous page.
 
<code>show s1_feeback2 if (hasseen (username, "s1_feedback1")))</code>


<code>show s1welcome if (not(hasseen (username, "s1welcome","true")))</code>
<code>show s1_feeback3 if (hasseen (username, "s1_feedback2")))</code>


'''Example 2'''


The hasseen logic can also be used without <code>not</code> to tailor the intervention for users.
===Different ways of using hasseen===
 
You can use the hasseen logic in one of three ways:
 
 
<code> show session2.interaction1 if (hasseen (username, "session1final"))</code>
 
This will show the end-user '''interaction1''' if they have seen '''session1final''' in any session EXCEPT the one they are currently in (i.e. in previous sessions only).
 


For example, you may want to show something on a later page only if an end-user has seen something on a previous one. You can use the hasseen logic in one of three ways depending on when you want it to be seen:
<code> show session2.interaction1 if (hasseen (username, "session1final", "true"))</code>


E.g.  
Adding '''true''' to the hasseen command will show '''interaction1''' if the end-user has seen '''session1final''' in ANY session, INCLUDING the current one.


<code> show sessionspage.session3details if (hasseen (username, "session3final"))</code>


This will show the end-user the session3details text box if they have seen the page called "session3final" in any session but the one they are currently in. In other words they will only be shown this once they have logged in for the next session.
<code> show session2.interaction1 if (hasseen (username, "session1final", "this"))</code>


<code> show sessionspage.session3details if (hasseen (username, "session3final", "this"))</code>
Adding '''this''' to the hasseen command will show '''interaction1''' if the end-user has seen '''session1final''' in the current session ONLY.


By adding "this" into the hasseen command here you can make sure that what you are wishing to show will be shown ONLY in the current session.
=I=


<code> show sessionspage.session3details if (hasseen (username, "session3final", "true"))</code>
== <code> if </code> ==


Adding "true" to the hasseen command enables the person to see this in ALL sessions INCLUDING the current one.
The <code>if</code> command is always used with another command. It is a conditional command so it should always be followed by a true or false statement (i.e. a statement that will be carried out if it is true OR a statement that will be carried out if it is false).


== <code> isempty </code> ==
== <code> isempty </code> ==
Line 398: Line 495:
If the end-user does not enter anything in interaction1 on page1 they would be set to the condition 'none'.
If the end-user does not enter anything in interaction1 on page1 they would be set to the condition 'none'.


== <code> or </code> ==
=L=
 
== <code> load </code> ==
 
Please see the <code>save</code> command for more details. The <code>load </code> command is always used with the save command.


The <code>or</code> command is used in much the same way as the <code>and</code>. It can be used to check if a user has responded in particular ways to an interaction (or number of interactions):
== <code> loadvalue </code> ==


<code> after page1 if (or (page1.interaction1 = "none", page1.interaction1 = "sometimes")) goto page3</code>
The '''loadvalue''' command is always used with the '''savevalue''' command. It loads the value that you have previously saved. Please see the '''savevalue''' command for more details.


== <code> lessthan </code> ==
== <code> lessthan </code> ==


This command can be used when performing calculations in the logic to check if one value is lower than another. The symbol <code><</code> can also be used.  
The symbol <code><</code> can also be used.
 
This command is used when
* performing calculations in the logic to check if one value is lower than another
* comparing time to check if one time occurs before another time (e.g. comparing the current time to the time the previous session was completed to check that one week has passed.
 
'''Example 1'''


<code>set condition1 if (page1.interaction1 < page1.interaction2) </code>
<code>set condition1 if (page1.interaction1 < page1.interaction2) </code>
'''Example 2'''
<code>after login if (comparetimes (loadvalue(username, "session1_time"), currenttime(), "seconds" ) < 86400)</code>


== <code> lessthanequal </code> ==
== <code> lessthanequal </code> ==


This command can be used when performing calculations in the logic to check if one value is lower than or equal to another. The symbol <code> <= </code> can also be used.  
The symbol <code> <= </code> can also be used.
 
This command is used in the same way as '''lessthan'''. It is used when:
 
* performing calculations in the logic to check if one value is lower than another
* comparing time to check if one time occurs before another time (e.g. comparing the current time to the time the previous session was completed to check that one week has passed.
 
'''Example 1'''


<code>set condition1 if (page1.interaction1 <= page1.interaction2) </code>
<code>set condition1 if (page1.interaction1 <= page1.interaction2) </code>


== <code> loadvalue </code> ==
 
'''Example 2'''
 
<code>after login if (comparetimes (loadvalue(username, "session1_time"), currenttime(), "seconds" ) <= 86400)</code>
 
=M=
 


== <code> makenewuser </code> ==
== <code> makenewuser </code> ==


The <code>makenewuser</code> is very important; it is used to set up an [[account]] for the user using a username (or e-mail address) and password.  
The <code>makenewuser</code> command is used to set up an for the end-user using a username (or e-mail address) and password.  


'''Example'''
'''Example'''
Line 428: Line 553:
<code>after signup if (makenewuser(signup.signup_username, signup.signup_password)) goto thankyou</code>
<code>after signup if (makenewuser(signup.signup_username, signup.signup_password)) goto thankyou</code>


So in the example above the information that the end-user enters into the interactions 'signup_username' and 'signup_password' is used to create a user account.  
So in the example above the information that the end-user enters into the interactions 'signup_username' and 'signup_password' is used to create a user account.


== <code> morethan </code> ==
== <code> morethan </code> ==


This command can be used when performing calculations in the logic to check if one value is higher than another. The symbol <code> > </code> can also be used.
The symbol <code> > </code> can also be used.
 
This command is used when performing calculations in the logic to check if one value is higher than another.  
 
'''Example 1'''


<code>set condition2 if (page1.interaction1 > page1.interaction2) </code>
<code>set condition2 if (page1.interaction1 > page1.interaction2) </code>
'''condition2''' will be set if the value selected for '''interaction1''' is greater than the value selected for '''interaction2'''.


== <code> morethanequal </code> ==
== <code> morethanequal </code> ==


This command can be used when performing calculations in the logic to check if one value is higher than or equal to another. The symbol <code> >= </code> can also be used.
The symbol <code> >= </code> can also be used.
 
This command is used when performing calculations in the logic to check if one value is more than or equal to another.
 
'''Example 1'''


<code>set condition2 if (page1.interaction1 >= page1.interaction2) </code>
<code>set condition2 if (page1.interaction1 >= page1.interaction2) </code>
'''condition2''' will be set if '''interaction1''' is greater than or equal to '''interaction2'''.


== <code> multiply </code> ==
== <code> multiply </code> ==


This command can be used when performing calculations to multiply one value by another. The symbol <code> * </code> may also be used. This value may be taken from an end-user's response to an interaction:
The symbol <code> * </code> may also be used.
 
This command is used when performing calculations to multiply one value by another. It may be taken from:
 
* an end-user's response to an interaction
* calculations performed elsewhere in the logic


'''Example 1'''
'''Example 1'''


<code>set score1 to (page1.interaction1 * page1.interaction2)</code>
<code>set score1 to (page1.interaction1 * page1.interaction2)</code>
This is taken from an end-user's response to an interaction. The response to '''interaction1''' is multiplied by the response to '''interaction2''' and set as '''score1'''.


'''Example 2'''
'''Example 2'''


The value may be taken from the calculations performed elsewhere in the logic: E.g.:
<code> set overallscore to (score1 * score2) </code>


<code> set overallscore to (score1 * score2) </code>
This is taken from a calculation performed elsewhere in the logic ('''score1''' and '''score2''' have been '''set''' previously in the logic). '''score1''' is multiplied by '''score2''' and set as '''overallscore'''
 
=N=
 
== <code> named </code> ==
 
This command will re-show a page you have already shown.
 
For example, if you had a page that you need to keep showing back to your end-users, you could use the <code>named</code> command as so (note that in the example below the line [etc, etc] has been used to indicate that there would be other lines of logic here):
 
'''Example 1'''
 
<code>show page1</code>
 
[etc, etc]
 
<code>show page1 named page2</code>
 
[etc, etc]
 
<code>show page1 named page3</code>


== <code> not </code> ==
== <code> not </code> ==
Line 475: Line 639:


<code> set condition1 if (not (isempty (page1.interaction1)))</code>
<code> set condition1 if (not (isempty (page1.interaction1)))</code>
=O=
== <code> or </code> ==
Also written as ||.
The <code>or</code> command is used in the same way as the <code>and</code> command. It can be used to check if a user has responded in a particular way to an interaction (or number of interactions):
'''Example 1'''
<code> after page1 if (or (page1.interaction1 = "none", page1.interaction1 = "sometimes")) goto page3</code>
'''Example 2'''
<code>savevalue(username, "sport", "cardio") if (or( page1.interaction1 = "running", page2.interaction2 = "swimming"</code>
This will save the variable '''sport''' if '''running''' is selected for '''interaction1''' on '''page1''' OR if '''swimming''' is selected for '''interaction2'''on ...page2'''.
=P=


== <code> patternmatch </code> ==
== <code> patternmatch </code> ==


The <code>patternmatch</code> function can be used when you require users to enter a specific combination of characters into a text entry interaction. The <code> patternmatch</code> function will check if the string entered by the user matches a pre-defined pattern of characters.
The <code>patternmatch</code> command is used when users are required to enter a specific combination of characters into a text entry interaction, e.g. a study code. The logic <code>patternmatch(characters,interactionname)</code> will check if the characters entered by the user, match the characters that you have pre-defined.
 
<code>Patternmatch</code> uses "Regular Expressions" to define a pattern of characters. Some basics are described below but for more detailed information, you can find guides to "Regular Expressions" on the Internet.
 
{| class="wikitable"
!Character !! Example !! Comment
|-
|a
|a
|match a single lower-case character. Can be any character except <code>.?+*[]\^$()&#124;{}</code>
|-
|A
|A
|match a single upper-case character.
|-
|abc
|abc
|match the exact sequence of characters
|-
|.
|a
|. means any character
|-
|a?
|a
|? means zero or one of the preceding character
|-
|a*
|aaa
| * means any number of the preceding character
|-
|a+
|aaaa
| + means one or more of the preceding character
|-
|[abc]+
|cab
|[] means any character between the brackets
|-
|[^abc]+
|fed
|^ in a [] means none of the characters between the brackets
|-
|[0-9]
|1
|match any number between this range
|-
|[A-Z]
|LIFEGUIDE
|match any uppercase letter between this range
|-
|[a-z]
|lifeguide
|match any lowercase letter between this range
|-
|[A-Za-z]+
|LifeGuide
|Any uppercase or lowercase letters
|-
|a(bc)+d
|abcbcbcd
|() groups things together
|-
|ab&#124;cd
|cd
|&#124; means 'or'
|}


'''Example 1'''
'''Example 1'''
Line 484: Line 732:
This function may be useful if you have assigned each participant in your study a different code which they will need to enter in order to take part.  This will ensure that only users who have been invited to use the intervention can gain access to it.  To do this, you will need to write an error message on the page which contains your text entry interaction e.g.         
This function may be useful if you have assigned each participant in your study a different code which they will need to enter in order to take part.  This will ensure that only users who have been invited to use the intervention can gain access to it.  To do this, you will need to write an error message on the page which contains your text entry interaction e.g.         


<code> Show nomatch if( not( patternmatch( “study[0-9][0-9][id][0-9][0-9]”, password ) ) ) </code>
<code> Show nomatch if( not( patternmatch( “study[0-9][0-9]id[0-9][0-9]”, password ) ) ) </code>


In this example, the error message named '''nomatch''' will be shown to users if they enter a string of characters in the text entry interaction named '''password''' which does not fit with the pattern specified in the square brackets.   
In this example, the error message named '''nomatch''' will be shown to users if they enter a string of characters in the text entry interaction named '''password''' which does not fit with the pattern specified in the square brackets.   
Line 496: Line 744:
The <code>patternmatch</code> function could also be used to direct users to specific conditions, sections or pages within an intervention e.g.  
The <code>patternmatch</code> function could also be used to direct users to specific conditions, sections or pages within an intervention e.g.  


<code> show page1 if (patternmatch(“[0-9][0-9][a][0-9][0-9]”, interaction1)) </code>
<code> show page1 if (patternmatch(“[0-9][0-9]a[0-9][0-9]”, interaction1)) </code>


<code> show page2 if (patternmatch(“[0-9][0-9][b][0-9][0-9]”, interaction1)) </code>
<code> show page2 if (patternmatch(“[0-9][0-9]b[0-9][0-9]”, interaction1)) </code>


In this example, if users enter the string xx'''a'''xx, where x represents a number between 0 and 9 they will see '''page 1''' of the intervention.  If they enter the string xx'''b'''xx they will see '''page 2''' of the intervention.   
In this example, if users enter the string xx'''a'''xx, where x represents a number between 0 and 9 they will see '''page 1''' of the intervention.  If they enter the string xx'''b'''xx they will see '''page 2''' of the intervention.   
Line 505: Line 753:
Instead of 0-9, you could use [a-z], which means the user will need to enter any letter between a and z in the alphabet.  You could also specify [a-z0-9] – this will mean the user will need to enter either a letter or a number.       
Instead of 0-9, you could use [a-z], which means the user will need to enter any letter between a and z in the alphabet.  You could also specify [a-z0-9] – this will mean the user will need to enter either a letter or a number.       


Please note that the <code> patternmatch </code>function is '''case sensitive'''.  If you specify '''[a-z]''', the user will need to enter a '''lowercase''' letter.  If you specify '''[A-Z]''', the user will need to enter an '''uppercase''' letter.  If you specify '''[a-zA-Z]''' the user may enter '''either an uppercase or a lower case letter'''.
NB The <code> patternmatch </code>function is '''case sensitive'''.  If you specify '''[a-z]''', the user will need to enter a '''lowercase''' letter.  If you specify '''[A-Z]''', the user will need to enter an '''uppercase''' letter.  If you specify '''[a-zA-Z]''' the user may enter '''either an uppercase or a lower case letter'''.


== <code> printtime </code> ==
== <code> printtime </code> ==
Line 523: Line 771:
'''Example 2'''
'''Example 2'''


This example shows how you can use the <code>printtime</code> function to display particular times or dates which you have saved in your intervention logic, such as the time/date a user signed up for the intervention and the time/date they logged back into the intervention.  
This example shows how you can use the <code>printtime</code> function to display particular times or dates that you have saved in your intervention logic, such as the time/date a user signed up for the intervention and the time/date they logged back into the intervention.
 


<code>show signup</code>
<code>show signup</code>
Line 552: Line 801:


This logic tells the intervention to display the time a particular user first signed up to the intervention <code>("lastlogintime"</code>) and the time they logged back into the intervention <code>("currentlogintime"</code>) in place of the words ‘lastlogintime’ and ‘currentlogintime’.
This logic tells the intervention to display the time a particular user first signed up to the intervention <code>("lastlogintime"</code>) and the time they logged back into the intervention <code>("currentlogintime"</code>) in place of the words ‘lastlogintime’ and ‘currentlogintime’.
=R=


== <code> randomnumber </code> ==
== <code> randomnumber </code> ==
Line 573: Line 824:
== <code> replaceall </code> ==
== <code> replaceall </code> ==


This command can be used to do text replacements inside a string.
This command replaces text in a string.
 
'''Example 1'''
 
<code>replaceall ("c", "b", "caked car")</code>
 
This would replace all the '''c's''' in the string to '''b's'''. So this would change '''caked car''' to '''baked bar'''.
 
'''Example 2'''
 
Workaround for showing responses to a single-choice interaction back to the user. The reason for this is that the '''Unique Response Name''' (not the Response text) is saved and this will be shown to the user when a single-choice drop-down interaction is used.
 
<code>savevalue (username, "s1_home", replaceall("_", " ", s1_whattodo1.home)) if (or( s1_fatigue.home = "Other_aspects_of_home_life", s1_fatigue.home = "I_find_it_hard_doing_things_around_the_house",s1_fatigue.home = "I_cannot_get_out_and_about_the_way_I_used_to" ))</code>


'''Example'''
This example is specific to a drop-down single-choice interaction, where you want to show the response selected for the interaction '''home''' on page '''s1_fatigue''' back to the end-user. All of the '''_''' in each '''Unique Reponse Name''' in the interaction will be replaced with a space, which you can show back to your user.
 
You can then use feedback boxes and a container to show the responses on a later page:


In the following example the <code>replaceall</code> command is used to replace all the 'a's in a string to 'b's. So this would change 'I like apples a lot' to 'I like bpples b lot'
<code>show s1_fatigue2.home1 if (s1_fatigue.home = "Other_aspects_of_home_life")
show s1_fatigue2.home2 if (s1_fatigue.home = "I_find_it_hard_doing_things_around_the_house"
show s1_fatigue2.home3 if (s1_fatigue.home = "I_cannot_get_out_and_about_the_way_I_used_to"</code>


<code>replaceall ("a", "b", "I like apples a lot")</code>
'''home1''' is a feedback textbox which will be shown on '''s1_fatigue2''' if '''Other_aspects_of_home_life''' was chosen for the interaction '''home''' on page '''s1_fatigue'''.


== <code> resetpassword </code> ==
== <code> resetpassword </code> ==
=S=
== <code> save </code> ==
The <code> save </code> key command allows you to save the responses that an end-user enters on a page. This can then be loaded using the <code> load </code> key command onto another page to re-show it to your end-user. The save and load commands can be used across sessions and requires end-users to have registered a user account.
Example:
<code> show page1</code>
<code> save page1 for username</code>
Then, later on in the logic (either in the same session or a later session) the following logic would be used:
<code> show page20</code>
<code> set default page20.interaction2 to load page1.interaction1 for username</code>
So, in the first part of this logic page1 is saved for the end-user. Then when they get to page20 in the intervention the response that they entered on interaction1 on page1 will be reshown to them on interaction2 on page20.
== <code> saveandload </code> ==
This command is used after a page that contains interactions. If an end-user clicks on a '''next''' button on that page and then returns to it, the page will automatically show them the responses they entered the last time they saw that page.
'''Example 1'''
<code>show page1
saveandload page1 for username</code>
Any interaction on page1 will be saved and loaded each time the end-user comes back to that page.
== <code> set </code> ==
The <code>set</code> key command can be used to set variables within the logic or for performing calculations.
'''Example 1'''
The most common use of setting variables will be to set a username for the user. Many of the logic commands such as <code>save</code> will need a username to be set. This will need to be done at the start of your logic file.
<code>Set username to login.loginuname</code>
This will set the variable '''username''' to whatever the end-user enters into the interaction uniquely named '''loginuname''' (usually an email address) on the login page. The word '''username''' can then be used any time throughout the logic to refer to the text an end-user entered into that interaction.
'''Example 2'''
You can '''set''' timings in your logic. Setting timings means you can change the timings for testing and change them back again to real-time easily,  and it reduces the likelihood of mistakes being made.
In this example, '''twelvemonth''' has been set to the number of seconds in 12 months:
<code>set twelvemonth to "31536000"</code>
You can then use this in your login logic as follows:
<code>after login if (comparetimes(loadvalue(username,"baselinetime"), currenttime(),"seconds") >= twelvemonth) goto studyfinished </code>
The above logic will show the page '''studyfinished''' if it has been more than 12 months since '''baselinelinetime'''.
'''Example 3'''
You can '''set''' text such as an email address to avoid having to type it out each time, e.g. the study coordinator's email address:
<code>set studyemail to "study@soton.ac.uk" </code>
This logic should appear near the top of your logic file. An advantage to using this function this way is that if you decide to change the study coordinator's email address, you only have to change it once (where you '''set''' it).
You can also '''set''' the text and timings in emails:
<code>set 3monthemail to "Thank you for taking part in The Reactivate Study. It is now time to complete your 3 month questionnaire. Your answers are very important to us. Please use the following link to login:\n\nwww.webaddress.co.uk\n\nIf you have any questions about the study, or no longer wish to participate, please contact us on study@soton.ac.uk\n\nFrom The Reactivate Team."</code>
<code>set oneday to "86400"
set oneweek to ""604800"</code>
The advantages to setting text in emails are:
* They can be changed easily as you only have to change one line instead of multiple lines throughout your logic. It's common to overlook vital lines if you have many lines of logic and setting text reduces the likelihood of mistakes being made.
* The lines are easy to find as they are placed at the top of the logic file.
Please see the command <code>sendemail</code> for more information on how to write email logic.
'''Example 3'''
The <code>set</code> key command can also be used to set a variable based on how end-users respond to certain interactions. This can then be used to tailor the intervention based on this variable.
<code>show page1</code>
<code>set condition1 to and (page1.chooseoptions contains "optiona", page1.chooseoptions contains "optionc")</code>
<code>after page1 if condition1 goto page3</code>
So in example 2, the variable '''condition1''' is set if end-users select '''optiona''' and '''optionc''' from the interaction '''chooseoptions''' on '''page1'''. Then those that are in this condition are sent to page 3 where they will receive tailored information based on the options they selected.
'''Example 4'''
In this example, the <code>set</code> key command is used to set a score based on the calculation that follows. In this calculation the number that the end-user selects in the interaction ‘dailyexercise’ on page1 is multiplied by 5 to create their exercise score
<code>set exercisescore to (page1.dailyexercise * 5)</code>
== <code> saveuniquevalue </code> ==
The saveuniquevalue function is used in the same way as the '''savevalue''' function. The only difference is that with '''saveuniquevalue''', if the value entered by an end-user is not unique, the function will return a 'false' input, and you can use this to stop end-users continuing with the intervention until they have entered a value which is unique.


== <code> savevalue </code> ==
== <code> savevalue </code> ==


The savevalue command allows you to save a variable for a username that can then be loaded again in later sessions.
The '''savevalue''' command saves a variable that can be loaded again in later sessions. It is used if users have to create an account to access your intervention and you want to save information to a user.
 
It can be used to:
* create a variable and save it to a user
* save a response a user has given to an interaction
* save the time
* save a questionnaire or session as 'complete'
 
 
'''Example 1 - Create a variable and save it to a user'''
 
<code>savevalue(username, "group", "web_support")</code>
 
This will save the variable '''web_support''' for a username. '''group''' will be the column heading in your data.
 
When loading this value later in your logic, you will use the command <code>loadvalue</code>, and the variables you have created - '''group''' and '''web_support''':
 
<code>after page5 if (loadvalue(username, "group") = "web_support") goto page10</code>
 
 
'''Example 2 - save a response a user has given to an interaction'''
 
<code>savevalue(username, "s1_fatigue", page1.interaction1)</code>
 
This will save the response given to '''interaction1''' on '''page1''' to the variable '''s1_fatigue''' for the username.
 
To load this later in your logic, you would use the variable name '''s1_fatigue''':
 
<code>set page5.fatigue_score to loadvalue (username,"s1_fatigue")</code>
 
This will load the variable '''s1_fatigue''' and will show it in the text box '''fatigue_score''' on '''page5'''. For this to function correctly, '''fatigue_score''' needs to be [[How to set text as a variable| set as a variable]].
 
 
'''Example 3 - save the time'''
 
<code>savevalue(username, "s1_time", currenttime())</code>
 
This will save the current time as '''s1_time'''.
 
You can load this later in your logic to ensure that end-users do not see session 2 until 1 week later:
 
<code>after login_successful if (comparetimes(loadvalue(username, "s1_time"), currenttime(), "seconds" ) > 604800) goto s2_welcome</code>
 
 
'''Example 4 - save a questionnaire or session as complete'''
 
<code>savevalue(username, "baselinecomplete", "yes")</code>
 
This will create the variable '''baselinecomplete''' and will save it as '''yes'''. In this example, you can use a number instead of '''yes'''.
 
You can load this in your logic to check that an end-user has completed their baseline questionnaire:
 
<code>after login_successful if (and( hasseen(username, "qintro"), (isempty(loadvalue(username, "baselinecomplete"))) )) goto q_notcomplete </code>
 
This will show the page '''q_notcomplete''' if the end-user has seen '''qintro''', but the variable '''baselinecomplete''' is empty (because the baseline questionnaire has not yet been completed).


== <code> sendemail </code> ==
== <code> sendemail </code> ==
Line 626: Line 1,046:
== <code> sum </code> ==
== <code> sum </code> ==


See <code>add</code>
Please see <code>add</code>
 
== <code> show </code> ==
 
The <code>show</code> command is the first logic command you will need to know.  It is also probably the most common one that you will use.
 
This command shows each of the pages you have created. Pages will be shown in the order they are written in the logic. When an end-user clicks on a Next button on a page, they will be moved to the next page written in the logic.
 
'''Example 1'''
 
<code>show page1
 
show page2
 
show page3
 
show page4</code>
 
In the example above, the end-user will be shown the page named ‘page1’. When they click on the next button on '''page1''', they will see the page called ''page2’''. This is followed by ‘''page3’'' and finally ‘''page4’''.
 
'''NB Before you can preview your intervention, you will need to have the '''show''' command in the logic file for each page you want to view.'''
 
As the logic requires you to use unique names for each page in your logic, you can only use the '''show''' command once for each page. However, you can re-show the same page to users - see the <code>named</code> command above for more details.
 
You can also reshow pages to your end-user by using a jump button on a previous page.
 
=T=
 
== <code> timesincelogin </code> ==
 
This command can be used to show users how much time has passed since they last logged into the intervention.
 
'''Example'''
 
Using the <code> timesincelogin </code> command involves 3 basic steps: 
 
'''1.''' In your logic, show the page (e.g. “time”) where you want to display how long it has been since the user last logged into the website: 
 
<code> show </code> time
 
'''2.''' In your logic, create a new variable (e.g. “username”) to tell the intervention, which user, time since login data should be displayed for:
 
<code> set </code> username <code> to </code> login.name
<code> if </code> (<code>not</code>(<code>isempty</code> (signup.name))) <code> set </code> username <code> to </code> signup.name
 
(For this logic to work, you will need to have already created “login” and “signup” pages which contain free text interactions to allow the user to enter their name or other identifier such as an email address – see also [[1.12 set]])
 
'''3.''' On your “time” page, create a new variable to represent where the time since login data should be displayed to the user (e.g. “secs”).  (This is done using the ‘set as variable’ function).  Then, in your logic, set this variable to display the desired time since login for a particular user, using the <code> timesincelogin </code> command.   
 
<code> set </code> time.secs to <code> timesincelogin </code> (username, <code> "seconds"</code>)
 
So, in this example, on the page named “time” you have shown the user the time in seconds since they last logged into the intervention.
 
The third step can be repeated to show the user the time in “minutes”, ”hours”, “days”, “weeks” or “months” since they last logged into the intervention.
 
== <code> to </code> ==
 
The <code>to</code> key command is used with the <code>set</code> key command to set variables.
 
=U=
 
== <code> urlencode </code> ==
 
<code> urlencode(string) </code>
 
This returns a URL encoded version of a string. <code>urlencode</code> should be used only when creating a dynamic URL (i.e. using a variable). It is used when  the variable might contain non alphanumeric characters. It converts a string into the correct format to prevent usual characters from breaking the link. This is because certain characters (such as ? and &) have special functions when included in a URL and have to be encoded in a different format (e.g. the & symbol gets converted to %26).
 
URL encoding is common and you will find more information here: http://en.wikipedia.org/wiki/Percent-encoding

Latest revision as of 13:48, 1 October 2014

A quick reference guide to LifeGuide logic. For more detailed information, please refer to the How to... Guide

A

add

This may also be written as sum or +. The add command is used when performing calculations in the logic.

Example 1

This can be used to perform a calculation using the end-user's responses to specific numeric value interactions:

set score1 to add (page1.interaction1, page1.interaction2, page1.interaction3)

Example 2

The add or sum commands can also be used to calculate variables that have been set earlier in the session:

set overallscore to add (score1, score2, score3)

after

The after command is used after a page to perform functions that relate to that page.

It is likely that you will use this command quite regularly in your intervention logic. The most common way of using the after command is with the if and goto commands, e.g.

show page1

after page1 if (any_commands_you_want_to_relate_to_this_page) goto page3

Example 1

after page1 if (page1.interaction1 = "yes") goto page3 show page 2 show page3

In the above example, the end-user will be directed to page3 if they have answered yes to interaction1 on page1. If they answer no to interaction1, they will be directed to the next line of logic and will see page2.

NB If you use the after command with the goto command, the page that you goto should NOT be the next page shown in your logic, it should be a page further down in your logic as in the example above.

As will be seen throughout this dictionary, any command can be used with the after command.

and

Can also be written as &&.

The and command can be used for a number of reasons:

  1. If there is more than one response that is involved in presenting tailored advice to end-users, i.e. if one response and another response is needed to show feedback to an end-user.
  2. If you need to perform a number of logic commands after a page

Example 1

show page6 if (and(page3.exercise = "yes", page3.intensity = "moderate", page3.frequency = "three"))

End-users will be shown page6 if they selected yes to the interaction exercise on page3, moderate to the interaction intensity on page3 and three to the interaction frequency on page3.


Example 2

after login_successful if (and( not(hasseen(username, "q_demographics")), (isempty (loadvalue(username, "baselinecomplete"))) )) goto q_intro

End-users will be shown q_intro if they have not seen page q_demographics and if the variable baselinecomplete is empty (i.e. the variable baselinecomplete hasn't been saved because the end-user hasn't finished the baseline questionnaire).

append

The append command allows you to attach strings of logic together or to attach a variable within a string.

Example 1

sendemail (append(username,"email_session1"),username,"StressLess - Session 1 is ready", append("Dear ", loadvalue (username, "personsname"), "\n\n", session1_email), 10)

In this example append is used to attach:

  • a username (which has been set in a previous part of the logic) to the unique name of the email message
  • a user's name to the text used in an email message. The append function here allows the content of the email message to be made of different parts.

The \n\n in the logic above means a new line in the email message content.

authenticateuser

This is important logic for ensuring that a user is registered with the intervention and is usually found after the login page.

The authenticateuser command can be used in the logic (intervention.lgil) file or in the error message logic.

Example

after login if (authenticateuser (login.username, login.password)) goto page1

So in the example above, the details that the end-user enters into the username and password interactions on the login page will be used to check that they are a registered user.

B

begin

The begin key command is always used with the end key command

If your intervention has separate sessions or groups (e.g. different weekly sessions in your behavioural intervention, or a different set of pages for different user groups) then splitting your pages into sections can make it easier for you to organise parts of your intervention and find sections easily.

Things to remember when splitting you intervention into sections:

  • If you begin a section, you should always end the section.
  • All the logic related to the section must be between begin and end
  • The name of the section should not be the same as any unique name that has been given to an object or page in your intervention.
  • As you can only ever end the section that you are currently in, you do not need to write the section name after end.

Example 1

begin session1

show page1

show page2

end

This will begin session1, show page1 and page2, and will end session1. All the pages related to session1 (page1 and page2) are between begin session1 and end.

Example 2 – Beginning and ending a section within another section

begin stress

begin causes

show page1

show page2

end

begin relieve

show page3

show page4

end

end

This will begin the section stress. The section causes will then begin and page1 and page2 in the section causes will be shown. The first end will end the section causes. The section relieve will then begin and page3 and page4 will be shown. The next end will end the section relieve. The final end will end the section stress.

C

cancelemail

Used to cancel an email that has been set up earlier in the logic.

You may want to:

  • cancel emails to end-users (e.g. if you set up email reminders for end-users to login to upcoming sessions, you will need to cancel them if they login before the email is due to be sent.
  • cancel emails to the study coordinator (e.g. if you set up email reminders to notify the study coordinator when end-users do not complete study questionnaires, you will need to cancel them if they complete the questionnaires.

This command uses the same basic formula:

after pagename if cancelemail ("unique name for email", e-mail address) goto nextpage

Example 1

cancelemail(append(username, "email_session2r"), username)

This will cancel the email email_session2r for an end-user. The append function links an end-user's username to the name of the email (email_session2r) to give each email a unique name.

Example 2

cancelemail(append(username,"q1_notcomplete"), "study@test.ac.uk")

This will cancel the email q1_notcomplete that was due to be sent to study@test.ac.uk. The append function links an end-users username to the name of the email (q1_notcompleteto) to give each email a unique name.

cancelsms

This command cancels an SMS message that has already been set up earlier on in the logic.

It uses a similar basic formula that is used for cancelling emails except it uses the cancelsms command and a phone number:

after pagename if cancelsms ("unique name for sms message", phonenumber) goto nextpage

changepassword

Enables end-users to change their password.

Please see the LifeGuide Community Website for a tutorial intervention that shows how to create the pages and write the logic for this.

Example 1

after passworddetails if changepassword (username, passworddetails.old, passworddetails.new) goto confirmchange

This will allow a password to be changed if the old password is correctly entered into the interaction called old on page passworddetails, and a new password is entered into the interaction called new on page passworddetails.

checkemailvalidity

Checks that the e-mail address a user has entered contains an @ symbol.

This command is used with an error message and is written in the Error Messages tab (please refer to Adding Error Messages for information about writing error messages).

Example 1

show invalidemail if (not (checkemailvalidity (email)))

invalidemail is the name of an error message and email is the name of the interaction on this page where the end-user would enter their e-mail address.

checkphonenumbervalidity

Checks that the mobile number a user has entered begins with +44 or '0.

This command is used with an error message (please see Adding error messages for more information.

Example 1

show invalidnumber if (not (checkphonenumbervalidity (phone)))

In this example invalidnumber is the name of the error message and phone is the name of the interaction on this page where the end-user would enter their phone number.

Please note that this logic is only set up to work with UK based numbers. Researchers will need to create their own error messages to check the correct numbers are entered for international numbers.

checkuserenabled

checkuserexists

This command would check whether an email address or username has already been registered for the intervention (i.e. if the details that have been entered is already registered with another user). This command is often used with an error message (please refer to the researcher help manual for details of writing error messages).

Example

show registeredemail if (checkuserexists (email))

In this example registeredemail is the name of the error message that would show if what they person enters in the 'email' interaction has already been registered.

comparetimes

This command can be used to compare two points in time.

Example 1

This example shows how comparetimes can be used to control users’ access to different sessions or pages within an intervention.


In your logic, you will first need to create a new variable (e.g. "username") which will tell the intervention which user times need to be compared for:

set username to login.name

if ( not ( isempty ( signup.name ) ) ) set username to signup.name

(For this logic to work, you will need to have already created “login” and “signup” pages which contain free text interactions to allow the user to enter their name or other identifier such as an email address – see also 1.12 set)


The order of your logic is very important when using the comparetimes function:


1. You first need to show the page users see before they are directed to particular sessions (e.g. "mainpage"):

show mainpage


2. Using the comparetimes function you now need to write the logic which directs the user to a particular session or page of the intervention:

after mainpage if ( comparetimes ( loadvalue ( username, "session4time") , currenttime ( ), "seconds" ) >= 120 ) goto endpage

This tells the intervention that the user can continue to the end of the website if the difference between the current time, and the time the user completed session4, is more than or equal to two minutes. “seconds” may be replaced by “minutes”, “hours”, “days”, “weeks” or “months” (Don’t forget to end each with an ‘s’!)


after mainpage if ( comparetimes ( loadvalue ( username, "session3time" ), currenttime ( ), "seconds" ) >= 120 ) goto session4

This line tells the intervention that the user can continue to session4 of the intervention if it has been at least two minutes since they completed session3


after mainpage if ( comparetimes ( loadvalue ( username, "session3time" ), currenttime ( ), "seconds" ) <= 120 ) goto waitpage

This line of logic tells the intervention that the user cannot continue to session 4 because it has been less than two minutes since they completed session 3. Users are directed to a “waitpage” instead.

Repeat this process for the various sessions or pages contained within your intervention, for which you want to control access. The variables "session3time" and "session4time" are created in step 3.


3. Finally, using the show function you need to display the individual pages or sessions of your intervention, e.g.:

show waitpage

show session3

after session3 if ( savevalue ( username, “session3time”, currenttime ( ) ) )goto session3end

show session3end

Using the currenttime function (see 2.15 currenttime), this logic instructs the intervention to save a new variable “session3time”. This new variable records the time at which the user completed session3.

So, in this example, the intervention compares the time at which the user completed a given section of the intervention, with the current time, to determine whether enough time has elapsed to allow them to continue on to the next session.

contains

Used with multiple-choice interactions. It is used to show tailored information based on a specific response an end-user has given.

Example 1

after page1 if (page1.exercise contains "none") goto page4

In this example, the end-user will be directed to page4 if they had selected none to the interaction exercise on page1.


Example 2

after page1 if (or( page1.exercise contains "1day", page1.exercise contains "2days" )) goto page4

An end-user will be shown page4 if they selected 1day or 2days to the interaction exercise on page1.

countif

This command can be used to count how many interactions an end-user has filled in.

Example

after page1 if (countif (not (isempty (page1.interaction1))), (not (isempty (page1.interaction2))), (not (isempty (page1.interaction3))), (not (isempty (page1.interaction4)))) <3) goto page4

This example counts how many interactions on page1 that the enduser fills in. If they respond to less than 3 of the interactions they will be directed to page4 of the interaction.

currenttime

This command instructs the intervention logic to load or save the time as it is at that particular moment.

The currenttime function can be used to create new variables which save the time at which users completed a particular session of the intervention.

1. In your logic, you will first need to create a new variable (e.g. “username”) which will tell the intervention which particular user a time is being saved for:

set username to login.name

if ( not ( isempty ( signup.name ) ) ) set username to signup.name

(For this logic to work, you will need to have already created “login”, “signup” pages which contain free text interactions to allow the user to enter their name or other identifier such as an email address – see also 1.12 set)

2. Using the “username” variable you have just created, you can then save the time at which each user completes a particular section of your intervention, in this case ‘session 3’:

show session3

after session3 if ( savevalue ( username, “session3time”, currenttime ( ) ) )goto session3end

show session3end

Here, the logic instructs the intervention to save the time at the particular moment a user completes the session 3 page. The saved time is represented as a new variable called "session3time".

3. The currenttime function can also be used as a comparison or reference point. This is particularly useful if you want to put time controls on when users can access particular sessions of the website (see also 2.12 comparetimes):

after mainpage if ( comparetimes ( loadvalue ( username, "session3time" ), currenttime ( ), "minutes" ) >= 120 ) goto session4

This line tells the intervention that the user can continue to session 4 of the intervention if it has been at least two hours since they completed session 3

after mainpage if ( comparetimes ( loadvalue ( username, "session3time" ), currenttime ( ), "minutes" ) <= 120 ) goto waitpage

This line of logic tells the intervention that the user cannot continue to session 4 because it has been less than two hours since they completed session 3. Users are directed to a “waitpage” instead.

You may have noticed that the currenttime function is always followed by (). These empty brackets tell the intervention that currenttime should act as a logic function rather than an intervention variable that you have created yourself.

D

divide

The symbol / can also be used. The command divide is used when performing calculations.

Example 1

set score1 to (page1.interaction1 / page1.interaction2)

score1 would be the result of dividing the response given in interaction1 by the response given in interaction2.

Example 2

set overallscore to (score1 / score2)

In this example, overallscore is calculated by dividing score1 by score2, where score1 and score2 have already been calculated elsewhere in the logic.

E

end

Please see begin for details of how to use end. The end command is always used with the begin command.

F

for

The for key command is used with the save and graph key commands.

G

getuserid

This function gives you the database ID for a user, which is a number that is unique to each LifeGuide server. This number is automatically generated and can be used to uniquely identify a user without having to refer to their identifier (i.e. username). This number can also be included in your data export by ticking the User Number box when you export your data.

Example 1

getuserid(username)

goto

The goto command is always used with the after command. It tells the logic which page the user should goto after that line. See after for details.

graph

The graph key command is used when you have used the graph interaction. It is used to plot the information given by end-users to the graph.

This key command always follows the same formula and requires users to set up a user account.

graph value to "data variable determined on the graph interaction" for unique_identifier_for_the_end-user_e.g._a_username

Another line of logic is then needed for the page where the graph occurs. This will also always follow the same formula:

set pagename.graph-1 to graph "data variable determined on the graph interaction" for username

Here, pagename.graph-1 is the automatically generated name of the graph that has been put on the page where the graph occurs.

Example1

In this example the number entered in the interaction ‘kg’ on the page ‘progresschart’ will be used as the data for the “weight” variable for the graph. The variable username has been set earlier in the logic as the unique identifier for the end-user (see the set key command for more information).

show progresschart graph progresschart.kg to "weight" for username

Later in the logic the following line is needed after the page where the graph occurs:

show weightgraph set weightgraph.graph-1 to graph "weight" for username

A full tutorial for using graphs will soon be available.

H

hasseen

hasseen is used to show end-users pages based on what they have or have not seen before.

Example 1

If you wanted to show end-users a different page each time they logged in depending on what sessions they had seen before you may use the hasseen command like so:

show login

show s1welcome if (not(hasseen (username, "s1welcome")))

show s2welcome if (not(hasseen (username, "s2welcome")))

show s3welcome if (not(hasseen (usernme, "s3welcome")))

This would mean that the first time they login they would see the page s1welcome. The next time they log in, because they have already seen the s1welcome page, the logic will skip that line and show s2welcome because they have not yet seen the s2welcome page.

Example 2

The hasseen logic can also be used without not, to tailor the intervention for users.

For example, you may want to show a page only if an end-user has seen a previous page.

show s1_feeback2 if (hasseen (username, "s1_feedback1")))

show s1_feeback3 if (hasseen (username, "s1_feedback2")))


Different ways of using hasseen

You can use the hasseen logic in one of three ways:


show session2.interaction1 if (hasseen (username, "session1final"))

This will show the end-user interaction1 if they have seen session1final in any session EXCEPT the one they are currently in (i.e. in previous sessions only).


show session2.interaction1 if (hasseen (username, "session1final", "true"))

Adding true to the hasseen command will show interaction1 if the end-user has seen session1final in ANY session, INCLUDING the current one.


show session2.interaction1 if (hasseen (username, "session1final", "this"))

Adding this to the hasseen command will show interaction1 if the end-user has seen session1final in the current session ONLY.

I

if

The if command is always used with another command. It is a conditional command so it should always be followed by a true or false statement (i.e. a statement that will be carried out if it is true OR a statement that will be carried out if it is false).

isempty

This command checks if an interaction is empty.

Example1

after page1 if (isempty (page1.interaction1)) goto page4

The end-user would be directed to page4 if they did not enter anything in interaction1 on page1.

Example2

set none if (isempty (page1.interaction1))

If the end-user does not enter anything in interaction1 on page1 they would be set to the condition 'none'.

L

load

Please see the save command for more details. The load command is always used with the save command.

loadvalue

The loadvalue command is always used with the savevalue command. It loads the value that you have previously saved. Please see the savevalue command for more details.

lessthan

The symbol < can also be used.

This command is used when

  • performing calculations in the logic to check if one value is lower than another
  • comparing time to check if one time occurs before another time (e.g. comparing the current time to the time the previous session was completed to check that one week has passed.

Example 1

set condition1 if (page1.interaction1 < page1.interaction2)


Example 2

after login if (comparetimes (loadvalue(username, "session1_time"), currenttime(), "seconds" ) < 86400)

lessthanequal

The symbol <= can also be used.

This command is used in the same way as lessthan. It is used when:

  • performing calculations in the logic to check if one value is lower than another
  • comparing time to check if one time occurs before another time (e.g. comparing the current time to the time the previous session was completed to check that one week has passed.

Example 1

set condition1 if (page1.interaction1 <= page1.interaction2)


Example 2

after login if (comparetimes (loadvalue(username, "session1_time"), currenttime(), "seconds" ) <= 86400)

M

makenewuser

The makenewuser command is used to set up an for the end-user using a username (or e-mail address) and password.

Example

show signup

after signup if (makenewuser(signup.signup_username, signup.signup_password)) goto thankyou

So in the example above the information that the end-user enters into the interactions 'signup_username' and 'signup_password' is used to create a user account.

morethan

The symbol > can also be used.

This command is used when performing calculations in the logic to check if one value is higher than another.

Example 1

set condition2 if (page1.interaction1 > page1.interaction2)

condition2 will be set if the value selected for interaction1 is greater than the value selected for interaction2.

morethanequal

The symbol >= can also be used.

This command is used when performing calculations in the logic to check if one value is more than or equal to another.

Example 1

set condition2 if (page1.interaction1 >= page1.interaction2)

condition2 will be set if interaction1 is greater than or equal to interaction2.

multiply

The symbol * may also be used.

This command is used when performing calculations to multiply one value by another. It may be taken from:

  • an end-user's response to an interaction
  • calculations performed elsewhere in the logic

Example 1

set score1 to (page1.interaction1 * page1.interaction2)

This is taken from an end-user's response to an interaction. The response to interaction1 is multiplied by the response to interaction2 and set as score1.

Example 2

set overallscore to (score1 * score2)

This is taken from a calculation performed elsewhere in the logic (score1 and score2 have been set previously in the logic). score1 is multiplied by score2 and set as overallscore

N

named

This command will re-show a page you have already shown.

For example, if you had a page that you need to keep showing back to your end-users, you could use the named command as so (note that in the example below the line [etc, etc] has been used to indicate that there would be other lines of logic here):

Example 1

show page1

[etc, etc]

show page1 named page2

[etc, etc]

show page1 named page3

not

The not command is used to refer to a response which had not been selected.

Example 1

set condition1 if (not (page1.interaction1 = "yes"))

So condition1 would be set for this user if they did not select the "yes" response in interaction1. We can then use this condition to tailor the rest of the intervention that the end-user sees.

Note: Do not confuse the not command with the isempty command. not is used to refer to a specific response to an interaction that has not been chosen. isempty is used to refer to an interaction that an end-user has not answered.

not and isempty can be used together to refer to an interaction that is not empty (i.e. something has been entered).

after page1 if (not (isempty (page1.interaction1))) goto page5

Or

set condition1 if (not (isempty (page1.interaction1)))

O

or

Also written as ||.

The or command is used in the same way as the and command. It can be used to check if a user has responded in a particular way to an interaction (or number of interactions):

Example 1 after page1 if (or (page1.interaction1 = "none", page1.interaction1 = "sometimes")) goto page3

Example 2 savevalue(username, "sport", "cardio") if (or( page1.interaction1 = "running", page2.interaction2 = "swimming"

This will save the variable sport if running is selected for interaction1 on page1 OR if swimming is selected for interaction2on ...page2.

P

patternmatch

The patternmatch command is used when users are required to enter a specific combination of characters into a text entry interaction, e.g. a study code. The logic patternmatch(characters,interactionname) will check if the characters entered by the user, match the characters that you have pre-defined.

Patternmatch uses "Regular Expressions" to define a pattern of characters. Some basics are described below but for more detailed information, you can find guides to "Regular Expressions" on the Internet.

Character Example Comment
a a match a single lower-case character. Can be any character except .?+*[]\^$()|{}
A A match a single upper-case character.
abc abc match the exact sequence of characters
. a . means any character
a? a ? means zero or one of the preceding character
a* aaa * means any number of the preceding character
a+ aaaa + means one or more of the preceding character
[abc]+ cab [] means any character between the brackets
[^abc]+ fed ^ in a [] means none of the characters between the brackets
[0-9] 1 match any number between this range
[A-Z] LIFEGUIDE match any uppercase letter between this range
[a-z] lifeguide match any lowercase letter between this range
[A-Za-z]+ LifeGuide Any uppercase or lowercase letters
a(bc)+d abcbcbcd () groups things together
ab|cd cd | means 'or'

Example 1

This function may be useful if you have assigned each participant in your study a different code which they will need to enter in order to take part. This will ensure that only users who have been invited to use the intervention can gain access to it. To do this, you will need to write an error message on the page which contains your text entry interaction e.g.

Show nomatch if( not( patternmatch( “study[0-9][0-9]id[0-9][0-9]”, password ) ) )

In this example, the error message named nomatch will be shown to users if they enter a string of characters in the text entry interaction named password which does not fit with the pattern specified in the square brackets.

The string of characters needed in this example is studyxxidxx, where x is any number between 0 and 9.

See also Adding Error Messages (example 7).

Example 2

The patternmatch function could also be used to direct users to specific conditions, sections or pages within an intervention e.g.

show page1 if (patternmatch(“[0-9][0-9]a[0-9][0-9]”, interaction1))

show page2 if (patternmatch(“[0-9][0-9]b[0-9][0-9]”, interaction1))

In this example, if users enter the string xxaxx, where x represents a number between 0 and 9 they will see page 1 of the intervention. If they enter the string xxbxx they will see page 2 of the intervention.


Instead of 0-9, you could use [a-z], which means the user will need to enter any letter between a and z in the alphabet. You could also specify [a-z0-9] – this will mean the user will need to enter either a letter or a number.

NB The patternmatch function is case sensitive. If you specify [a-z], the user will need to enter a lowercase letter. If you specify [A-Z], the user will need to enter an uppercase letter. If you specify [a-zA-Z] the user may enter either an uppercase or a lower case letter.

printtime

This command can be used to instruct the intervention to display a particular time or date to the user.

Example 1

This example shows how you can use the printtime and currenttime functions to display the time/date a user is shown a specific page of the intervention:

show welcome

set welcome.time to printtime (currenttime, "H:m d-M-y")

In this example, the word 'time' on the page called 'welcome' has been set as a variable (see Setting text as a variable). This logic tells the intervention to display the hour, minute, day, month, and year at which the user is shown the page named 'welcome' in place of the word 'time'.

Example 2

This example shows how you can use the printtime function to display particular times or dates that you have saved in your intervention logic, such as the time/date a user signed up for the intervention and the time/date they logged back into the intervention.


show signup

after signup if (and (makenewuser (signup.name, signup.password), savevalue(signup.name, “currentlogintime”, currenttime()))) goto welcome

The first part of this logic tells the intervention to set up an account for the user using the username (signup.name) and password (signup.password) they created (see makenewuser). The second part of this logic uses the currenttime function to instruct the intervention to save the time/date a user signed up to the intervention as the variable "currentlogintime".

show welcome

set welcome.signuptime to printtime(loadnumber(signup.name, "currentlogintime"), "H:m d-M-y")

This logic tells the intervention to display the time/date a user signed up to the intervention on the page named 'welcome' in place of the word 'signuptime'.

show login

after login if (and(savevalue(login.name, "lastlogintime", loadnumber(login.name, "currentlogintime")), savevalue(login.name, "currentlogintime", currenttime()))) go to loginhistory

This first part of this logic uses the previously created variable "currentlogintime" to create a new variable called "lastlogintime" – the time at which the user first signed up to the intervention ("currentlogintime") now becomes the time at which they last logged in to the intervention ("lastlogintime").

The second part of this logic uses the currenttime function to re-create a new "currentlogintime" variable. Instead of saving the time at which the user first signed up for the intervention this variable now saves the time the user logged back into the intervention.

show loginhistory

set loginhistory.lastlogintime to printtime (loadnumber(login.name, "lastlogintime"), "H:m d-M-y")

set loginhistiry.currentlogintime to printtime (loadnumber (login.name, "currentlogintime"), "H:m d-M-y")

This logic tells the intervention to display the time a particular user first signed up to the intervention ("lastlogintime") and the time they logged back into the intervention ("currentlogintime") in place of the words ‘lastlogintime’ and ‘currentlogintime’.

R

randomnumber

This command allows you to randomise your users into different groups and always follows the same formula:

after page1 if (randomnumber (lowestvalue , highestvalue) = value) goto page3

For example:

after page1 if (randomnumber (0, 1) = 1) goto page3

show page2

show page3

Thus, users that are randomised to group 1 will be directed to page3. Those that are randomised to group 0 will carry on to page2.

A full tutorial for randomisation is available in the LifeGuide Researcher Help Manual.

replaceall

This command replaces text in a string.

Example 1

replaceall ("c", "b", "caked car")

This would replace all the c's in the string to b's. So this would change caked car to baked bar.

Example 2

Workaround for showing responses to a single-choice interaction back to the user. The reason for this is that the Unique Response Name (not the Response text) is saved and this will be shown to the user when a single-choice drop-down interaction is used.

savevalue (username, "s1_home", replaceall("_", " ", s1_whattodo1.home)) if (or( s1_fatigue.home = "Other_aspects_of_home_life", s1_fatigue.home = "I_find_it_hard_doing_things_around_the_house",s1_fatigue.home = "I_cannot_get_out_and_about_the_way_I_used_to" ))

This example is specific to a drop-down single-choice interaction, where you want to show the response selected for the interaction home on page s1_fatigue back to the end-user. All of the _ in each Unique Reponse Name in the interaction will be replaced with a space, which you can show back to your user.

You can then use feedback boxes and a container to show the responses on a later page:

show s1_fatigue2.home1 if (s1_fatigue.home = "Other_aspects_of_home_life") show s1_fatigue2.home2 if (s1_fatigue.home = "I_find_it_hard_doing_things_around_the_house" show s1_fatigue2.home3 if (s1_fatigue.home = "I_cannot_get_out_and_about_the_way_I_used_to"

home1 is a feedback textbox which will be shown on s1_fatigue2 if Other_aspects_of_home_life was chosen for the interaction home on page s1_fatigue.

resetpassword

S

save

The save key command allows you to save the responses that an end-user enters on a page. This can then be loaded using the load key command onto another page to re-show it to your end-user. The save and load commands can be used across sessions and requires end-users to have registered a user account.

Example:

show page1

save page1 for username

Then, later on in the logic (either in the same session or a later session) the following logic would be used:

show page20

set default page20.interaction2 to load page1.interaction1 for username

So, in the first part of this logic page1 is saved for the end-user. Then when they get to page20 in the intervention the response that they entered on interaction1 on page1 will be reshown to them on interaction2 on page20.

saveandload

This command is used after a page that contains interactions. If an end-user clicks on a next button on that page and then returns to it, the page will automatically show them the responses they entered the last time they saw that page.

Example 1

show page1

saveandload page1 for username

Any interaction on page1 will be saved and loaded each time the end-user comes back to that page.

set

The set key command can be used to set variables within the logic or for performing calculations.

Example 1

The most common use of setting variables will be to set a username for the user. Many of the logic commands such as save will need a username to be set. This will need to be done at the start of your logic file.

Set username to login.loginuname

This will set the variable username to whatever the end-user enters into the interaction uniquely named loginuname (usually an email address) on the login page. The word username can then be used any time throughout the logic to refer to the text an end-user entered into that interaction.

Example 2

You can set timings in your logic. Setting timings means you can change the timings for testing and change them back again to real-time easily, and it reduces the likelihood of mistakes being made.

In this example, twelvemonth has been set to the number of seconds in 12 months:

set twelvemonth to "31536000"

You can then use this in your login logic as follows:

after login if (comparetimes(loadvalue(username,"baselinetime"), currenttime(),"seconds") >= twelvemonth) goto studyfinished

The above logic will show the page studyfinished if it has been more than 12 months since baselinelinetime.

Example 3

You can set text such as an email address to avoid having to type it out each time, e.g. the study coordinator's email address:

set studyemail to "study@soton.ac.uk"

This logic should appear near the top of your logic file. An advantage to using this function this way is that if you decide to change the study coordinator's email address, you only have to change it once (where you set it).

You can also set the text and timings in emails:

set 3monthemail to "Thank you for taking part in The Reactivate Study. It is now time to complete your 3 month questionnaire. Your answers are very important to us. Please use the following link to login:\n\nwww.webaddress.co.uk\n\nIf you have any questions about the study, or no longer wish to participate, please contact us on study@soton.ac.uk\n\nFrom The Reactivate Team."

set oneday to "86400" set oneweek to ""604800"

The advantages to setting text in emails are:

  • They can be changed easily as you only have to change one line instead of multiple lines throughout your logic. It's common to overlook vital lines if you have many lines of logic and setting text reduces the likelihood of mistakes being made.
  • The lines are easy to find as they are placed at the top of the logic file.

Please see the command sendemail for more information on how to write email logic. Example 3

The set key command can also be used to set a variable based on how end-users respond to certain interactions. This can then be used to tailor the intervention based on this variable.

show page1

set condition1 to and (page1.chooseoptions contains "optiona", page1.chooseoptions contains "optionc")

after page1 if condition1 goto page3

So in example 2, the variable condition1 is set if end-users select optiona and optionc from the interaction chooseoptions on page1. Then those that are in this condition are sent to page 3 where they will receive tailored information based on the options they selected.

Example 4

In this example, the set key command is used to set a score based on the calculation that follows. In this calculation the number that the end-user selects in the interaction ‘dailyexercise’ on page1 is multiplied by 5 to create their exercise score

set exercisescore to (page1.dailyexercise * 5)

saveuniquevalue

The saveuniquevalue function is used in the same way as the savevalue function. The only difference is that with saveuniquevalue, if the value entered by an end-user is not unique, the function will return a 'false' input, and you can use this to stop end-users continuing with the intervention until they have entered a value which is unique.

savevalue

The savevalue command saves a variable that can be loaded again in later sessions. It is used if users have to create an account to access your intervention and you want to save information to a user.

It can be used to:

  • create a variable and save it to a user
  • save a response a user has given to an interaction
  • save the time
  • save a questionnaire or session as 'complete'


Example 1 - Create a variable and save it to a user

savevalue(username, "group", "web_support")

This will save the variable web_support for a username. group will be the column heading in your data.

When loading this value later in your logic, you will use the command loadvalue, and the variables you have created - group and web_support:

after page5 if (loadvalue(username, "group") = "web_support") goto page10


Example 2 - save a response a user has given to an interaction

savevalue(username, "s1_fatigue", page1.interaction1)

This will save the response given to interaction1 on page1 to the variable s1_fatigue for the username.

To load this later in your logic, you would use the variable name s1_fatigue:

set page5.fatigue_score to loadvalue (username,"s1_fatigue")

This will load the variable s1_fatigue and will show it in the text box fatigue_score on page5. For this to function correctly, fatigue_score needs to be set as a variable.


Example 3 - save the time

savevalue(username, "s1_time", currenttime())

This will save the current time as s1_time.

You can load this later in your logic to ensure that end-users do not see session 2 until 1 week later:

after login_successful if (comparetimes(loadvalue(username, "s1_time"), currenttime(), "seconds" ) > 604800) goto s2_welcome


Example 4 - save a questionnaire or session as complete

savevalue(username, "baselinecomplete", "yes")

This will create the variable baselinecomplete and will save it as yes. In this example, you can use a number instead of yes.

You can load this in your logic to check that an end-user has completed their baseline questionnaire:

after login_successful if (and( hasseen(username, "qintro"), (isempty(loadvalue(username, "baselinecomplete"))) )) goto q_notcomplete

This will show the page q_notcomplete if the end-user has seen qintro, but the variable baselinecomplete is empty (because the baseline questionnaire has not yet been completed).

sendemail

This is the command for setting up e-mails to send out to the end-user at specific points in the intervention. The function for sending out an e-mail always uses the same basic formula:

after pagename1 if sendemail("unique name for e-mail", e-mail address, "Subject message for e-mail", "E-mail content", number in seconds indicating how long after the end-user views pagename1 that you want the e-mail sent out) goto pagename2

Example

after page1 if sendemail("welcomeemail", login.email, "welcome to the intervention", "Thank you for registering for the lifestyle intervention. Please remember to check back regularly for more information.", 60) goto page1

In this example a welcome email will be sent to the e-mail address that the end-user has entered on the login page 60 seconds after they have clicked away from the page.

A full tutorial is available for Sending Emails including details of how to send e-mails to a researcher or healthcare professional instead of the end-user.

sendtext

This is the command for sending sms text messages to an end-user. It uses a similar basic formula as the command for sending email messages. The only differences are:

  • it uses the end-user's mobile phone number instead of an e-mail address
  • it does not need a subject message
  • there is a restriction for how long a text message can be

after page1 if sendtext ("welcometext", login.phone, "Thank you for registering for the lifestyle intervention. Please remember to check back regularly for more information.", 60) goto page1

Note: You will need to set up an sms account for your intervention before you can send sms messages. See LifeGuide Community Website FAQs for more information.

stringlength

This command tells the intervention how many characters a user has entered into a free text interaction.

This can be useful if you want your users to create usernames that are a specific number of characters.

To use this function you will need to write an error message:

show namemessage if (stringlength (username) < 5)

In this example, the error message called “namemessage” will be shown to users if they have entered less than 5 characters in the interaction called “username” (see also Example 11: Asking end-users to enter a response that consists of a certain number of characters).

sum

Please see add

show

The show command is the first logic command you will need to know. It is also probably the most common one that you will use.

This command shows each of the pages you have created. Pages will be shown in the order they are written in the logic. When an end-user clicks on a Next button on a page, they will be moved to the next page written in the logic.

Example 1

show page1

show page2

show page3

show page4

In the example above, the end-user will be shown the page named ‘page1’. When they click on the next button on page1, they will see the page called page2’. This is followed by ‘page3’ and finally ‘page4’.

NB Before you can preview your intervention, you will need to have the show command in the logic file for each page you want to view.

As the logic requires you to use unique names for each page in your logic, you can only use the show command once for each page. However, you can re-show the same page to users - see the named command above for more details.

You can also reshow pages to your end-user by using a jump button on a previous page.

T

timesincelogin

This command can be used to show users how much time has passed since they last logged into the intervention.

Example

Using the timesincelogin command involves 3 basic steps:

1. In your logic, show the page (e.g. “time”) where you want to display how long it has been since the user last logged into the website:

show time

2. In your logic, create a new variable (e.g. “username”) to tell the intervention, which user, time since login data should be displayed for:

set username to login.name if (not(isempty (signup.name))) set username to signup.name

(For this logic to work, you will need to have already created “login” and “signup” pages which contain free text interactions to allow the user to enter their name or other identifier such as an email address – see also 1.12 set)

3. On your “time” page, create a new variable to represent where the time since login data should be displayed to the user (e.g. “secs”). (This is done using the ‘set as variable’ function). Then, in your logic, set this variable to display the desired time since login for a particular user, using the timesincelogin command.

set time.secs to timesincelogin (username, "seconds")

So, in this example, on the page named “time” you have shown the user the time in seconds since they last logged into the intervention.

The third step can be repeated to show the user the time in “minutes”, ”hours”, “days”, “weeks” or “months” since they last logged into the intervention.

to

The to key command is used with the set key command to set variables.

U

urlencode

urlencode(string)

This returns a URL encoded version of a string. urlencode should be used only when creating a dynamic URL (i.e. using a variable). It is used when the variable might contain non alphanumeric characters. It converts a string into the correct format to prevent usual characters from breaking the link. This is because certain characters (such as ? and &) have special functions when included in a URL and have to be encoded in a different format (e.g. the & symbol gets converted to %26).

URL encoding is common and you will find more information here: http://en.wikipedia.org/wiki/Percent-encoding