[SOLVED] A "JavaScript" event

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.

  1. 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.

In one picture :
Showing in the console of your navigator “oui”

Tested and approved :slight_smile:

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.

@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 :slight_smile:

Thanks for pointing me in the direction.

I glad of you, it’s easy :slight_smile:
Can you edit the title of this topic with [Solved] for next user :wink: ?

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?

You need to pass the “runtimeScene” variable as a parameter of your external code function (as runtimeScene is only available for javascript inlined inside the javascript event).

And I assume that you can do this with all the classes mentioned in the documentation ?

Your message makes no sense. runtimeScene is an instance of gdjs.RuntimeScene, that’s why you need to pass it around to use it.

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