Python coding to javascript for OSWeb/JATOS
Hi Everyone! I made an experiment that is locally running fine. I have added three short inline python scripts. Now, I need to run it online using JATOS and I am unable to do so because it requires javascript. I do not have any prior understanding of java coding. Any type of help would be highly beneficial.
## first inline python script
global win_b
global win_c
win_b = 100
win_c = 50
win = 0
total = 0
current = 2000
previous = 2000
borrowed = 2000
net = 0
exp.set('current', current)
exp.set('previous', previous)
exp.set('currency', 'INR')
## second inline python script
exp.set('previous', current)
if self.get('response') == 2:
loss =self.get('b')
win = win_b
elif self.get('response') == 3:
loss =self.get('c')
win = win_c
total = current + loss + win
current = total
net = current - borrowed
exp.set('win', win)
exp.set('loss', loss)
exp.set('current', total)
## third inline script
if [loss]+[win]>[0]:
src = pool['Sound_Win.wav']
my_sampler = Sampler(src, volume=.5)
my_sampler.play()
elif [loss]+[win]<[0]:
src = pool['Sound_No.wav']
my_sampler = Sampler(src, volume=.5)
my_sampler.play()
Please help if possible.
Comments
Hi @adars ,
It seems that everything in your scripts can be re-implemented in JavaScript, and syntactic differences between JavaScript and Python are (for simple things) not that large. I would start by reading this page and following this tutorial, which together should provide you with the tools you need.
One important note. This:
... probably doesn't do what you think it does, neither in Python nor in JavaScript. The
+operator concatenates lists (and it does not add up the contents of the lists!), and so you're effectively asking whether a list of length 2 ([loss, win]) is longer than a list of length 1 ([0]), which is always true. You probably mean:Another note: there is no
Samplerobject in JavaScript. But you probably don't need that, because you can use a regularsampleritem from the user interface.— Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Thank You @sebastiaan ! I will go through the mentioned details and tutorials and try to change the python inline script to javascript. Also, thanks for correcting the code for conditional audio play!