Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
gdevelop:tutorials:usingjsevents [2015/05/18 12:28]
127.0.0.1 external edit
gdevelop:tutorials:usingjsevents [2020/06/13 11:38]
rapperdinesh [Use external source files]
Line 3: Line 3:
 Using Javascript events, you can insert an arbitrary code of Javascript into your games created with the Web platform. Using Javascript events, you can insert an arbitrary code of Javascript into your games created with the Web platform.
  
-This can be useful if you want to use some external libraries or very specific code. With external source files, you can also integrate entire Javascript source files into your game: it's nice to progressively learn Javascript programming or create a game with a programmer.+This can be useful if you want to use some external libraries or very specific code. With external source files, you can also integrate entire Javascript source files into your game: it's nice to progressively learn Javascript programming or create a game with a programmer.
  
 {{ gdevelop:​tutorials:​javascriptevent.png?​nolink |}} {{ gdevelop:​tutorials:​javascriptevent.png?​nolink |}}
Line 33: Line 33:
 Using external Javascript source files (.js files) is very easy: just include it into the folder of the game (or a subfolder). Using external Javascript source files (.js files) is very easy: just include it into the folder of the game (or a subfolder).
  
-Then, activate the use of external source files in your game property (right click on the game name in the Project Manager, ​than choose properties, and finally check ''​Activate the use of C++/JS source files''​).+Then, activate the use of external source files in your game property (right-click on the game name in the Project Manager, ​then choose properties, and finally check ''​Activate the use of C++/JS source files''​).
  
-Now there is a new item in the structure of your projet ​called ''​Sources''​. Make a right click on it to choose to create a new source file or to import an existing one.+Now there is a new item in the structure of your project ​called ''​Sources''​. Make a right-click on it to choose to create a new source file or to import an existing one.
  
 {{ gdevelop:​tutorials:​externaljavascriptfiles.png?​nolink |}} {{ gdevelop:​tutorials:​externaljavascriptfiles.png?​nolink |}}
  
-You can edit the files using GD integrated editor or you preferred text editor (take a look at [[http://​www.sublimetext.com/​|Sublime Text]]). When your game will be exported or when you launch a preview, the source files will be integrated ​to the game.+You can edit the files using GD integrated editor or your preferred text editor (take a look at [[http://​www.sublimetext.com/​|Sublime Text]]). When your game will be exported or when you launch a preview, the source files will be integrated ​into the game.
  
 Source files are included like any other javascript file: if you want to access to functions defined inside, you have to store them into a global object or make these functions globals (just declare it with any prefix, like this: ''​function myFunction() { ... }''​). Then you can call them from your events using a Javascript event. Source files are included like any other javascript file: if you want to access to functions defined inside, you have to store them into a global object or make these functions globals (just declare it with any prefix, like this: ''​function myFunction() { ... }''​). Then you can call them from your events using a Javascript event.