Howdy, Stranger!

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

Supported by

NameError: name 'Keyboard' is not defined AND problems with sketchpad show if

I have one piece of feedback and one question
FEEDBACK:
I spent a long time being confused because I tried to create a keyboard with

my_keyboard = Keyboard ()

and got the error "NameError: name 'Keyboard' is not defined". I just figured out that they K of keyboard() should be lower case, unlike it is shown in the examples in the python section of the documentation of Opensesame.

QUESTION:
I am trying to show instructions A on a canvas item if the subject number is multiple of four and instructions B if it is not. For that I created an inline script at the begining of the experiment:

byfour = var.subject_nr/4

if float(byfour).is_integer():
var.Ginstructions = True
else:
var.Ginstructions = False

and then I wanted to use the show if field of the sketch pad item. I have tried to set show if:

[Ginstructions]
[Ginstructions] = True
[Ginstructions] == True
=var.Ginstructions
=var.Ginstructions == True
=var.Ginstructions = True
var.Ginstructions == True
var.Ginstructions = True
var.Ginstructions

And it always returns that the variable Ginstructions does not exist and I should open the variable explorer. When I do, Ginstructions is there and it has a value. I have also tried giving Ginstructions other type falues like 0 and 1 or 'yes' and 'no'. I have tried to initialize Ginstructions before the if loop as var.Ginstructions = 0. I suppose what hapens is that Ginstructions is not a global variable. How do I create a global variable that can be taen by the show if of sketchpad?

Comments

  • edited February 28

    Hi Andrea,

    , unlike it is shown in the examples in the python section of the documentation of Opensesame.

    The default documentation that you use when you go on www.osdoc.cogsci.nl, is for the most recent version of Opensesame, which is currently 3.2. I suppose you are still using 3.1.9? The change from lower to uppercase was introduced in the last update of Opensesame, so that's why the documentation appears to be incorrect to you. At the top of the page, you can actually change for which version you want to have the documentation. Just select 3.1 and you should get all information that are relevant for you (or just update your Opensesame).

    I am trying to show instructions A on a canvas item if the subject number is multiple of four and instructions B if it is not.

    Did you put the script in the prepare phase of the inline_script? It might be a little simpler if you used the modulo operator:

    var.Ginstructions = var.subject_nr%4
    

    Can you then try [Ginstructions]== 0 in the show-if field? Does is still not work then?

    Eduard

  • Hi Eduard,

    thanks for your help. In the end I put the instruction sketchpads inside of a sequence and set the show if conditions on the sequence table. It worked that way so I never tried the modulo operator, but I will keep it in mind.

    Also, I didnt know how to change the version for which I see documentation, thank you!

  • edited March 15

    Hi Andrea,

    Also, I didnt know how to change the version for which I see documentation, thank you!

    See the attached screenshot.

Sign In or Register to comment.