• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

[Solved] Creating a JavaScript Extension

B

borthrop

Guest
I'm having trouble getting my JavaScript extension working. It's my first one, so I'm starting off super simple: I want it to print the word "Left" to the compiler window when I hit the left arrow key. The entirety of the JavaScript file is
Code:
function return_left() {
    return "Left";
}
In the object that has the "press <Left>" event, the code is
Code:
message = return_left();
show_debug_message(message);
Right now, this prints "0" (the number zero) when I hit the left arrow. It also prints "0" when my code is show_debug_message(return_left());

In Extension Function Preferences, Name is return_left and External Name is return_left. The Return Type is string.

I'm using GameMaker: Studio version 1.4.1772

Any thoughts on what I'm doing wrong?
 
W

Wraithious

Guest
I'm assuming this is for android?
Your java script should look like this:
Code:
package ${YYAndroidPackageName};
import ${YYAndroidPackageName}.R;

public class MyClass {

public String return_left() {
return "left";
}
}
and double click your extension in the file tree, go to the android tab of the extension properties box that pops up and type in the name of your class (in the above case example the name of the class is MyClass) in the ClassName box.

NOTE: you can name your class anything you want, but it should be named something different from what you named your extension.
 
Last edited by a moderator:
B

borthrop

Guest
I'm assuming this is for android?
Your java script should look like this:
Code:
package ${YYAndroidPackageName};
import ${YYAndroidPackageName}.R;

public class MyClass {

public String return_left() {
return "left";
}
}
and double click your extension in the file tree, go to the android tab of the extension properties box that pops up and type in the name of your class (in the above case example the name of the class is MyClass) in the ClassName box.

NOTE: you can name your class anything you want, but it should be named something different from what you named your extension.
Hmmm, that didn't work. It's still just printing "0".

I'm actually aiming to make this for HTML5, though at this point I'd be happy getting it to work on any platform.

Do I need to have an Init Function and/or a Final Function (in the Extension File Properties)?
 

FrostyCat

Redemption Seeker
Hmmm, that didn't work. It's still just printing "0".

I'm actually aiming to make this for HTML5, though at this point I'd be happy getting it to work on any platform.

Do I need to have an Init Function and/or a Final Function (in the Extension File Properties)?
I am getting "Left" just fine on HTML5 (1.4.1773). Do note that's the only place you can run JavaScript extensions.
 
W

Wraithious

Guest
Hmmm, that didn't work. It's still just printing "0".

I'm actually aiming to make this for HTML5, though at this point I'd be happy getting it to work on any platform.

Do I need to have an Init Function and/or a Final Function (in the Extension File Properties)?
Ahh ok thats definatly different than android sorry
 
B

borthrop

Guest
I am getting "Left" just fine on HTML5 (1.4.1773). Do note that's the only place you can run JavaScript extensions.
Welp, because of your post I tried restarting my computer and now the extension is working. Thank you for (indirectly) solving my problem!
 
Top