phyton tutorial?

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
herenvardo
Veteran
Posts: 359
Joined: Sat Feb 25, 2006 11:09 am
Location: Sant Cugat del Vallès (Barcelona, Spain)
Contact:

phyton tutorial?

#1 Post by herenvardo »

That's simple: I'm working on my game using Ren'Py, and even I feel it's good enough, I just feel that I need more. What I most like of Ren'Py's features is that it allows you to include phyton code, so it automatically embedes phyton features. I like it, the only problem is that I don't know phyton; but I'm confident that if I find a good tutorial I'll be able to take profit of it to implement the 'non-novel' (more precisely, rpg) features that I want my game to have.
So, the question is: does somebody know about a phyton tutorial, introduction or reference to look at?

Thanks ^_^
I have failed to meet my deadlines so many times I'm not announcing my projects anymore. Whatever I'm working on, it'll be released when it is ready :P

User avatar
PyTom
Ren'Py Creator
Posts: 16096
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:

#2 Post by PyTom »

Okay, it's python, not phython, so that could have hurt your search for python tutorials.

For people who have never programmed before, the best Python tutorial is "How to Think Like a Computer Scientist Learning with Python". It can be found at:

http://www.ibiblio.org/obp/thinkCSpy/

If you already know how to program, the official python tutorial is probably best. Along with the Library reference (which is also useful), it can be found at:

http://docs.python.org/

Please note Ren'Py still uses Python 2.3.
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

herenvardo
Veteran
Posts: 359
Joined: Sat Feb 25, 2006 11:09 am
Location: Sant Cugat del Vallès (Barcelona, Spain)
Contact:

Thanks

#3 Post by herenvardo »

Wops, it seems I moved a 'h' out of its place :oops:
Anyhow, thanks. I've been in programming for years and I guess the official tutorial will be fine. I feel it take more fun to learn two languages (Ren'Py and python) 'on the fly' in a NaNoRenO... this makes it even more challenging. I guess that next year I'll search for a new engine to work with, so I'll keep the challenge level high at the same time I get new knowledge :P (I only took two weeks to learn Java, and some years before I learnt VB in one month... php took me around the same time).
Wow, I just seen that python has OOP and even inheritance. Is this supported in the version Ren'Py works with? Maybe I'll take profit from OOP, but guess that I won't work on complex class hierarchies due to the deathclock 8)

Well, PyTom, thanks for your help. Surely it'll be enough to implement my combat system and to manage the shops that appear in my game.
I have failed to meet my deadlines so many times I'm not announcing my projects anymore. Whatever I'm working on, it'll be released when it is ready :P

User avatar
PyTom
Ren'Py Creator
Posts: 16096
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:

#4 Post by PyTom »

Ren'Py embeds the full python, so you can use objects all you want. That being said, to ensure saving and rollback work, you'll want to make sure that all of the objects that live longer than a single python block are serializable, meaning that they inherit from object, and they use classes defined in a python block defined inside an init block.
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

herenvardo
Veteran
Posts: 359
Joined: Sat Feb 25, 2006 11:09 am
Location: Sant Cugat del Vallès (Barcelona, Spain)
Contact:

#5 Post by herenvardo »

PyTom wrote:Ren'Py embeds the full python, so you can use objects all you want. That being said, to ensure saving and rollback work, you'll want to make sure that all of the objects that live longer than a single python block are serializable, meaning that they inherit from object, and they use classes defined in a python block defined inside an init block.
I'm not even sure I'll use objects, since I've only 23 more days to finish the project... I'll maybe use some objects to represent shops and to implement the combat system, but they will be (relatively) static and created in the init block, so no saving will be needed.
Anyhow, I'm just noticing that I'll need to disable saving the game during the combat... and now I understant why so many games do that: saving the combat status would be to weird! (Is there any way to temporaly disable saves?).
In addition, as working on the combat & encounter system, I've found another problem. How should I do to print a % character from a 'say' statement? It's getting me in lots of trouble :? Can it be scaped in the C/C++ way "\%"?

Thanks for all the help ^^
I have failed to meet my deadlines so many times I'm not announcing my projects anymore. Whatever I'm working on, it'll be released when it is ready :P

User avatar
PyTom
Ren'Py Creator
Posts: 16096
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:

#6 Post by PyTom »

I'd need to check, but I don't think there's an easy way to disable saving. I'm not sure that it's necessary, either... I believe Ren'Py should do the right thing, depending on how you save during combat. As long as all global variables are of reasonably simple types (int, float, list, tuple, dict, string, unicode, etc... just not odd types like iterators, generators, files, and so on), then you should be okay to save.

Just realize that only things reachable from variables changed outside of init blocks is saved. So if you have code like:

Code: Select all

init:
    python:
        class MyObject(object):
            pass

        a = MyObject()
        a.foo = 1

label start:
    $ b = MyObject()
    $ b.foo = 1

    "blah"

    $ a.foo = 2
    $ b.foo = 2

    "blah"

    "save/load here"
When you load the game, a.foo will be 1 and b.foo will be 2, since the variable a (as opposed to the object pointed to by a) was never changed outside of an init block, and hence won't be saved.
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

herenvardo
Veteran
Posts: 359
Joined: Sat Feb 25, 2006 11:09 am
Location: Sant Cugat del Vallès (Barcelona, Spain)
Contact:

#7 Post by herenvardo »

Thanks, PyTom! Your example is very illustrative.
I guess my code will be something like this:

Code: Select all

init:
    python:
        class Monster(object):
            # here will go some data that defines each monster
            pass #this line will gu out once I put real data here
        troll = Monster()
        # troll.field = something and so on, defining how a 'troll' is in the game
        ork = Monster()
        # and so on defining the existing monsters
start:
    $ m1 = Monster()
    $ m2 = Monster()
    # and so on up to the maximum number of monster per encounter
Then, I'll make a funcion fight(monster, amount) which will copy the appropriate amount of monsters in m1, m2, etc; and will track there the status of the monster (such as lifepoints and so) as the combat goes on. So, I'll guess the monsters status will be saved if the player saves the game during a combat. The player's character status won't be a problem, because it's managed through global simple variables (like char_race, char_class, char_life, etc). The only point that worries me is if the load process will be able to put the current execution point inside a phyton function.

About the other question I asked in my previous post, I've resolved it by myself, through imagination and the ever-working test&fail method. I'll put here my answer in order to help any other who has the same problem:
I needed to put a % character in the strings said by the 'Game Master' character, to provide some important system information. I tried to scape it using the backslash: "\%", but it didn't work; but then remembered C's printf format strings, where % does a similar job than in RenPy's say statement: the C method to take % as a literal worked also in Ren'Py: as easy as putting %% (the first one is supposed to indicate that something has to be inserted there, the second one tells, as I guess, that what must be inserted is a plain, literal % character).

So, thanks again for so much help, and hope I don't need too much more to put the game to work definitely.
Last edited by herenvardo on Wed Mar 08, 2006 2:01 pm, edited 1 time in total.
I have failed to meet my deadlines so many times I'm not announcing my projects anymore. Whatever I'm working on, it'll be released when it is ready :P

User avatar
PyTom
Ren'Py Creator
Posts: 16096
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:

#8 Post by PyTom »

The load process won't be able to place the current execution point inside of a python block. It will place the execution point at the start of the current python block, or perhaps sometime before that. Loading will also reset the variables to the appopriate point, so everything should work out.

If you do the battle as one python function, then everything should work, and if the user saves he'll be returned to the start of the function when he loads.
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

herenvardo
Veteran
Posts: 359
Joined: Sat Feb 25, 2006 11:09 am
Location: Sant Cugat del Vallès (Barcelona, Spain)
Contact:

#9 Post by herenvardo »

PyTom wrote:If you do the battle as one python function, then everything should work, and if the user saves he'll be returned to the start of the function when he loads.
Then I guess I'll have to track the turn order and this kind of data in global variables, also. Well, it can be done... if I've writen around 70% of the story script in the first week, I should be able to implement all this stuff during the remaining 23 days 8) :P
I have failed to meet my deadlines so many times I'm not announcing my projects anymore. Whatever I'm working on, it'll be released when it is ready :P

User avatar
PyTom
Ren'Py Creator
Posts: 16096
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:

#10 Post by PyTom »

Sure. And if you want me to check it over once you have something basic working, let me know. There may be some things that I've internalized, but haven't been able to articulate, although I think I've covered the basics.
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], Google [Bot]