Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Nsutton

macrumors member
Original poster
Dec 29, 2009
92
0
6 Feet Under
In a function like this how can you find out if a variable (inv) contains the necessary quest items and put that into an if statement. I've tried a few ideas but none work...

Code:
#Tavern Class
class tavern():
    def taver_n(self):
    #if quest is in progress or finished
        if currnt_quest=="Chef's Helper":
            done=raw_input("Chef Bill: You finish the quest yet? [yes/no] ")
            if done=="yes":
                if inv #IF INV CONTAINS QUEST ITEMS
                    global gold
                    gold+=500
                    print "Chef Bill: Great Job! Here's $500 for your troble..."
                    print "Reward of 100xp!"
                    global exp
                    global level
                    exp+=100
                    if exp>=100:
                        print "Level up! \n You are now level"+level+"."
                        level=2
I need this to see if the player has meet the requirements to complete the quest.
 
This doesn't use a class, and is probably poor in a number of ways. I don't know python. For the specific question you had, the "in" keyword is what you're looking for.

Code:
exp = 0
gold = 0
level = 1

def visit_tavern(current_quest,inv):
	if current_quest=="Chef's Helper":
		done=raw_input("Chef Bill: You done? [yes/no]")
		if done=="yes":
			if "theGoldenSpoon" in inv:
				inv.remove("theGoldenSpoon")
				global gold
				gold+=500
				print "Chef Bill: Great! Here's some money"
				print "Reward of 100xp"
				global exp
				global level
				exp+=100
				if exp>=100:
					level=level+1
					exp=exp%100
					print "Level up! \n Now: " + str(level) +"."

visit_tavern("Chef's Helper",["anApple","aDustyMap","someFalseTeeth","theGoldenSpoon","someString"])
 
This doesn't use a class, and is probably poor in a number of ways. I don't know python. For the specific question you had, the "in" keyword is what you're looking for.

Code:
exp = 0
gold = 0
level = 1

def visit_tavern(current_quest,inv):
	if current_quest=="Chef's Helper":
		done=raw_input("Chef Bill: You done? [yes/no]")
		if done=="yes":
			if "theGoldenSpoon" in inv:
				inv.remove("theGoldenSpoon")
				global gold
				gold+=500
				print "Chef Bill: Great! Here's some money"
				print "Reward of 100xp"
				global exp
				global level
				exp+=100
				if exp>=100:
					level=level+1
					exp=exp%100
					print "Level up! \n Now: " + str(level) +"."

visit_tavern("Chef's Helper",["anApple","aDustyMap","someFalseTeeth","theGoldenSpoon","someString"])

ok, thank you.

besides it CAN have a class. why should i not have one? i use them organize things.. like class menu contains: menu,exit ,start
 
I didn't say not to use classes, i meant to indicate that i was pulling the code out and not using a class because i didn't know how. On the contrary, you should definitely use OOP and organize your code in classes, i just don't know python so to get a working example i decided to forego it in this case.

-Lee
 
I didn't say not to use classes, i meant to indicate that i was pulling the code out and not using a class because i didn't know how. On the contrary, you should definitely use OOP and organize your code in classes, i just don't know python so to get a working example i decided to forego it in this case.

-Lee
my bad, i thought you were calling me out on my use of classes. you were right.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.