Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

pool object not identified on javascript

Hi there,

I am trying to insert some javascript inline code on my experiment to be able run it online. In python I access my stimuli from the pool using the pool function (ie, path = pool[u'stimulus']), so I am trying to do the same on javascript as explained here (The pool object: Access to the file pool). However the command line prompts the following error:

js2py.internals.simplex.JsException: ReferenceError: pool is not defined

Find below a simplified version of my code. First in the prepare tab, I define the canvas object and the stimuli list that I will later use to index one stimulus on each trial:

persistent.img1 = Canvas()
let desirable_list = ["LT1.png", "LT2.png"]

After that in the run tab, I select the first stimulus from the list and then access it from the pool.

var imagen1 = desirable_list[1]
var path = pool[imagen1]
img1.image({fname: path, x: 250, y:0})
persistent.img1.show()

I would appreciate any help with this issue. Thanks!

best,

P Elosegi

Comments

  • Based on previous posts I have managed to fix the previous error and add a file to the pool from GitHub, but I think that I have some problems going on with the CORS policy.

    Code prepare:

    function addExternalImageToPool(url, name) {
        const img = new Image()
        img.crossOrigin = "anonymous"
        img.src = url
        const item = {
            data: img,
            type: "image",
            name: name
        }
        runner._pool.add(item)
    }
    
    addExternalImageToPool(
        "https://raw.githubusercontent.com/Patxelos/stimuli/main/LT1.png",
        "LT1.png"
    )
    
    var path = runner._pool['LT1.png'].name
    persistent.img1 = Canvas()
    persistent.img1.image({fname: path, x: 250, y: 0})
    

    Code run:

    persistent.img1.show()
    

    Before this step I have a fixation routine that works fine but after the fixation a white screen pops up and I don't see any image:

    Any hint of what could be going on here?

    Best,

    P

  • edited February 2022

    Closed as duplicate of 7279

    Buy Me A Coffee

This discussion has been closed.