Global variables - Set max and min values

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.
Message
Author
philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Global variables - Set max and min values

#16 Post by philat »

I don't know how you structured your game or exactly what kind of game mechanics you're going for, but it seems like jumping to a renpy label from code that's being called after every python block would be a bad idea in general.

I would seriously just give the DSE a look. Poke at it and see how it's set up -- the scheduler and code you can run at the start of each day with the scheduler, an event runner to handle activities that are picked, then a loop back to the scheduler. You don't have to use it in full, but the logic and mechanics will help you set up your own game.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Global variables - Set max and min values

#17 Post by xela »

cardium wrote:Yeah this is what I initially have done thank you. But I want to change and check my value in every action, so PyTom solution was more appropriate for my problem. Now I am trying to find how to Jump after the if in that code for example:

Code: Select all

init python:
    def limit_stats():
        try:
            if store.energy < 0:
                store.energy = 0
                renpy.jump("need_sleep")
            elif store.energy > 100:
                store.energy = 100
renpy.jump(label) or renpy.jump_out_of_context(label) are not working, but I will think of something. Thanks again!
This will do as you ask:

Code: Select all

init python:
    def limit_stats():
        if hasattr(store, "energy"):
            if store.energy < 0:
                store.energy = 0
                renpy.jump("need_sleep")
            elif store.energy > 100:
                store.energy = 100

    config.python_callbacks.append(limit_stats)
There is nothing wrong with wanting to jump to a label whenever a character gets tired, I do the same thing in my game when a characters health reaches 0 (game_over label) but in my case it will work even in the middle of a (very) long python block :)

I'd suggest to use a <= operator or nothing will happen if energy just reaches 0 and not below.
Like what we're doing? Support us at:
Image

BlueDragon
Newbie
Posts: 3
Joined: Mon Jul 24, 2017 4:49 pm
itch: Abhainnairgid
Contact:

Re: Global variables - Set max and min values

#18 Post by BlueDragon »

How to do this now? I tried putting in the code and it said "indentation mismatch", did I just do it wrong?
This is what I put (in the options file).

Code: Select all

init python:
     def limit_stats():
           try:
               if Health < 0:
                    Health = 0
               elif Health > 100:
                    Health = 100
          except:
               pass

    config.python_callbacks.append(limit_stats)

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

Re: Global variables - Set max and min values

#19 Post by Alex »

Lines with "try:" and "except:" must have equal number of spaces (be indent the same). For now "try:" has 11 spaces and "except:" has 10 spaces - change it.

https://www.renpy.org/doc/html/language ... and-blocks

BlueDragon
Newbie
Posts: 3
Joined: Mon Jul 24, 2017 4:49 pm
itch: Abhainnairgid
Contact:

Re: Global variables - Set max and min values

#20 Post by BlueDragon »

Okay, that fixed it, thank you!

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Majestic-12 [Bot]