Numbers problem

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
Hoseigndie
Regular
Posts: 31
Joined: Sat Jun 02, 2018 3:00 pm
Contact:

Numbers problem

#1 Post by Hoseigndie »

Hello all,

I have this code :

$ money = 200

In my game I'd like to be able to pick a sum, and it's taken out of "money".

For exemple, a code like that :

$ sum = renpy.input("how much?")

If you enter 100, the operation is 200-100 (money-sum).

I make this code, but it not work :(

$ sum = renpy.input("how much?")
$ money -= sum


Sorry for my english and thx for your help :)

nananame
Regular
Posts: 72
Joined: Fri Oct 13, 2017 1:40 pm
Contact:

Re: Numbers problem

#2 Post by nananame »

The player can input anything so the result of your sum is a text string. And then you are asking money to be reduced by a string. Which doesn't work. You should always post the error you get if you don't know what's wrong as that will help people answer you faster.

I think this should work if you do $money -= int(sum) ----> since int() turns the string into an integer number. Of course, you'd need to make sure it is an integer number prior to this, by only enabling the input to take numbers....

User avatar
IrinaLazareva
Veteran
Posts: 399
Joined: Wed Jun 08, 2016 1:49 pm
Projects: Legacy
Organization: SunShI
Location: St.Petersburg, Russia
Contact:

Re: Numbers problem

#3 Post by IrinaLazareva »

Code: Select all

    $ money = 200
    $ sayd = int(renpy.input("how much?", allow=['0','1','2','3','4','5','6','7','8','9']) or 0)

    ## at this step, you can enter a condition if you need it. Like:  if sayd > 200: ... elif  .. else).

    $ sum = money - sayd
    'You say [sayd]? The rezult of operation is [sum]'
https://docs.python.org/2.7/library/std ... ng-complex
https://www.renpy.org/doc/html/input.html#renpy.input
example of condition with numbers

Hoseigndie
Regular
Posts: 31
Joined: Sat Jun 02, 2018 3:00 pm
Contact:

Re: Numbers problem

#4 Post by Hoseigndie »

Thx, it's perfect !!!!

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]