Python minigames in Ren'Py?

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
jukebox
Newbie
Posts: 2
Joined: Thu Jun 09, 2011 12:28 pm
Location: Europe
Contact:

Python minigames in Ren'Py?

#1 Post by jukebox »

Hi, I used Ren'Py a lot some years ago (for fun, never shared my stuff... ) and think I remember there being a part in the tutorial game about integrating python minigames in a Ren'Py visual novel. I didn't find it in the current tutorial version but am guessing that adding python minigames is still possible?

I've become interested in learning some python and it'd be fun to try making a silly minigame and get it to play in a Ren'Py game. How do I go about doing this? I mean, in what way do I code it, what do I need to get it to work... I'm sorry, I don't really know anything. Feel free to direct me to old threads or wiki pages, I've searched a bit but I'm not so smart.

(For curiousity, I'm following this tutorial...
http://www.tuxradar.com/content/code-pr ... ders-clone
... to start trying to make my first python code. I have some limited programming experience from before so this stuff is not overwhelming, but even so I'm still a n00b.)

Thanks for the help beforehand, and since I've never been around here to say it before, thanks to PyTom for making Ren'Py! I've had tons of fun with it!

User avatar
PyTom
Ren'Py Creator
Posts: 16088
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: Python minigames in Ren'Py?

#2 Post by PyTom »

If you want to use pygame, you can check out renpygame, available from:

http://www.renpy.org/wiki/renpy/Frameworks

Probably a better way to do this would be with user-defined displayables. They're totally different from pygame (for example, UDDs are event-driven). But they give you the full power of Ren'Py, includign the OpenGL acceleration.
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

jukebox
Newbie
Posts: 2
Joined: Thu Jun 09, 2011 12:28 pm
Location: Europe
Contact:

Re: Python minigames in Ren'Py?

#3 Post by jukebox »

PyTom wrote:If you want to use pygame, you can check out renpygame, available from:

http://www.renpy.org/wiki/renpy/Frameworks

Probably a better way to do this would be with user-defined displayables. They're totally different from pygame (for example, UDDs are event-driven). But they give you the full power of Ren'Py, includign the OpenGL acceleration.
Okay, thanks a lot! I'll be trying to get that to work!

Vict0r1994
Newbie
Posts: 19
Joined: Mon Apr 08, 2013 10:46 pm
Contact:

Re: Python minigames in Ren'Py?

#4 Post by Vict0r1994 »

Thank you very much for your advice. I had to customize the quest definition a bit to add titles to every quest (bits of text with bigger font size before the rest of the text) and color to differentiate main and secondary quests and so on, but I used the skeleton you gave me and it works perfectly, so thanks.
Yet, I can't say the same about the scree images. I want images to appear to the left of every inventory item, not above it, and as i use the "text" function for displaying items, when I use the "add" function it places the image either above or below the item, not near it. Here's the code for that screen: (maybe it was a mistake to display items this way, I don't know)

Code: Select all

screen aff_screen:
    frame:
        has vbox       
        $ current_money = inventory.money
        text "Money: [current_money] florins" 
        [color=#800000]add "Diamond_small.png" xalign 0.0 yalign 0.1[/color]
        text "Diamonds: [diamonds]"  
        text "Rubys: [rubys]"
        text "Emeralds: [emeralds]"
        text "Food: [food] meals"
        text "Rapier Swords: [rapier]"  
        text "Bows: [bow]"
        text "Crossbows: [crossbow]"       
        text "Heavy Swords: [sword]"
        text "Light Armors: [light Armor]"
        text "Heavy Armors: [heavy Armor]"
        imagebutton:
                idle "Return.png"
                hover "Return_hover.png"
                action Return()

label aff_screen_label:
    call screen aff_screen
    return
I highlighted the image adding function with red. Now, how could I make it appear next to the text? I tried placing it on the same row just in case it might work, but none of the functions ("add" and "text") accept one another as a valid child. So, what should I do?
Last edited by Vict0r1994 on Tue Apr 09, 2013 12:57 pm, edited 3 times in total.

User avatar
PyTom
Ren'Py Creator
Posts: 16088
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: Python minigames in Ren'Py?

#5 Post by PyTom »

Ren'Py code should go in [ code ] tags, to preserve indentation.

The easy way to put an image next to the text is to use an hbox, as shown below.

Code: Select all

screen aff_screen:
    frame:
        has vbox       
        $ current_money = inventory.money
        text "Money: [current_money] florins" 
        hbox:
            add "Diamond_small.png"
            text "Diamonds: [diamonds]"  
        text "Rubys: [rubys]"
        text "Emeralds: [emeralds]"
        text "Food: [food] meals"
        text "Rapier Swords: [rapier]"  
        text "Bow: [bow]"
        text "Crossbows: [crossbow]"       
        text "Heavy Swords: [sword]"
        text "Light Armors: [light Armor]"
        text "Heavy Armors: [heavy Armor]"
        imagebutton:
                idle "Return.png"
                hover "Return_hover.png"
                action Return()
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

Vict0r1994
Newbie
Posts: 19
Joined: Mon Apr 08, 2013 10:46 pm
Contact:

Re: Python minigames in Ren'Py?

#6 Post by Vict0r1994 »

Thanks! :)) Sorry for not observing that. It was pretty stupid of me.

Vict0r1994
Newbie
Posts: 19
Joined: Mon Apr 08, 2013 10:46 pm
Contact:

Re: Python minigames in Ren'Py?

#7 Post by Vict0r1994 »

I'm sorry if I'm being too persistent, but, well, does somebody know how could I add images near text in a screen? (not above or below) It's been two days and nobody tried to answer my question.

User avatar
Alex
Lemma-Class Veteran
Posts: 3090
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Python minigames in Ren'Py?

#8 Post by Alex »

Mmm... actually PyTom gave you an answer

Code: Select all

hbox:
            add "Diamond_small.png"
            text "Diamonds: [diamonds]"
Or do you mean something else?

http://www.renpy.org/doc/html/screens.html#hbox
http://www.renpy.org/doc/html/screens.html#vbox

Vict0r1994
Newbie
Posts: 19
Joined: Mon Apr 08, 2013 10:46 pm
Contact:

Re: Python minigames in Ren'Py?

#9 Post by Vict0r1994 »

Sorry for that. :oops: I had another another error in the code and that's why it didn't work. No, the hbox is fine. It works like a charm! Thank you very much Pytom!
However, I know that I my sound like ren'py newb, but I am one after all, and I would like to know if there is a way to save information contained within lists in ren'py. Here's the problem - apricotorange gave me this questlog skeleton:

Code: Select all

define questlist = []

screen quests:
  vbox:
    for i in questlist:
      text i

label addquest:
  $ questlist.append("Go find a sword")
In my game, I updated it a little bit for design like this:

Code: Select all

screen button2:
    vbox xalign 0.2 yalign 0.0:
        imagebutton:
                idle "button2.png"
                hover "button2_hover.png"
                action ui.callsinnewcontext("addquest")

screen quests:
  frame:
        has vbox
        text "{i}{size=14}Legend:{color=4bf81e} Green = Main Questline{/color}; {color=ecef0e} Yellow = Secondary Quest{/color}; White = Completed Quest;{color=cb0e0e} Red = Failed Quest{/color}{/size}{/i}"
        for i in questlist:
          text i
        imagebutton:
                idle "Return.png"
                hover "Return_hover.png"
                action Return()

label addquest:
  call screen quests
  return
Yet, the problem is that when I save a game and then load it, any added quests are no longer in the questlog, and as I use the python operations $ questlist.remove and $ questlist.append to update the information within a quest or make it completed/failed, the game gives me a fatal error as it has nothing to remove! I tried implementing an if statement or a python statement like

Code: Select all

if questlist = []:
  pass
else:
  $ questlist.remove ("{color=4bf81e}{i}{size=28}Text contained within{/size}{/i}{/color}")

Then again, I never studied informatics or programing and I don't know how python language works and why this doesn't work, but even if I'd manage to have the game not delete a quest if it wasn't there, it would be pretty strange for a player to see that a quest had simply vanished when he loaded a savegame, so it is possible to have them remembered by ren'py instead?
Again, sorry for asking so much questions, but it's just that I want this game to be good, as it isn't a test.

User avatar
PyTom
Ren'Py Creator
Posts: 16088
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: Python minigames in Ren'Py?

#10 Post by PyTom »

For a variable to be saved, it needs to be set after the game start. So instead of:

Code: Select all

define questlist = [ ]
do

Code: Select all

label start:
     $ questlist = [ ]
I haven't checked for other bugs, but this should fix the loading bug.
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

Post Reply

Who is online

Users browsing this forum: Bing [Bot]