Trying to set a number of times you can do an action....

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
ProxyPawaa
Newbie
Posts: 23
Joined: Sun Jan 16, 2011 5:43 pm
Contact:

Trying to set a number of times you can do an action....

#1 Post by ProxyPawaa »

Basically, I need to set a variable for time. A number. That I can decrease by one, and then test to see if it equals zero to see if a day ends, based on what choices a person makes during the day.

I've tried simply making it somthing like....

Code: Select all

    $ test = "0"
Followed by....

Code: Select all

   $ test += 1
When applicable... but unlike in the inventory and money page of the wiki (http://www.renpy.org/wiki/renpy/doc/coo ... ney_System), it had issues with the second line of code there, and refused to add the one to the value. Can anyone explain to me a way to do this? If possible, one that could be easily repeatable?

This is the full error code I got, for the record:
I'm sorry, but an uncaught exception occurred.

TypeError: cannot concatenate 'str' and 'int' objects

While running game code:
- script at line 25 of C:\Users\ProxyPawaa\Desktop\Folders\Game Development\Apples and Oranges; Dawn/game/script.rpy
- python at line 25 of C:\Users\ProxyPawaa\Desktop\Folders\Game Development\Apples and Oranges; Dawn/game/script.rpy.

-- Full Traceback ------------------------------------------------------------

File "C:\Users\ProxyPawaa\Desktop\Folders\renpy-6.11.2\renpy\bootstrap.py", line 270, in bootstrap
File "C:\Users\ProxyPawaa\Desktop\Folders\renpy-6.11.2\renpy\main.py", line 310, in main
File "C:\Users\ProxyPawaa\Desktop\Folders\renpy-6.11.2\renpy\main.py", line 93, in run
File "C:\Users\ProxyPawaa\Desktop\Folders\renpy-6.11.2\renpy\execution.py", line 259, in run
File "C:\Users\ProxyPawaa\Desktop\Folders\renpy-6.11.2\renpy\ast.py", line 574, in execute
File "C:\Users\ProxyPawaa\Desktop\Folders\renpy-6.11.2\renpy\python.py", line 957, in py_exec_bytecode
File "C:\Users\ProxyPawaa\Desktop\Folders\Game Development\Apples and Oranges; Dawn/game/script.rpy", line 25, in <module>
TypeError: cannot concatenate 'str' and 'int' objects

While running game code:
- script at line 25 of C:\Users\ProxyPawaa\Desktop\Folders\Game Development\Apples and Oranges; Dawn/game/script.rpy
- python at line 25 of C:\Users\ProxyPawaa\Desktop\Folders\Game Development\Apples and Oranges; Dawn/game/script.rpy.

Ren'Py Version: Ren'Py 6.11.2b
Something where I could add a minimum and maximum the number can go to as well would be just peachy. >.< I've been messing with this for about an hour now.... Thanks to anyone who helps!

User avatar
Camille
Eileen-Class Veteran
Posts: 1227
Joined: Sat Apr 23, 2011 2:43 pm
Completed: Please see http://trash.moe
Projects: the head well lost
Organization: L3
Tumblr: narihira
Deviantart: crownwaltz
itch: lore
Contact:

Re: Trying to set a number of times you can do an action....

#2 Post by Camille »

It's because you're putting quotes around the 0 in the first line, so you're making the variable a string. So then when you try to add to it, it won't let you because you can't add strings and integers like that. (which is exactly what the error message is telling you) Remove the quotations and it should work.

ProxyPawaa
Newbie
Posts: 23
Joined: Sun Jan 16, 2011 5:43 pm
Contact:

Re: Trying to set a number of times you can do an action....

#3 Post by ProxyPawaa »

Thank you Camille!!! That explains everything, and helped me fix all the issues.

The only thing now I'd like to do in top of this, is make a maximum for the number, and a minimum. Is that at all possible without some long python code at the start?

User avatar
Greeny
Miko-Class Veteran
Posts: 921
Joined: Sun Dec 20, 2009 10:15 am
Completed: The Loop, The Madness
Projects: In Orbit, TBA
Organization: Gliese Productions
Location: Cantankerous Castle
Contact:

Re: Trying to set a number of times you can do an action....

#4 Post by Greeny »

Long python code? No. But this reasonably short one should solve your problem.

Code: Select all

python:
    test = 0
    def addtest():
        if test < max:
            test += 1
    def subtracttest():
        if 0 < test:
            test -= 1

label scene:
    "Eileen" "I'm going to add one point."
    $ addtest()
    "Eileen" "I'm going to remove one point."
    $ subtracttest()
Been a while since I did python, someone correct me if I'm wrong. -_-''
In Orbit [WIP] | Gliese is now doing weekly erratic VN reviews! The latest: Halloween Otome!
Gliese Productions | Facebook | Twitter
Image

KimiYoriBaka
Miko-Class Veteran
Posts: 636
Joined: Thu May 14, 2009 8:15 pm
Projects: Castle of Arhannia
Contact:

Re: Trying to set a number of times you can do an action....

#5 Post by KimiYoriBaka »

the code greeny posted works if you just want to set a limit to what values a variable can have.

however, you said in your first post you wanted to check if it had reached the limit right?

that would be more like this:

Code: Select all

$ test += 1
if test >= 3:
    jump end_day
if you wanted to make a python function to do this for you it'd be something like this

Code: Select all

python:
    test = 0
    def addtest():
        test += 1
        if test > 3:
            return True
        return False

label scene:
    Eileen "now let's see if we have any time left"
    if addtest():
        Eileen "nope, where out of time"
    else:
        Eileen "Yep, we still have some left"
I would suggest avoiding that unless you have to though, as it's not that much effort to just copy and paste the simpler code where ever you need it.

Post Reply

Who is online

Users browsing this forum: Google [Bot], Kocker