PennController for IBEX › Forums › Support › Preloading resources by experiment list
- This topic has 7 replies, 2 voices, and was last updated 3 years, 9 months ago by emorgan.
-
AuthorPosts
-
February 5, 2021 at 3:42 pm #6587emorganParticipant
I’ve gotten preloading resources to work in general, but I’m running an experiment with a large number of sound files, so I’d like to only preload the files that are necessary for the particular experiment group that a participant has been assigned to. Is there a way to access the internal counter to know which group I’m on (and hence which .zip file to preload)? Or is there another standard way to achieve this?
Thank you for your help!
February 5, 2021 at 5:37 pm #6589JeremyKeymasterHi,
I understand you are talking about preloading resources for different groups from a zip file. To be clear, when not part of a zip file, only the resources used in the trials effectively presented to the current group are fetched.
If you need to preload different zip files depending on group, you can use the variable __counter_value_from_server__. Say you have a total of 4 groups:
EDIT: this code will not immediately work on https://expt.pcibex.net or https://ibex.spellout.net/ — see this message if you’re running your study at one of those two domains
switch (__counter_value_from_server__ % 4) { case 0: PreloadZip("https://my.server/path/to/zip_a.zip"); break; case 1: PreloadZip("https://my.server/path/to/zip_b.zip"); break; case 2: PreloadZip("https://my.server/path/to/zip_c.zip") break; case 3: default: PreloadZip("https://my.server/path/to/zip_d.zip") break; }
Let me know if you have any questions
Jeremy
February 5, 2021 at 5:39 pm #6590emorganParticipantYes, thanks for clarifying–I did mean preloading from a zip file, and that solution is exactly what I was looking for! Thank you!
February 15, 2021 at 4:59 pm #6610emorganParticipantHi Jeremy,
To follow up on this, our template is designed with a variable and plays a specific audio file from a group. It seems that in order to use the __counter_value_from_server__, we need to be inside the template. Is that right? If so, where would that switch statement go if the code structure looks like:Template(“myTable.csv”, variable =>
newTrial(“music”,
newText (“Listen carefully to the melody.”)
.center()
.print()
,
newButton(“Play”)
.center()
.print()
.wait()
,
…Thank you again for your help!
-Emily
February 15, 2021 at 5:09 pm #6611JeremyKeymasterHi Emily,
The switch statement from my previous message lets you execute different PreloadZip commands depending of the value of __counter_value_from_server__ (which goes to show that it is available from outside Template). This is a rather specific need
The Template function readily implements group designs by looking up a Group/List column in your table and selecting a subset of rows that share a single value for that column, so you don’t need to manually check __counter_value_from_server__. Since you should have the option of specifying the name of the audio file you want to play directly in a column in your table, I am not sure why you would need to access __counter_value_from_server__ from within the Template command
Jeremy
February 15, 2021 at 5:23 pm #6612emorganParticipantThank you for such a quick response! I realized I glossed over too much in my question. We really do want to execute different PreloadZip commands depending on the counter value (because otherwise the amount of data to be loaded is way too large if we have to load all possible files for every participant). When we first tried to use the __counter_value_from_server__ variable (in a switch statement outside of the Template function), we got the error:
Unrecognized expression ‘__counter_value_from_server__’ (line 250) (PennController: 9)
We thought perhaps the problem was that that variable was only defined inside the Template, but clearly that’s not the problem. Do you know what the issue might be? Thank you again!
Best,
EmilyFebruary 15, 2021 at 5:50 pm #6613JeremyKeymasterMy bad, I tested my code at https://farm.pcibex.net/, where __counter_value_from_server__ is accessible from the start, which is not the case at https://expt.pcibex.net.
If you’re running your study on the expt Farm (or on the original Ibex Farm for that matter) you’ll need a little trick to detect when __counter_value_from_server__ is being set:
let myOwnCounter = 0, preloadZipSent = false; Object.defineProperty(window, '__counter_value_from_server__', { set(v){ myOwnCounter = v; if (preloadZipSent) return; preloadZipSent = true; switch (v % 4) { case 0: PreloadZip("https://my.server/path/to/zip_a.zip"); break; case 1: PreloadZip("https://my.server/path/to/zip_b.zip"); break; case 2: PreloadZip("https://my.server/path/to/zip_c.zip") break; default: case 3: PreloadZip("https://my.server/path/to/zip_d.zip") break; } }, get(){ return myOwnCounter; } });
Jeremy
February 19, 2021 at 6:55 pm #6639emorganParticipantThanks very much!
-
AuthorPosts
- You must be logged in to reply to this topic.