Feel free to edit this post if it requires it.
Hi, I have been learning python for two months now, and I just finished learning about functions and blue bean logic. I decided to try my hand at making a text adventure on the side while I am not in class, and seeing how it turns out at the end of the semester. My tutor is not available this week, or the next, so I take my questions here. I feel like my problem has to do with me not fully understanding how the global variables work yet, as I just started using them, or if I should even use them to store data for this purpose. The idea I have with this game is essentially to run on calling a bunch of functions that I will make when I need them to, because I feel like it is pretty efficient for what I know. Running this code gives the error "positional argument is missing" if you are to run it. What could I do better here? I tried to integrate a function to test it out too, so that it would be easier to give me assistance.
tldr; how can I make the experience points system I am trying to envision work so that it saves the number of experience points that are gained, then adds that number to the new higher requirement of experience for the next level as in most RPG games? For example, upon adding five experience, the program errors out. Thanks in advance for reading this! I hope I adequately explained my issue.
here is the code that I have come up with so far
global playername
playername = "Name Jeff 21 Bruh"
global playerlvl
playerlvl = 0
global xpcurrent
xpcurrent = 0
global xpnext
xpnext = int(((playerlvl * 4) / 3) + 4)
global xpgained
xpgained = 0
def show_stats():
print("*" * 20, "\n")
print(playername, "the Adventurer")
print("Lvl", playerlvl)
print("EXP =", xpcurrent, '/', xpnext)
print("-_" * 16 + '\n')
def lvlup(xpgained):
global xpcurrent
xpgainedhere = xpgained
xpcurrent += xpgained
xpgained = 0
if xpcurrent >= xpnext:
playerlvl + 1
xpcurrent -= xpnext
print("~ ~", playername, "is Lvl", playerlvl, "! ~ ~")
if xpcurrent >= xpnext:
lvlup()
else:
show_stats()
else:
print("~ ~", playername, "gained", xpgainedhere, "Exp! ~ ~")
show_stats()
def game_main():
print("*" * 50)
print("This is where the game begins.")
# ------just before this \n (the '.' )is the character limit
# ---------------------------------------------------------V
print("The player after lines of text can enter commands.\n"
"use this to enter commands to test them.")
print("*" * 50, "\n")
def testexp():
addexp = int(input("type the integer for how much exp "
"that you would like to add\n"))
lvlup(addexp)
testexp()
testexp()
testexp()
testexp()
testexp()
testexp()
testexp()
testexp()
game_main()