Preview not workink with js

Hi!
I needed an xor gate for my game but the visual scripting did not have it, so I had to add a JavaScript code block and write it there. However after I was done the preview did not work, it loaded to 100% and stayed there. The javascript code doesn’t show any errors. How could I fix that?

However there is a part that seems wrong, the syntaxer expects a semicolon on the if senteces condition wich should not be happening, if I add that the program does not run. If I dont it runs but none of the code I wrote while visual scripting works.
Thanks

1 Like

Thanks for sharing, it might be useful to others. :wink:

1 Like

Please show your code, else how could we know what’s wrong?

The semicolon problem was me thinking javascript is like python and using the OR keyword.
I don’t get any errors when I change that in the code.
However even with no errors the program did not load.
Here is the code

Again, this is my first time with javascript and I might be doing something wrong

Well this is clearly not the GDevelop api. Read the documentation and base your work on that instead of writing random words related to what you want to do and expecting it to work. Note also that JavaScript events are meant for users that know JS and what they are doing.

You can emulate an XOR using an expanded AND/OR

a XOR b

is the same as

(a and !b) or (!a and b)

or in GD notation:

  • OR Condition
    • AND Condition
      • a
      • NOT b
    • AND Condition
      • NOT a
      • b
1 Like