Python Forum
I'm getting an error, please help! thanks
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I'm getting an error, please help! thanks
#1
The problem is that I want to set a default value to the crate_num's and if they receive a crate, it adds one to the default value. In def start() you can see how I'm attempting to add a value to the default value, but it gives me an error. I don't want to set the value to 1, I want to add 1 to it, so if I have 2 crates and I receive another one, I then have 3 crates. thanks

ERROR:
[pyflakes] local variable 'starting_crate_num' defined in enclosing scope on line 5 referenced before assignment
[pyflakes] local variable 'starting_crate_num' is assigned to but never used

import os
from time import sleep
import random

starting_crate_num = 0
basic_crate_num = 0
rare_crate_num = 0
ultra_rare_crate_num = 0
epic_crate_num = 0

starting_crate = ["basic sword", "basic shovel", "basic rock"]
starting_random = random.choice(starting_crate)

print('before we begin, please enter you name')
name = input('> ')
money = 0
player = {"name": name, }
os.system('clear')

def start():
	os.system('clear')
	print('..You have started the game..')
	sleep(1.5)
	os.system('clear')
	print("To start you off, you're given a basic crate!")
	starting_crate_num += 1
	print('Would you like to open your crate?')
	answer = input("> ")

	if answer == "1":
		open_crate()
	elif answer == "2":
		print('')
	else:
		print()

def open_crate():
	print('...Available crates...')
	if starting_crate_num > 0:
		print(starting_crate_num)
	else:
		pass

	if basic_crate_num > 0:
		print(basic_crate_num)
	else:
		pass

	if rare_crate_num > 0:
		print(rare_crate_num)
	else:
		pass

	if ultra_rare_crate_num > 0:
		print(ultra_rare_crate_num)
	else:
		pass

	if epic_crate_num > 0:
		print(epic_crate_num)
	else:
		pass


def welcome():
	os.system('clear')
	print("Welcome to Crates, " + name + '!')
	print("(1) Start")
	print("(2) Info")
	answer = input("> ")

	if answer == "1":
		start()
	if answer == "2":
		info()
	

def info():
	os.system('clear')
	print("...Welcome to How To Play!...")
	print("""To play, you have to go on quests, while on quests,
you have a chance to find a crate. but, you also have a chance
of finding an enemy. If you don't have a weapon that is capable
of defeating that enemy, you die and lose all items you own.
You can decide the levels of quest you want to go on, and the more You
progress, the harder difficulty of quest you can go on. The higher level
your character is, you can complete quests faster, and you become stronger.
If you find a crate, you can find random items inside, depending on the quest,
and what level of crate it is, you can get better or worse items.""")
	print('------------------------------------------')
	print("Please type '1' to go back to the main menu!")
	start = input('> ')

	if start == "1":
		welcome()
	else:
		print("Invalid, please type '1'")
		info()




welcome()
Reply


Messages In This Thread
I'm getting an error, please help! thanks - by AlluminumFoil - Jan-08-2020, 08:44 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020