record function not working

165 views
Skip to first unread message

Jered Abernathy

unread,
Feb 1, 2019, 2:28:24 AM2/1/19
to LIONESS Lab help and discussion
As the title says, I'm trying to record the values used later in the experiment early on in the Lobby.  
I have tried the following iterations all to no avail:
record('letter',letter);
InsertRecord('letter',letter);
setValue('decisions', 'playerNr=' + playerNr + ' and period=' + period, 'letter', letter);

None of the above have saved the data to the decisions table as I hoped.  In fact, I seem completely unable to add new variables to the database with these commands.

Am I missing some fundamental aspect of the record commands?

Thank you for your help!

-Jered A.

Lucas Molleman - LIONESS Lab Development Team

unread,
Feb 1, 2019, 3:15:43 AM2/1/19
to LIONESS Lab help and discussion
Hi Jered,

Your example on the first line is the correct one. This should write the value of the JS variable 'letter' to a column in the database with the name 'letter'. 

Note that this JS variable needs to be defined - if not, errors may occur. 

Hope this helps!

Lucas

jose guinot

unread,
Feb 1, 2019, 3:55:58 AM2/1/19
to LIONESS Lab help and discussion
Hello Jered,

Lucas gave you the correct advice. It is quite likely that you have any error before this line and this is why it is not working properly. 
One more thing, every time you create a new variable you need to compile (update is not enough).

Best regards,
Jose

Jered Abernathy

unread,
Feb 1, 2019, 4:13:42 AM2/1/19
to LIONESS Lab help and discussion
Thank you both for your responses. 
I'm unsure as to what the error in my code is though I am new to JS, so I don't doubt there are likely many).  It is particularly confusing because I can access the JS variable 'letter' by using the console (accessed in Chrome via ctr+shift+i) and it reports correctly, but the decisions table remains unchanged, even when I use the record command in inspector, which made me think there was a problem with the record() function.  I have attached screenshots and relevant code below.  

Thank you for your help,

-Jered A.
var PID= getInt("PID");
var Cond= getInt("Cond");
if (Cond>8) {
   
if (PID ===1) {letter="A";}
else if (PID ===2) {letter="B";}
else if (PID ===3) {letter="C";}
else if (PID ===4) {letter="D";}
else if (PID ===5) {letter="E";}
else if (PID ===6) {letter="F";}
else if (PID ===7) {letter="G";}
else if (PID ===8) {letter="H";}
}
//assign University IDs
if (Cond<9) {
   
if (PID ===1) {letter="USC-A";}
else if (PID ===2) {letter="USC-B";}
else if (PID ===3) {letter="USC-C";}
else if (PID ===4) {letter="USC-D";}
else if (PID ===5) {letter="OSU-E";}
else if (PID ===6) {letter="OSU-F";}
else if (PID ===7) {letter="OSU-G";}
else if (PID ===8) {letter="OSU-H";}
}
//set endowments
//HeteroUSC HeteroOSU
if (Cond===3 || Cond===7 ||Cond===10) {
   
if (PID===1) {endowment=20;}
   
else if (PID===2) {endowment=10;}
   
else if (PID===3) {endowment=20;}
   
else if (PID===4) {endowment=10;}
   
else if (PID===5) {endowment=20;}
   
else if (PID===6) {endowment=10;}
   
else if (PID===7) {endowment=20;}
   
else if (PID===8) {endowment=10;}
}
// RichUsc poorOSU
if (Cond===1 || Cond===5 || Cond===9) {
   
if (PID===1) {endowment=20;}
   
else if (PID===2) {endowment=20;}
   
else if (PID===3) {endowment=20;}
   
else if (PID===4) {endowment=20;}
   
else if (PID===5) {endowment=10;}
   
else if (PID===6) {endowment=10;}
   
else if (PID===7) {endowment=10;}
   
else if (PID===8) {endowment=10;}
}
//poor USC rich OSU
if (Cond===2 || Cond===6) {
   
if (PID===1) {endowment=10;}
   
else if (PID===2) {endowment=10;}
   
else if (PID===3) {endowment=10;}
   
else if (PID===4) {endowment=10;}
   
else if (PID===5) {endowment=20;}
   
else if (PID===6) {endowment=20;}
   
else if (PID===7) {endowment=20;}
   
else if (PID===8) {endowment=20;}
}
//med all
if (Cond===4 || Cond===8 ||Cond===11) {
   
if (PID===1) {endowment=15;}
   
else if (PID===2) {endowment=15;}
   
else if (PID===3) {endowment=15;}
   
else if (PID===4) {endowment=15;}
   
else if (PID===5) {endowment=15;}
   
else if (PID===6) {endowment=15;}
   
else if (PID===7) {endowment=15;}
   
else if (PID===8) {endowment=15;}
}

//GROUP FORMATION
//ID segregated
if (Cond<4 || Cond>8) {
    if (PID<5) subgroup=1;
    else subgroup=2;
}
//ID mixed
if (Cond>4 & Cond<9) {
    if (PID<3) subgroup=1;
    else if (PID>6) subgroup=1;
    else subgroup=2;
}
if (Cond<4) {
    if (PID<5) {subgroup=1;
   }
   else {subgroup=2;}
}
//ID mixed
if (Cond>4 & Cond<9) {
    if (PID<3) {subgroup=1;
    }
    else if (PID>6) {subgroup=1;
    }
    else {subgroup=2;}
}
record ('subgroup',subgroup);
record ('endowment',endowment);
record ('letter',letter);

LIONESS control panel missing letter variable.PNG
Calling letter in inspector.PNG

Lucas Molleman - LIONESS Lab Development Team

unread,
Feb 1, 2019, 4:18:58 AM2/1/19
to LIONESS Lab help and discussion
it seems there's a space between 'record' and the opening bracket of the function. If you remove those, you should be fine!

Jered Abernathy

unread,
Feb 1, 2019, 4:27:20 AM2/1/19
to LIONESS Lab help and discussion
Thank you greatly!  

You were absolutely correct.  Amazing what damage a space bar can do...

Thank you again,

-Jered A.
Message has been deleted

Jered Abernathy

unread,
Feb 1, 2019, 4:42:04 AM2/1/19
to LIONESS Lab help and discussion
I have a follow-up small question.  I'm pleased to report that the code fixes above have completed a full round, which is the farthest it has gotten.  

However, when a new round starts, all of my variables are reset to null.  See screenshot.  Is there a way to stop this from happening without re-running the functions from round 1?

Thank you,

-Jered A.
variables erased in round 2.PNG

Lucas Molleman - LIONESS Lab Development Team

unread,
Feb 1, 2019, 4:55:35 AM2/1/19
to LIONESS Lab help and discussion
When a new round starts, LIONESS experiments by default add a new line to the decisions table (as you can see in your screenshot). These new lines only contain the 'identifiers' groupNr, playerNr, subjectNr and period. 

If you need your custom variables, you need to retrieve them from the database (using similar functions to the one you have in your lobby) Perhaps all that can be done in the first stage within your loop? If so, make sure that you refer to period 1 when you retrieve the values of your custom variables (e.g. Cond, PID, subgroup), e.g. by using 

Cond=getValue('decisions', 'playerNr='+playerNr+' and period=1', 'Cond');

hope this helps!

Lucas

thomas....@gmail.com

unread,
Feb 13, 2020, 9:01:14 PM2/13/20
to LIONESS Lab help and discussion
I believe I have a related coding mistake to Jared's. But I don't know what it is. I guess I just don't quite understand how to create variables with the record() function.

So yes, I use the record() function of yours. But my experiment doesn't seem to actually record/generate those variables.

My experiment should be visible in the repository: InsuranceExperiment_v3 (=alternative title)
It's stage 9 (Experiment_loop) I need help with. If that works, I can fix all other stages myself too.

I assumed I would have generated all the necessary variables once in period 1 and then could use, show, and manipulate them easily in any of the periods. But that doesn't seem to be the case?

For example, when I use
record('homeValue', 500,000) and then try to show this home value in a text box using $homeValue$, the text box doesn't show me anything.

What mistake am I making?

Many thanks for your help!
Best,
Thomas

Lucas Molleman - LIONESS Lab Development Team

unread,
Feb 14, 2020, 3:25:25 AM2/14/20
to LIONESS Lab help and discussion
Hi Thomas,

JavaScript (JS) functions that take multiple parameters have those parameters separated by commas. Using commas to separate thousands (as in your example) will not work, as the three zeroes at the end will be interpreted as an additional parameter of the function.

From the experiment on the repository, stage 9, I can see that you have wrapped all your record() functions in an 'if' statement. This will lead to errors. See the warning box here: https://lioness-doc.readthedocs.io/en/latest/040_reference_manual.html#writing-to-the-database . In your case I would record all of these custom variables in a previous stage (e.g. stage 1) and use setValue from there on out. The setValue() function will work as normal inside if statements.

Furthermore, the record() function is to write to the database. It does not define the value of a JS variable in a stage. In your script (stage 9), for example, you cannot use 'cash_start' in a text element by only writing:

 record('cash_start', 50000);

This will merely write the value 50000 to the column 'cash_start' for this participant. If you want the value to be available in text elements you should write:

cash_start = 50000 /* this defines a JS variable and assigns a value to it */
record('cash_start', cash_start); /*this writes that value to the decisions table */

Cheers,
Lucas

thomas....@gmail.com

unread,
Feb 17, 2020, 10:34:12 PM2/17/20
to LIONESS Lab help and discussion
Big thanks for this detailed explanation once again, Lucas.

I think I am getting closer in understanding the functions and all. I really am a complete newbie in JavaScript and still struggle understanding the syntax.

I do have a follow-up question here.
Can you explain me shortly what the difference between the setValue() and the record() function is?

I thought record only generates a new variable in the decision table, but in your example (and other examples of users who posted in this forum) it seems that the record() function is also used to write a value into an available variable?
But if record() writes a value into a variable, what is setValue() for then?

Cheers,
Thomas



On Friday, February 14, 2020 at 9:25:25 PM UTC+13, Lucas Molleman - LIONESS Lab Development Team wrote:
Hi Thomas,

JavaScript (JS) functions that take multiple parameters have those parameters separated by commas. Using commas to separate thousands (as in your example) will not work, as the three zeroes at the end will be interpreted as an additional parameter of the function.

From the experiment on the repository, stage 9, I can see that you have wrapped all your record() functions in an 'if' statement. This will lead to errors. See the warning box here: https://lioness-doc.readthedocs.io/en/latest/040_reference_manual.html#writing-to-the-database . In your case I would record all of these custom variables in a previous stage (e.g. stage 1) and use setValue from there on out. The setValue() function will work as normal inside if statements.

Furthermore, the record() function is to write to the database. It does not define the value of a JS variable in a stage. In your script (stage 9), for example, you cannot use 'cash_start' in a text element by only writing:

 record('cash_start', 50000);

This will merely write the value 50000 to the column 'cash_start' for this participant. If you want the value to be available in text elements you should write:

cash_start = 50000 /* this defines a JS variable and assigns a value to it */
record('cash_start', cash_start); /*this writes that value to the decisions table */

Cheers,
Lucas

Lucas Molleman - LIONESS Lab Development Team

unread,
Feb 18, 2020, 4:18:27 AM2/18/20
to LIONESS Lab help and discussion
Hi Thomas,

Thank you for your question. I noticed the LIONESS documentation could have been clearer on this. 

The function record() will create a variable in the decisions table with the name of the first argument and the value of the second argument. By contrast, the function setValue() will update the value of an existing variable in the database, which may be created with a standard input element, or with the record() function.

This information can also be found in this (now updated) part of the documentation: https://lioness-doc.readthedocs.io/en/latest/040_reference_manual.html#writing-to-the-database

Lucas

thomas....@gmail.com

unread,
Feb 18, 2020, 2:28:05 PM2/18/20
to LIONESS Lab help and discussion
Awesome! Thank you. That definitely makes it clearer.

So it seems to me I use all variables created "locally" with var variable_name = value/function() only within a stage. If I want "local" variables with their values to appear in the decisions table (database), then I need to use the record() and setValue() functions appropriately. Furthermore, all "global" variables created with the record() and setValue() functions will not show up in the stages, so these variables can't be used for calculations within a stage, i.e. they are not usable for evaluations (if conditions) or the like. For that, I really need to create the "local" variables (I just call them "local" now, because I somewhere read that someone called other variables or parameters "global" variables).

I am typing this all for two purposes: so that other users clearly understand and so that I get a confirmation that I understand everything correctly myself :-D

Thank you, Lucas and team LIONESS!



On Tuesday, February 18, 2020 at 10:18:27 PM UTC+13, Lucas Molleman - LIONESS Lab Development Team wrote:
Hi Thomas,

Thank you for your question. I noticed the LIONESS documentation could have been clearer on this. 

The function record() will create a variable in the decisions table with the name of the first argument and the value of the second argument. By contrast, the function setValue() will update the value of an existing variable in the database, which may be created with a standard input element, or with the record() function.

This information can also be found in this (now updated) part of the documentation: https://lioness-doc.readthedocs.io/en/latest/040_reference_manual.html#writing-to-the-database

Lucas

Lucas Molleman - LIONESS Lab Development Team

unread,
Feb 18, 2020, 4:09:01 PM2/18/20
to LIONESS Lab help and discussion
Hi Thomas,

Indeed, JS variables declared in a stage can be used in that stage. Variables saved in the database (e.g. from previous stages or previous periods) can be retrieved with getValue() and subsequently be used in that stage. 

Hope this helps clarifying things!

Lucas

Liliana Dewaele

unread,
Feb 2, 2026, 10:41:30 AMFeb 2
to LIONESS Lab help and discussion
I have a related question. I am new to Lioness Lab and JS, and I want to use a JS variable (correctly recorded in one stage), in the next stage. I have tried accessing the variable in question using the getValue() function, but for some reason, it gets reset to 0 (the default value). I have put my experiment on the repository (stage 6 - is the stage where I record quizScore; and in the next stage I want to acces the stored value). 

Can someone help me with this? 

Thanks a lot!
Liliana

Op dinsdag 18 februari 2020 om 22:09:01 UTC+1 schreef Lucas Molleman - LIONESS Lab Development Team:

in...@lioness-lab.org

unread,
Feb 2, 2026, 11:01:48 AMFeb 2
to Liliana Dewaele, LIONESS Lab help and discussion

Hi Liliana,

 

In stage 7 your JS element should be placed above the text element where it is used. Hopefully that solves it.

 

Besides, in stage 6 you are using the record() function inside another function. This might not work stably. Probably it’s safer to write record(‘quizScore’,0) before the function and then use setValue() within a function.

 

Cheers, Lucas

--
You received this message because you are subscribed to the Google Groups "LIONESS Lab help and discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lioness-lab...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/lioness-lab/50536dc7-cb6e-4d8f-806e-0ba6f64258e5n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages