Page 1 of 1

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

Posted: Sat Jan 14, 2012 1:44 am
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!

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

Posted: Sat Jan 14, 2012 1:57 am
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.

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

Posted: Sat Jan 14, 2012 2:01 am
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?

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

Posted: Sat Feb 11, 2012 1:48 pm
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. -_-''

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

Posted: Sun Feb 12, 2012 1:07 pm
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.