Page 1 of 1

[SOLVED] Calling Java (android) int insde my renpy game

Posted: Mon Jul 30, 2018 4:45 pm
by FroGlenn
Hello. This is my first post.

I've been working in a Renpy game for some time and Renpy is great.

Following this guide and Google Official Documentation, I got a Rewarded Video AD to work.

I have one last step tho: I need to let the players use the reward points inside the game.

I have one int (coins) with the reward value. I just need to call it 'inside' Renpy.

Is there a easy way to do this? If its not easy, there is a documentation that I can read to learn?

Thank you!

Re: Calling Java (android) int insde my renpy game

Posted: Wed Aug 01, 2018 1:06 pm
by FroGlenn
Thx to Pytom I found the pyjnius module and a some topics about it.

Following this reply, I made the import, but now Renpy returns the error "ImportError: No module named...". I tried:

import jnius and import pyjnius

Both returns the same error when I execute my project.

Re: Calling Java (android) int insde my renpy game

Posted: Fri Aug 03, 2018 1:10 am
by FroGlenn
I finally managed to do it.

Thx to Pytom and storykween for this guide.

If someone would like to know in detail how to use Rewarded Video AD with Renpy, I can make a guide, but answering this topic, you need to use pyjnius to get a java method returning the value you want to use in your game.

Start importing pyjnius and creating the variable with the class PythonSDLActivity inside your renpy code.

Code: Select all

init python:
    if renpy.android:
        from jnius import autoclass
        PythonSDLActivity = autoclass('org.renpy.android.PythonSDLActivity')
Inside Android Studio find the PythonSDLActivity.java file and create a method to return the value of the variable you want.

In my case I did something very quickly just to test:

Code: Select all

public int getCoins(int coins) {
        cCoins = cCoins + coins;
        return cCoins;
    }
In this example, cCoins stores the coins rewarded after watching the video ad.

Back to your renpy code, just create a new variable that will get the return value from getCoins().

Code: Select all

python:
            if renpy.android:
                coins = PythonSDLActivity.getCoins(0)

        "You have [coins]"
I'm sure there are ways way cleaner than mine to do this, but I would like to share my approach if someone wants to use this type of ad in their android version games.

Like I said, if you guys wants a full tutorial, I can make it with all the steps, but this forum has a lot of examples already.

Good luck!

Re: [SOLVED] Calling Java (android) int insde my renpy game

Posted: Mon Jul 06, 2020 2:26 am
by phillopeters
Hi @FroGlenn. Could you kindly make the guide for the rewarded ads. I managed to add the ads to my app but there are too many issues... At some point, the reward was added but then in stopped and now when I run an ad, it quits the app. I must be missing something but I am not sure what. If you don't mind kindly make the guide with the steps you followed.

Thank you in advance.

Re: [SOLVED] Calling Java (android) int insde my renpy game

Posted: Mon Jul 06, 2020 6:02 am
by renardjap
Hi
I'm very interesting by this guide. I would like to add Rewarded Video AD with Renpy in my game.

Re: [SOLVED] Calling Java (android) int insde my renpy game

Posted: Sat Aug 22, 2020 6:34 pm
by beastcarving
I'd love a guide, please.