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

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
FroGlenn
Regular
Posts: 53
Joined: Sun Feb 25, 2018 2:07 pm
Contact:

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

#1 Post 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!
Last edited by FroGlenn on Fri Aug 03, 2018 1:10 am, edited 1 time in total.

FroGlenn
Regular
Posts: 53
Joined: Sun Feb 25, 2018 2:07 pm
Contact:

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

#2 Post 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.

FroGlenn
Regular
Posts: 53
Joined: Sun Feb 25, 2018 2:07 pm
Contact:

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

#3 Post 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!

phillopeters
Newbie
Posts: 1
Joined: Wed May 31, 2017 6:18 am
Deviantart: phillopeters
Contact:

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

#4 Post 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.

User avatar
renardjap
Regular
Posts: 75
Joined: Sun Aug 05, 2018 1:08 pm
Location: France ! Cocorico
Contact:

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

#5 Post by renardjap »

Hi
I'm very interesting by this guide. I would like to add Rewarded Video AD with Renpy in my game.

User avatar
beastcarving
Regular
Posts: 139
Joined: Mon May 13, 2019 5:03 pm
Completed: Pulse Cage https://beastcarving.itch.io/pulse-cage-the-full-series
Projects: Your Brother's Religion
Organization: BeastCarving Studio
IRC Nick: BeastCarving
Tumblr: beastcarving
Deviantart: beastcarving
Github: beastcarving
itch: beastcarving
Contact:

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

#6 Post by beastcarving »

I'd love a guide, please.
Image Pulse Cage (full game)Image Your Brother's Religion (Demo)
PLAY HERE: https://beastcarving.itch.io/
Love my work: https://www.patreon.com/beastcarving

Post Reply

Who is online

Users browsing this forum: Google [Bot]