[OSWeb] Creating an array using inline javascript
Hi,
I'm trying to create a list variable (e.g. in Python, var.x = [1, 2, 3]) where I can append new values in it and store x in the variable inspector for future use. I try to do a similar thing with the inline_javascript. When I do const x = [1, 2, 3];, the experiment runs successfully, but of course I can't use x in a different workspace. The problem is, if I do vars.x = [1, 2, 3]; then the experiment won't store any variables as if it's illegal to store an array using the vars object. Can someone help with how I can get it to work?
Much appreciated,
intan
Comments
Hello Intant,
for me is working fine. I use an array to create a radom FixPoint duration.
I have a inline_js at the start of experiment in the prepare-fase
Then every cycle this other inline (run-fase)
function disordina(a) { for (let i = a.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [a[i], a[j]] = [a[j], a[i]]; } return a; } disordina(vars.listaFix); vars.fix1 = vars.listaFix[0]; //alert(vars.fix1);You could try it removing the comment on the last line.
Bye
Paolo
HI @bilancino ,
thanks for your response! I also did the same in terms of the flow, but it still didn't work properly in my case. I have noticed that it would work with three-digit numbers like yours (e.g., [150, 250]) and strings (e.g., ["a", "b"]), but not with one- or two-digit numbers. In my case, I need to append zeros and ones (e.g., [1, 0, 0, 1]) and it does not work. Can you maybe try and see if it works for you?
Cheersies,
intan
Update:
No worries, it works too with any digits! The problem is it will save the numbers, but won't print them off.
Cheersies,
intan