Ask here your questions to get help using GDevelop.
By michalhz
#61515 According to this page: http://wiki.compilgames.net/doku.php/gdevelop/tutorials/usingjsevents

You can add javascript to your game, but there is a problem.

1) No actual "JavaScript Event" exists in the Events tab.
there is only a "JavaScript code (Web platform ..)" and that is not what I want.

So I tried External sources... created that, added it to my game and it looks exactly as on the image in the tutorial, but.

2) You have to call your functions using a "JavaScript Event" and that one doesn't exist...

What am I doing wrong ?


Edit: SOLUTION

1.Write a function in your external source and give it a parameter.
2.In "Events" tab create a "JavaScript code" and call the function using sing the instance of whatever you are trying to access as the parameter.



Thanks
M.
Last edited by michalhz on Thu 16 Mar 2017, 20:21, edited 2 times in total.
User avatar
By Bouh
#61516 In one picture :
Showing in the console of your navigator "oui"
Image
Tested and approved :)

Javascript Code is more like a action for me. i use some condition of GD and with a sub event i put a Javascript Code for execute my code.
By michalhz
#61523 @Bouh So if I get you correctly
I create an external source, in there I write all the functions, then I use the javascript code event and put in the name of the function from the external file >> no reference required ?

Edit: Ok I figured it out :)

Image

Thanks for pointing me in the direction.
By michalhz
#61525 Actually .. there is still a problem.

Scenario: I copied the default code that is generated when you add a "JavasScript code" event and put it in a function in my external source.

It says "runtimeScene is not defined"

I can't access any of the gdjs functions. Are they namespaced or how do I import them?
By michalhz
#61543 I meant that when I want to use e.g. gdjs.RuntimeObject I have to use "runtimeObject" as a variable passed in my external file, and similarly to the rest of the gdjs.______.classes. I'll give it a try and report back.

Edit: Ok I was being stupid .. I had it set up properly, but I kept executing my code from Chrome's JS console.
Now it is working.
Thanks @victor and @Bough