Logic Dictionary
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:
- 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 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
andend
- 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 end-users 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
sendemail (append(username,"welcome_email"),username,"You have successfully registered to Stress Less", append("Dear ", loadvalue (username, "firstname"), "\n\n", welcome), 10)
In this example, the first part of the logic ,(append(username,"welcome_email")
, is the unique name of the email. The append function joins the username to the name of the email (welcome_email) to make sure that every email is unique. If the append function is not used, every email will be called welcome_email and only the first one will be unique - the other emails will not be unique and will not be sent out.
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