How to use a variable defined in Renpy to Pygame?

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
HazeE
Regular
Posts: 26
Joined: Sun Feb 19, 2017 4:52 am
Contact:

How to use a variable defined in Renpy to Pygame?

#1 Post by HazeE »

I have a variable defined at my labels in Renpy and I added a minigame wherein I imported the pygame module. This variable represents something as a guide in my game so that when the pygame is exited, it would go right back to the labels and I would know which label to jump to.
Since I'm fairly new to Renpy language, I was hoping to find some help here. I can't seem to get that variable. Can I somehow pass it from label to pygame or vice versa? I tried using the same variable name however it seems like it created its own variable depending whether you are at the labels or at the pygame.
Any help and suggestions are appreciated! :D

HazeE
Regular
Posts: 26
Joined: Sun Feb 19, 2017 4:52 am
Contact:

Re: How to use a variable defined in Renpy to Pygame?

#2 Post by HazeE »

To make it clearer, I'll give an example:
So I have a variable counter in my labels called "ctr" and it contains a value. From this label, i jump to another label that initiates the pygame. While I am inside pygame, I would like to check the value of the variable ctr and if possible, change it as well if it meets certain conditions.
I somehow can't seem to get variable ctr in pygame, any suggestions?

User avatar
PyTom
Ren'Py Creator
Posts: 16093
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: How to use a variable defined in Renpy to Pygame?

#3 Post by PyTom »

You can do:

Code: Select all

import renpy.store

def update():
    renpy.store.ctr +=1
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

HazeE
Regular
Posts: 26
Joined: Sun Feb 19, 2017 4:52 am
Contact:

Re: How to use a variable defined in Renpy to Pygame?

#4 Post by HazeE »

it works!!! :D thanks a lot!!! I finally got it to work ^^

By the way, I have another question: Can you use the renpy.store for calling labels and images from renpy too or is it just used for variables?

User avatar
PyTom
Ren'Py Creator
Posts: 16093
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: How to use a variable defined in Renpy to Pygame?

#5 Post by PyTom »

It's probably a bad idea to do so. Ren'Py runs code - even Python code in an init python block - in very specific ways. You may confuse Ren'Py if you try to call Ren'Py functions from Python code. It's best to just put Python code in init python blocks, perhaps in namespaces.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

HazeE
Regular
Posts: 26
Joined: Sun Feb 19, 2017 4:52 am
Contact:

Re: How to use a variable defined in Renpy to Pygame?

#6 Post by HazeE »

Ohh.. alright. Thanks for your help~! :D

HazeE
Regular
Posts: 26
Joined: Sun Feb 19, 2017 4:52 am
Contact:

Re: How to use a variable defined in Renpy to Pygame?

#7 Post by HazeE »

One last question, let's say you're in pygame then after checking the variable, you would want to jump to a label however you can't do that in python code. What can you suggest to fix this?

User avatar
PyTom
Ren'Py Creator
Posts: 16093
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: How to use a variable defined in Renpy to Pygame?

#8 Post by PyTom »

You can jump to a label from python code. Do:

Code: Select all

import renpy.exports
renpy.exports.jump("labelname")
This works for many of the renpy.whatever functions in the documentation - they all live in the renpy.exports module.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

HazeE
Regular
Posts: 26
Joined: Sun Feb 19, 2017 4:52 am
Contact:

Re: How to use a variable defined in Renpy to Pygame?

#9 Post by HazeE »

Ohh, I see thanks a lot for answering my questions! :D

HazeE
Regular
Posts: 26
Joined: Sun Feb 19, 2017 4:52 am
Contact:

Re: How to use a variable defined in Renpy to Pygame? [Solve

#10 Post by HazeE »

Sorry for asking again PyTom but I have a question ^^; I've been working on the label to where it will jump from pygame. And now that it's ready to be connected I tried using renpy.exports.jump() but it would just simply do nothing. I can still see the pygame window but nothing happens. I can hear the music playing in the label it should have jumped but the image and dialogues are not there. There are no errors shown so I'm not sure of the problem ><. Any tips?

EDIT: I think I should make a new post for this since this was already solved a few days ago, and my question is different from the title XD

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]