Ren'Py Adding money based on other variable

D.mon

Newbie
Game Developer
Dec 29, 2023
35
468
Sorry if this has been asked before, but I havent found an answer yet.

Is it possible to add a certain amount based on another variable to my money variable?
for example:
Code:
$ money += [income]
basically I have multiple conditions to adding money, which would be more convenient if I could define the amount in another variable, avoiding having to rewrite the same code for each condition.
The code here gives me an error:

Code:
TypeError: unsupported operand type(s) for +=: 'int' and 'RevertableList'
Thanks in Advance!
 

peterppp

Active Member
Mar 5, 2020
763
1,349
lose the []. that's used to display the value inside strings, like when talking
Code:
$ money += income
 
  • Like
Reactions: D.mon

D.mon

Newbie
Game Developer
Dec 29, 2023
35
468
lose the []. that's used to display the value inside strings, like when talking
Code:
$ money += income
Yep, that works!
Thank you very much. Appreciate it!

I think I understand it now, basically when putting the variable in [], it displays the variable rather than using it? Or something like that... XD
 
  • Like
Reactions: peterppp

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,979
16,236
I think I understand it now, basically when putting the variable in [], it displays the variable rather than using it? Or something like that... XD
Yes but no ; in fact, mostly no.

"I earn [income] every month" is something purely specific to Ren'Py. It only apply in a really limited number of context ; to dialog lines, menu choices, as well as text and textbutton screen statements.
In such use, it mean "display the text representation of that variable", with whatever between the [] being the name of the variable.

But anywhere else, brackets are a list materialisation. Hence the error message you got.


Understanding variables being the only effective mandatory knowledge needed when using Ren'Py, I recommend you the reading of the "newbie guide to basic variables in Renpy" how-to, including the links in its first post.
 
  • Like
Reactions: D.mon

D.mon

Newbie
Game Developer
Dec 29, 2023
35
468
I see, I think I get it.
Correct me if I'm wrong, you're referring to the difference between ren'py specific functions and python commands? Would make sense since using "$" is a python command.

I have been working for some time on my game, so I'm familiar with the basics of variables and other functions with in ren'py and some of python (admittedly, struggling the most with it.)

But thank you, I appreciate the explanation and reference you've given me.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,611
2,258
To (over) clarify a bit...

$ money += income
... is almost pure python (as you say, the $ is effectively "do python command").

mc "I have $[money]."
... is almost pure RenPy. Where you have a string (the bits between quotes) and a string substitution (swapping everything between the [ ] for the value of a variable). Python has , but it doesn't do it this way.

Context matters, as RenPy is a mix of scripting languages. All are technically "RenPy" except , but all are used for very specific things. So one common script is the how RenPy handles , another is how RenPy handles , another is how RenPy handles .

For the most part, don't worry about it. You likely don't need custom screens yet, very few people use animated graphics that way any more (video has replaced a lot of it). So you're left with "characters talk" and "variables are used to keep track of the player's choices".

You can literally write a full RenPy story using as few as 4 (out of a possible 8) RenPy statements. For more of a "game" rather than story, expand that by another 6 statements. Then once you get more ambitious, there's all the other statements and commands to pick from. RenPy is as simple or complicated as you need it to be.