|
|
|
|
Reply From: |
dsina |
See if you can get a simple javascript alert working. For your godot version I think it has to be:
func _ready():
JavaScript = Globals.get_singleton("JavaScript")
JavaScript.eval("""alert("test")""")
This JavaScript object is just your connection to the Javascript runtime. You can’t directly load javascript files using the get_singleton() method. What you can do is execute any Javascript command with eval() once the javascript singleton is loaded.
To load the kongregate api I suggest you do it like they discribed in Javascript API. Everytime you do a webexport godot generates a html file which you can modify (in Windowns 10 it’s under c:\Users\USERNAME\AppData\Roaming\Godot\tmp\tmp_export.html).
In this html file you need to import the kongregate api, preferably before your game starts. It’s just one line to add. Your html file should then contain something like this:
....
<script src='https://cdn1.kongregate.com/javascripts/kongregate_api.js'></script>
<script type="text/javascript" src="tmp_export.js"></script>
<script type="text/javascript"> .....
Now you can execute commands there in the javascript part of the html file or in Godot if you’ve loaded the javascript singleton as shown before, e.g.:
Javascript.eval(kongregateAPI.loadAPI(function(){
window.kongregate = kongregateAPI.getAPI();
// You can now access the Kongregate API with:
// kongregate.services.getUsername(), etc
// Proceed with loading your game...
}))
You might have to change your html file with every new export though. Compiling for the Web — Godot Engine (stable) documentation in English shows how to customize it properly but I don’t quite understand it tbh. I didn’t test any of this so let me know if it works.
Thank you very much, dsina:
You do not know the problems that I have in my head for not being able to solve this dilemma of the javascript singleton.
Actually I created a Node2D and placed the following script:
func _ready():
JavaScript = Globals.get_singleton("JavaScript")
JavaScript.eval("""alert("test")""")
I exported the small project to HTML5, then uploaded it to Kongregate.com and ran it …
… but nothing happened.
I unlocked the pop up in the webbroser thinking what that would be, but nothing either …
…I do not know what else to do…
Please help…!!! (T.T)
ferhand | 2017-12-20 02:06
Update…
Actually in the console the project writes this…
**SCRIPT ERROR**: At: res://.gdc:11:_ready() - Attempt to call function 'eval' in base 'null instance' on a null instance.
What this means?
ferhand | 2017-12-21 00:07
My bad. I think it should look like this:
func _ready():
var JavaScript = Globals.get_singleton("JavaScript")
JavaScript.eval("""alert("test")""")
Try to get just this running locally and without kongregate first to make sure the singleton works as expected.
If this doesn’t work try upgrading to the new beta1 version. This Singleton might only be available in newer versions. If you’ve done that, the following is what works for me. No need to load the singleton through the Global class, contrary to what the docs say.
func _ready():
JavaScript.eval("""alert("test")""")
milestone
Wow, thank you very much for answering again, dsina:
I have some problems to use version 3 of Godot since my laptop does not have OpenGL 3. I will try some solution for my laptop to work with OpenGL 3 otherwise I will be stuck in Godot 2 until the version of Godot 3 comes out that use OpenGL2. I read that in this link
I would swear that I have seen in some old forum the possibility of using the JavaScript singleton from Godot 2, but I can not find the link to show it to you. Maybe it was also my imagination and the desire to solve this problem.
for the moment I thank you again and I will wait to be able to use OpenGL 3 on my laptop. I have heard that if I use Ubuntu (Linux) it is possible that there is an update for my microprocessor. I’m not sure…
Very grateful for your help, dsina …
ferhand | 2017-12-22 22:04
I just read that you have a question about this on another thread. Where are you stuck currently?