Ich bin (versucht), ein Hacker-Spiel wie Hack Run oder Hacknet zu machen. Aber nur das Terminal. Ich bekomme diese Fehlermeldung, wenn ich versuche 86 die Variable ‚currentip‘ in Zeile zu drucken („print (“ Sie befinden sich auf „+ currentip +“ „)“.):Ich kann den Fehler in meinem Python-Code nicht finden
UnboundLocalError: local variable 'currentip' referenced before assignment
Dies sieht aus wie ein einfacher Fehler aber ich kann es nicht herausfinden. Ich habe es zugewiesen. Mehrmals. Vielleicht lese ich die Auftragsausführung falsch, aber ich kann keine Information finden, die sagt, dass ich es falsch mache ...
Alle Ideen für die Reinigung und damit es besser/besser ist auch sehr geschätzt.
import os
import random
from time import sleep
os.system("cls")
save = {}
ips = {"1337.1337.1337.1337": "Cheater's Stash"}
shells = []
storyips = ["Bitwise Test PC"]
currentip = "1.1.1.1"
homeip = "1.1.1.1"
def resetip():
ip1 = random.randint(1, 999)
ip2 = random.randint(1, 999)
ip3 = random.randint(1, 999)
ip4 = random.randint(1, 999)
homeip = str(ip1) + "." + str(ip2) + "." + str(ip3) + "." + str(ip4)
if homeip in ips:
resetip()
else:
ips[homeip] = "Your Computer"
currentip = homeip
def storyreset():
for x in storyips:
ip = (0, 0, 0, 0)
ip1 = random.randint(1, 999)
ip2 = random.randint(1, 999)
ip3 = random.randint(1, 999)
ip4 = random.randint(1, 999)
ip = str(ip1) + "." + str(ip2) + "." + str(ip3) + "." + str(ip4)
if ip in ips:
storyreset()
else:
ips[ip] = x
def start():
os.system("cls")
print("Python 3.5, HackSim 1.1")
print("")
print("Loading modules...")
print("")
sleep(1)
print("OS Loaded.")
sleep(0.5)
print("HELP Loaded.")
sleep(0.5)
print("FILE USE Loaded.")
sleep(1)
print("CONNECTIONS Loaded.")
sleep(0.5)
print("UTILS Loaded.")
sleep(0.5)
print("HACKS Loaded.")
print("")
sleep(1)
print("Initiating command line...")
sleep(1)
commandline()
def usecommand(c):
if c == "reboot":
print("Rebooting...")
sleep(3)
start()
elif c == "clear":
os.system("cls")
elif c == "quit":
quit()
elif c == "forkbomb":
del ips[currentip]
if homeip in ips:
currentip = "Your Computer"
else:
resetip()
currentip = "Your Computer"
elif "connect " in c:
if c[8:] in ips:
connectip = ips[c[8:]]
print("Connecting to ", connectip, " ", c[8:], "...")
currentip = connectip
else:
print("This ip does not exist.")
elif c == "connect":
print("You are currently at " + currentip + ".")
print("The syntax of this command is: connect <ip>.")
else:
print("Invalid command. Either the command does not exist or check the required syntax.")
def commandline():
while True:
command = input("> ")
usecommand(command)
storyreset()
resetip()
start()
Vielen Dank!
Bitte geben Sie hier die relevanten Teile Ihres Quellcodes sowie den Fehler stacktrace, den Sie beim Ausführen des Programms erhalten, an. –
Stacktrace: http://pastebin.com/DkYdgPDV –
Wie für die relevanten Teile ... Ich habe keine Ahnung. Ich bin ein Anfänger mit Python. –