Howdy, Stranger!

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

Supported by

[solved] Different ERP triggers for different conditions

edited November 2012 in OpenSesame

Hi There!

quick question about ERP triggers. If I want to send different triggers for different conditions in my experiment
(e.g. I have named the following variables in my loop item "Context" consisting of Whole, Half and Quarter and "Lateralization" consisting of Right and Left)
would the following inline script send the correct triggers?

E.g. "Whole left" will send trigger 11 and "Quarter Right" will send trigger 32

If self.get("Context") = Whole:
    p = 1
elif self.get("Context") = Half:
    p = 2
    p = 3

If self.get("Lateralization") = Left:
    o = 1
    o = 2

global io
trigger = po
port = 0x378
    io.DlPortWritePortUchar(port, trigger)
    print 'Failed to send trigger!'

Thanks in advance!



  • ITA

    We will come back to you as soon as possible.

  • edited November 2012

    Hi Michel!

    You could do this as follows:

    NOTE: edited in line with Lotje's comment below:

    if self.get("Context") == Whole:
        p = '1'
    elif self.get("Context") == Half:
        p = '2'
        p = '3'
    if self.get("Lateralization") == Left:
        o = '1'
        o = '2'
    strpo = p + o
    po = int(strpo)

    What the script does is saving your triggerparts as strings, then adding the strings for p and o together and finally reverting them to integers.

    Good luck!


  • edited 8:32PM

    Hi Edwin,

    thanks for the reply. Good call to save them as strings and reverting them to integers, I hadn't thought of that to get the 'po' part working.

    Unfortunatly, the script in total doesn't seem to work and gives me the following error:

    Python 2.6.6
    Type "help()", "copyright()", "credits()" or "license()" for more information.
    Type "modules()" for details about installed modules and version information.
    Use the "print [msg]" statement in inline_script items to print to this debug window.
    openexp.sampler._legacy.init_sound(): sampling freq = 48000, buffer size = 512
    openexp._canvas.legacy.init_display(): enabling hardware surface
    openexp._canvas.legacy.init_display(): enabling double buffering
    openexp._canvas.legacy.init_display(): video mode ok
    experiment.init_log(): using 'C:/Documents and Settings/erp.users/Desktop/[PMQ]CNSWexp1/subject-0.csv' as logfile (ascii) experiment started at Mon Nov 26 12:04:37 2012
    Traceback (most recent call last):
      File "libopensesame\inline_script.pyo", line 97, in prepare
      File "", line 1
        If self.get("Context") = Whole:
    SyntaxError: invalid syntax

    I guess he doesn't recognize the variable? Or I refer to it in the wrong way?



  • NOTE: the answer was edited after being posted.

    Hi Michel,

    There are three problems with the if-then statements in your script:

    Firstly, note the following general rule:

    When assigning a value to a variable, use =, the assignment operator, like so:

     i = 5

    When comparing if two objects are equal, such as when comparing whether the variable Context has the value "Whole", use ==, the equal-to operator, like so:

    if i == 5:
    print "i is five"

    Secondly, you should indicate that the value 'whole' is a string, by putting the word into sinlge (') or double (") quotes.

    Thirdly, 'if' does not start with a capital (and neither do all other parts of control flow statements).

    Applied to your script, this becomes:

    if self.get("Context") == "Whole":
    p = '1'


    I hope this helps,

    Best wishes,


  • edited 8:32PM

    Lol, I should've spotted that!

  • edited 8:32PM

    Thanks a lot!

    I should have seen that aswell. I should know basic python (although I'm just starting with it and have no previous programming experience).

    The script is working great now!


Sign In or Register to comment.