I'm new to python and 'real' programming. I fucked around with logo and qbasic before briefly, but never anything serious.
I want to change a variable from inside a function, but it only creates a local one with the same name. How the fuck do i change the global variable? (in this case "current_room").
please explain it to me or link to something useful.
;_;
in b4 people flip out and call me names + act like fags and bitch about python
Name:
Anonymous2007-09-02 7:47 ID:Fm5EpQWi
I figured it out. Allow me to reveal my terrible fucking code. Keep in mind this is my first program that does more than compare numbers or draw colored hexagons using turtles.
#------START MAGIC CODE
import math
import string
import sys
world = [["You're in a dark and spooky room! There's some stairs going up from here.", 0] , ["You are on the second floor of the exceptionally scary tower! There's a shower to [WASH] up in.", 3] , ["Now you are on the third floor. THE REALLY REALLY SCARY THIRD FLOOR, OH GOD!",0] , ["You're at the top of the tower. It's not that scary up here, but the ceiling is pretty low!\nSeems like you could probably [WIN] from here.",0]]
global starting_room
starting_room=0
current_room=0
pissed=0
def print_pre():
print "\tWelcome to..."
print
print "\t\t\t*****************************************"
print "\t\t\t* *"
print "\t\t\t* D R A G O N ' S --- Q U E S T ! ! ! *"
print "\t\t\t* *"
print "\t\t\t*****************************************"
lines(1)
print "\tAKA 'The wizards tower' (Gold Dragon expansion pack sold separately)"
def help():
lines(1)
print "[HELP]:\nTry going [U]p or [D]own! You can [Q]uit.\nYou can check your [STATUS] if you'd like to.\nThere is a way to [WIN], but only those who are pure may do so! \nAlso there's no dragon, but on the upside this wizard's tower is pretty cool."
lines(1)
def stat():
global pissed
lines(1)
print "Status:"
if pissed != 1:
print "You are feeling alright"
if pissed == 1:
print "Your pants are soaked in urine. Oops."
lines(1)
def wash():
global pissed
if current_room == 1 and pissed == 0:
print "\nYou get all washed up and clean, but you can't help but feel weird getting nude in some strange wizard's shower.\n"
if current_room == 1 and pissed == 1:
print "\nYou get all washed up and clean, almost forgetting your earlier shame.\n"
pissed = 2
elif current_room != 1:
print "\nWash up in what?\n"
def move(dir):
global current_room
if dir == "u" or dir=="up":
if current_room + 2 > len(world):
lines(1)
print "You bumped your head! Ouch!"
lines(1)
return
else:
current_room = current_room + 1
if dir == "d" or dir=="down":
if current_room - 1 < 0:
lines(1)
print "There's no where to go down from here. You stop your feet angrily. Damn gravel!"
lines(1)
return
else:
current_room = current_room - 1
print_room()
global pissed
if current_room == 2 and pissed == 0:
print "-You have pissed yourself-"
pissed = 1
lines(1)
if current_room == 2 and pissed == 2:
print "This room isn't so scary anymore.\nIt does smell pretty strongly of urine, however\n"