Я пытаюсь создать систему опыта для своего летнего игрового проекта, но по какой-то причине она, похоже, не относится к функции системы опыта. Вот что я сделал:
global currentxp
currentxp = 0
global level
level = 1
def exp_system():
import random
mobxp = random.randrange(1, 20, 1)
currentxp = currentxp
currentxp = currentxp + mobxp
level = currentxp
if currentxp >= 100:
print("You Leveled Up!")
level_up = True
if currentxp < 100:
level_up = False
print("You need more xp to level up!")
if level_up:
currentxp = 0
print("Your Current XP is now:")
print(currentxp)
level = level + 1
print("You current level is now:")
print(level)
improvestst = input("Choose a stat to improve:(Health or Attack Power)")
else:
print("Your Current XP is now:")
print(currentxp)
print("You current level is now:")
print(level)
Для тестирования системы я использовал следующее:
mobhealth = 0
if mobhealth >= 0:
victory = True
if victory:
exp_system()
victory = False
Однако я получаю UnboundLocalError: локальная переменная 'currentxp', на которую ссылается перед присваиванием currentxp =currentxp на консоли Python. Я надеюсь, что кто-то может сказать мне, что я сделал неправильно, и привести пример, используя мои переменные. Спасибо!