0 votes

I uploaded a game to Kongregate where it shows the user's name in a Label. But it doesn't work. I've looked at these two posts but nothing:
1 Post
2 Post

My porject:
In the Godot project (version 3.0.5) I have the following GDScript:

extends Node

func _ready():
var nametext= JavaScript.eval(kongregate.services.getUsername())
get_node("Label").set_text(nametext)

And when I export it, I modify the HMLT file, and add the following in the head:

<script src='https://cdn1.kongregate.com/javascripts/kongregate_api.js'></script>

And in the body in the function section I add this:

    kongregateAPI.loadAPI(function(){
    window.kongregate = kongregateAPI.getAPI();
});

When I upload it to Kongregate I don't enter anything in the "API CALLBACK URL" and I don't add anything in the "Static API".

I don't know what the problem is.

asked Jul 18, 2018 in Engine by Konevgate (15 points)
edited Jul 18, 2018 by Konevgate

1 Answer

+1 vote
Best answer

I know almost nothing about HTML5 export, but in the doc I see one of your problems:
http://docs.godotengine.org/en/3.0/classes/class_javascript.html?highlight=JavaScript.eval#class-javascript-eval

JavaScript.eval expects the JS code as a string. But you didn't send a string:

JavaScript.eval(kongregate.services.getUsername())

You wrote GDScript code. I think the function expects you to write this:

JavaScript.eval("kongregate.services.getUsername()")

There is another argument for the execution context, not sure what that is but I would suggest you have a look. Keep an eye on the error logs (I hope you can see them, I dunno how that works) because that mistake will certainly have been printed there.

answered Jul 18, 2018 by Zylann (26,143 points)
selected Jul 18, 2018 by Konevgate

Wow, you're right about that. I didn't notice the .eval function.

Thank you very much, NOW IT WORKS!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.