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
Numbers problem
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.
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.
-
- Regular
- Posts: 31
- Joined: Sat Jun 02, 2018 3:00 pm
- Contact:
Re: Numbers problem
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....
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....
- IrinaLazareva
- Veteran
- Posts: 399
- Joined: Wed Jun 08, 2016 1:49 pm
- Projects: Legacy
- Organization: SunShI
- Location: St.Petersburg, Russia
- Contact:
Re: Numbers problem
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://www.renpy.org/doc/html/input.html#renpy.input
example of condition with numbers
-
- Regular
- Posts: 31
- Joined: Sat Jun 02, 2018 3:00 pm
- Contact:
Re: Numbers problem
Thx, it's perfect !!!!
Who is online
Users browsing this forum: Bing [Bot], Google [Bot]