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.
I'm trying to do a simple exp system in my game, where defeating the enemy will reward the player exp when they win. When exp is over 99 (So, at least at 100), they'll level up. I thought that I did it right, but as I'm still learning, it's no surprise that I messed up again. Here is the exp - leveling up code:
$ level = 1
$ exp = 0
if exp >= 99 and <299:
$ level = 2
if exp >= 299 and <599:
$ level = 3
if exp >= 599 and <999:
$ level = 4
if exp >= 999 and <1499:
$ level = 5
if exp >= 1499 and <2099:
$ level = 6
if exp >= 2099 and <2799:
$ level = 7
if exp >= 2799 and <3599:
$ level = 8
if exp >= 3599 and <4499:
$ level = 9
if exp >= 4499 and <5499:
$ level = 10
if exp >= 5499 and <6599:
$ level = 11
if exp >= 6599 and <7799:
$ level = 12
if exp >= 7799 and <9199:
$ level = 13
if exp >= 9199 and <= 15999:
$ level = 14
if exp >= 15999:
$ level = 15
And if someone can help me with my renpy.random.randint problem here, I'd appreciate it. It's really bringing my game to a halt, as the battle and random encounter system relies on this.
$ level = 1
$ exp = 0
if exp >= 99 and exp < 299:
$ level = 2
if exp >= 299 and exp < 599:
$ level = 3
if exp >= 599 and exp < 999:
$ level = 4
if exp >= 999 and exp < 1499:
$ level = 5
if exp >= 1499 and exp < 2099:
$ level = 6
if exp >= 2099 and exp < 2799:
$ level = 7
if exp >= 2799 and exp < 3599:
$ level = 8
if exp >= 3599 and exp < 4499:
$ level = 9
if exp >= 4499 and exp < 5499:
$ level = 10
if exp >= 5499 and exp < 6599:
$ level = 11
if exp >= 6599 and exp < 7799:
$ level = 12
if exp >= 7799 and exp < 9199:
$ level = 13
if exp >= 9199 and exp <= 15999:
$ level = 14
if exp >= 15999:
$ level = 15
When using a conditional joined by 'and', there needs to a complete statement on both sides. if (statement 1) and (statement 2). For the following line of code that you originally had:
It looks at 'exp >= 99' and that's a complete and syntactically correct statement that can evaluate properly. It looks at the right-hand side as ' < 299' and that is incorrect syntax. The code does not assume that you still want to use the same variable from earlier in the statement and therefore you need to explicitly use it each time.
Thank you both! I shall try to keep this in mind, jw2pfd, as I shall no doubt use it again. Anima, what did you mean by elif statements? I've always seen it as an else statement when there are a lot of those statements, but I'm a noob, so I use a lot of things that I don't understand. The Ren'Py documentation has a lot of info, but not enough examples or really technical language.
As you see you only need one test instead of two. It's also faster since it stops when the right level is reached.
The elif clauses are only elevated if the preceding if or elif clause was false. You can also keep the current order but need to change the comparison to lesser than.
If you just use else followed by if you would have to do an extra indentation, making the code look rather ugly when you have a lot of them stacking on top of each other. elif allow you to avoid that.