Howdy, Stranger!

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

Supported by

The problem with the inline_script

Hello,

I have created an experiment using OpenSesame and I wish to make it online. When I tried to check compatibility on OSweb to make it online. It showed that it item_form_base is not supported, item_inline_script not supported etc.

I am attaching the screenshot of it.

I also know that I have to change the inline script into JavaScript but I have no idea how to do it?

What should I do?

Thanks,

Tanya


Comments

  • Hi Tanya,

    You are right that both the form_base and inline_script items are not yet supported in osweb. To convert and inline_script item into javascript, you first have to replace these items with inline_javascript items, and convert your code from python to javascript. It is not really easy to tell you how to do this, except for that you can best follow some javascript tutorials if you are unfamiliar with the language. For an example of a fully implemented osweb experiment you could read through https://osdoc.cogsci.nl/3.3/tutorials/wcst/

    For the key characteristics of the inline_javascript itself, you can have a look at https://osdoc.cogsci.nl/3.3/manual/osweb/javascript/.

    I hope this helps you forward.

    Buy Me A Coffee

  • edited March 2021

    Hello🤠,

    I am having a similar problem with my experiment. I need to perform my experiment online using OSWeb. I tried OSWeb and it says inline_script not supported. So tried to change inline_script sections in Javascript. (Like variables etc.) This time I get the following error: "Cannot use import statement outside a module"

    I used "Import" in imports_and_defauts section at the begining of the experiment in the OpenSesame as follows:

    import random

    How can I fix this error? How am I supposed to change this in javascript? What should I do? I am not very good at JavaScript.

    Thank you so much. 😇

  • Hi,

    What should I do? I am not very good at JavaScript.

    Well, get better at Javascript ;)

    No, but seriously, we will be able to help you for some specific questions, but many of us aren't javascripts experts themselves. So, there is a lot of googling and trying things out involved.

    I guess it generally make sense to try to learn a bit of javascript: This tutorial by Sebastiaan for example is a great place to start: https://www.youtube.com/watch?v=NCTpb09jtQA

    To your specific questions:

    I used "Import" in imports_and_defauts section at the begining of the experiment in the OpenSesame as follows:

    I guess there are two problems. The first one is that every java_inline_script has a non-permanent workspace. That means that you need to define variables, functions and imports in every inlinescript separately. The second is that there is no random module in javascript. To get a random number, you would use Math.random() , for other random operations, like shuffle or sample it is a little more complicated, see for example this discussion.

    Generally, it is easier for us to help you, if you don't just paraphrase your problem, but actually post the error message, and ideally the code that led to that error (e.g. by uploading your experiment).

    Hope this helps somewhat,

    Eduard

    Buy Me A Coffee

  • Hello 🤠,

    Thank you so much for the suggestions. I will try to fix the problem using the link that you provided.

    If the problem continues, I will post the error message and the code.

    Best 🤠

  • Hello everyone,

    Is there an api for inline javascript elements?

    I'm trying to find out what elements are allowed/not allowed. It's been stated that the inline js elements do not cover as much ground as the inline python scripts. I've looked at the links sent above but haven't found a list of possible commands.

    Thank you!

  • Hi,

    yes in the recent update, the documentation was somewhat changed, so the link doesn't show the supported items anymore. If you want to know what was on that list, you can select, Opensesame version 3.2 (however this one is quite outdated).

    Generally, there is no api for javascript items, because there are currently no javascript functions defined in Opensesame. The things that you have to keep in mind from the Opensesame point of view are listed here. For the rest, you'll have to browse the forum or google to find javascript code that you can use in those inline_scripts to make things happen.

    I hope this clears things up a bit.

    Eduard

    Buy Me A Coffee

Sign In or Register to comment.