Callback for using game points outside the game

Hi, I’m Sebastian from Uruguay.
I’m working on an Android app with games and I’m planning to add a simple 2d game.

I need to get the points generated in the 2d games to use them in the app.
Is there any callback to get this points once the player finish the game?

What do you mean with points? I guess you can create an object, get its x and y value and store it in a globlal Js namespace, if your app is in Js. How do you plan to create your app exactly? Wich technologies will be involved?

When I say points I mean the game score, if I can get that score so I can use it to give trophies for example in the app.
The app is already up and working, it’s an Android app.
In the app we have a quiz, and you win points by completing this quiz. Then you can use those points to get discounts in our store.

I would like to do the same with a 2d game

This doesn’t tells me much about technologies used. Did you use plain Java, a webview with Js, a framework like Cordova or xamarin, something else?

The app is made in kotlin

How do you plan to embedd the GDevelop game? Through a webview?

If I export it in html5 I guess a webview should be fine.
I noticed that there is an action that let you save a json with the value of a variable, I haven’t figured it out yet

It’s for PC only, that won’t do the job. The way to go is in my opinion are Javascript Interfaces. Create a class like this:

public class JavaScriptInterface {
    Context mContext;

    /** Instantiate the interface and set the context */
    JavaScriptInterface(Context c) {
        mContext = c;
    }

    /** Show a toast from the web page */
    @JavascriptInterface
    public void showToast(String toast) {
        Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
    }
}

To create an interface. Then, use something like this in your webview:

webView.addJavascriptInterface(new JavaScriptInterface(this), "Android");

Where the second argument is the namespace you attribute in the Js environment. Then you can in GDevelop use a Js event to call the Java function from the interface, in that case like this:

Android.showToast("hello");

Use it to modify variables in your app instead to values of GDevelop variables.

2 Likes

Nice, I’m going to try this.
Thanks!