Tuesday, 15 June 2010

function - What's stopping these variable's from being defined in my code? -



function - What's stopping these variable's from being defined in my code? -

i've been designing game, , ive come across weird problem. maybe it's simple i've missed or way formatted it. when run code these errors suggest none of variables i've been defining beingness declared/defined. on top of none of functions seem run... should define text1, button1name, etc... global variable? or improve way?

class="snippet-code-js lang-js prettyprint-override">##project 1 v4 ##structure whole programme base of operations functionality ##begin outline fill in functions , windows v2, , v3. import tkinter import random inventory=[] playcount=0 def startgame(): ##adds name ##button calls storycard text1="welcome treasure quest!! game allows pick own destiny! treasure quest simple game. story display on screen until reaches event. @ each event shown 2 choices. each decision may cause leave more treasure or die horrible death... still true or false question on final exam, have 50/50 chance of ruining entire life if not know! know how play, please click button below start game!" button1= introcard() button1name="play" button2= win.destroy button2name="quit" def introcard(): text1="you bravest knight in service of great kingdom universitas! kingdom has long been icon throughout world, faces great peril. king of universitas has foolishly spent entirety of kingdoms fortune shopping online. hope kingdom, find money pay off it's debts. luckily scrolls have been found describe locations of hidden treasures. have been selected find these treasures. except?" button1=wincard() outcome1="you embark upon quest!" button1name="accept!" button2=losscard() outcome2="the kingdom falls debt , die of dysentary... nice going oregon trail..." button2name="decline!" def storycard(n):##this function randomly select story chunk ##recieves random int ##tests true int w/ if else line ##story blurbs these stored in v2 re-create them! if n ==1: text1="you come across dark cave... dragon said lurk within... come in , see holy sword... how take it?" button1=losscard() outcome1="the dragon bakes crisp... sorry!" button1name="bargain it!" button2=wincard() outcome2="victory! sneak past dragon , create off sword!" button2name="steal it!" #get="holy sword" elif n==2: text1="you come across mummys tomb... see 2 doors. take front end entrance or hidden entrance?" button1=wincard() outcome1="the mummy awake , glad company! feeds tea , sets on way gifts!" button1name="front" #get="a beautiful glass vase!" button2=losscard() outcome2="the mummy sees you! screams thief! , shivs you..." button2name="hidden" elif n==3: text1="you come across magic tree inhabited elves. inquire climb , see beautiful home." button1=losscard() outcome1="you climb high slip off branch , fall death. elves laugh." button1name="climb" button2=wincard() outcome2="the elves perplexed why not want see them. come downwards , give new couch show off things." button2name="stay" #get="a rad couch" elif n==4: text1="you come across cave filled unusual lights! troll stands guard." button1=wincard() outcome1="this hip , happening new dwarven nightclub! troll lets in because seem cool! dwarves give rare cave mushrooms. seems lame said kings regular , go on well. have fun night... drink much ale , late start next morning though..." button1name="strut in!" #get="rare mushrooms" button2=wincard() outcome2="this hip new dwarven nightclub! bouncer troll won't allow in though... oh well! dwarves hipsters anyways! gratefull company troll gives amulet!" button2name="wait in line." #get="sweet amulet" elif n==5: text1="you come across hut in woods! owned merlin! great wizard starts conversation , invites inside!" button1=losscard() outcome1="insulted, merlin kills axe... have expected magic... no, merlin psychopath , prefers murder axes." button1name="leave" button2=wincard() outcome2="he talks god damned grandkids 4 hours... grateful company , lets leave staff." button2name="enter" #get="a sweetness staff" ## each if, elif, ect must contain ##text blurb ##button 1 function def ##button 2 function def ##button 1 name ##button 2 name ##outcome 1 text ##outcome 2 text def wingame(): text1="congratulations!! have collected plenty treasure pay off kingdoms debts! forever known people great knight! king in debt!" button1name="hooray!" button1=win.destroy button2name="huzzah!" button2=win.destroy def wincard():##describes how event played out #inventory.append[get] playcount+=1 text1= outcome1 or outcome2 if playcount == 5: button1name="onward!" button1=wingame() button2name="go forth!" button2=wingame() else: button1name="onward!" button1=storycard(random.randint(1,5)) button2name="go forth!" button2=storycard(random.randint(1,5)) def losscard(): text1=outcome1 or outcome2 button1name="game over" button1= win.destroy button2name="game over" button2= win.destroy startgame() win=tkinter.tk() win.title("treasure quest!!") textlabel=tkinter.label(win,text = text1,font=('times new roman',12),justify=left,) textlabel.pack() row2=tkinter.frame(win) btn1=tkinter.button\ (row2, text=button1name, command=button1,font=('times new roman',12)) btn2=tkinter.button\ (row2, text=button2name, command=button2, font=('times new roman',12)) btn1.pack(side='left') btn2.pack(side='left') row2.pack() win.mainloop()

when run code these errors:

class="snippet-code-js lang-js prettyprint-override">traceback (most recent phone call last): file "c:/users/logan/desktop/project#1v4.py", line 141, in <module> startgame() file "c:/users/logan/desktop/project#1v4.py", line 17, in startgame button1= introcard() file "c:/users/logan/desktop/project#1v4.py", line 26, in introcard button1=wincard() file "c:/users/logan/desktop/project#1v4.py", line 116, in wincard playcount+=1 unboundlocalerror: local variable 'playcount' referenced before assignment

if want alter global variable in function, need utilize keyword global follows -

def wincard():##describes how event played out global playcount #inventory.append[get] playcount+=1

function python-2.7 variables tkinter global-variables

No comments:

Post a Comment