Need help with Leveling System [SOLVED]

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
DewyNebula
Newbie
Posts: 15
Joined: Sun Apr 21, 2024 10:57 am
Contact:

Need help with Leveling System [SOLVED]

#1 Post by DewyNebula »

Hiya, I'm working on a level-up screen right now. Everything is working perfectly except for the increase in level-up points. I want the level-up points to correlate with the level. So, in level two, you have 2 points; in level three, you have 3. But, for level three and onward, you would always only have 1 point to spend since the other allotted amount is already used (I hope that makes sense). However, the level-up points remain one regardless of the player's level. Here is my code below:

Code: Select all

# player_stats file
default player_experience = 0
init python:
    def player_experience_func():
        return 500 * player_level
# player_leveling file
label player_leveling(amount):
    $ player_experience += amount
    if player_experience >= 500 * player_level:
        $ player_level += 1
        call screen player_level_up with dissolve
    return
screen player_level_up:
    modal True
    image "bg-level-up"
    # Finished leveling
    imagebutton auto "button-check-%s":
        align(0.6, 0.15)
        action Function(fill_health, 1000), Function(fill_willpower, 1000), Return()
    # Ability point total text
    vbox:
        align(0.415, 0.2)
        text "{size=+15}Points: [level_up]" xalign 0.5
# Ability points maximum
init python:
    player_level = 1
    init_level_up = player_level
    level_up = init_level_up
Last edited by DewyNebula on Fri May 17, 2024 12:51 pm, edited 1 time in total.

jeffster
Miko-Class Veteran
Posts: 520
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: Need help with Leveling System

#2 Post by jeffster »

I don't really understand the code, but to initialize variables that would be changed and used in saving and rollback, use default rather than init python. (For constants it's OK to use "init python").

I mean instead of

Code: Select all

init python:
    player_level = 1
    init_level_up = player_level
    level_up = init_level_up
use

Code: Select all

default player_level = 1
default init_level_up = player_level
default level_up = init_level_up
Note that it's the same as just assigning 1 to all of these variables, and later when you change player_level it wouldn't automatically change init_level_up.
If you try to use aliasing, it would work with mutable objects (like lists etc.), but

Code: Select all

player_level = 1
is an immutable value (integer) of 1. Hence

Code: Select all

init_level_up = player_level
would also make it an immutable integer 1, and later re-assigning player_level to something else wouldn't change init_level_up.
If the problem is solved, please edit the original post and add [SOLVED] to the title. 8)

jeffster
Miko-Class Veteran
Posts: 520
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: Need help with Leveling System

#3 Post by jeffster »

PS
DewyNebula wrote: Thu May 16, 2024 5:58 pm I want the level-up points to correlate with the level. So, in level two, you have 2 points; in level three, you have 3.
Then you don't need a separate variable for "level-up points". If it's always the same as "player level", just use "player level" variable there.
If the problem is solved, please edit the original post and add [SOLVED] to the title. 8)

DewyNebula
Newbie
Posts: 15
Joined: Sun Apr 21, 2024 10:57 am
Contact:

Re: Need help with Leveling System

#4 Post by DewyNebula »

jeffster wrote: Fri May 17, 2024 4:57 am PS
DewyNebula wrote: Thu May 16, 2024 5:58 pm I want the level-up points to correlate with the level. So, in level two, you have 2 points; in level three, you have 3.
Then you don't need a separate variable for "level-up points". If it's always the same as "player level", just use "player level" variable there.
Awesome thank you so much!

Post Reply

Who is online

Users browsing this forum: Bing [Bot], henne