• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
KuraiTsubasa

[Solved]How to make variable for item[Adventure Text Game]

4 posts in this topic

Hi everyone biggrin.png i tried to make item in adventure text based game but it seems not working i make the variable for key so when the variable go to number 1 it would open the door but when i tried it.It show me an error : Name:Global name key_work_room is not defined

 

here my script(fixed for global variable):

from sys import exit

global key_work_room

key_work_room = 0

def work_room():
	global key_work_room
	if key_work_room == 1:
		print "There is a book."
		print"""Choices:
		1.Read
		2.Leave
		"""
		
		next = raw_input(">")
		
		if next == "1":
			print """
			Go to the Dark corridor and there is a door that
			keep a magic sword.It can used to kill demon 
			in that door there is a key
			541
			"""
		elif next== "2":
			stair()
		else:
			print "Check your spelling."
			print " "
			work_room()
	else:
			print "Check your spelling."
			print " "	
			work_room()
def bed_room():
	print "there is a key in the desk."
	print """choices:
	1.Take.
	2.leave.
	"""
	
	next = raw_input("> ")

	if next == "1":
		global key_work_room
		key_work_room += 1
		stair()
	
	elif next == "2":
		stair()
	else:
		print "Check your spelling."
		print " "
		bed_room()

def second_floor():
	print "There is so many torch in this room but there is a dark side."
	print """Choices:
	1.Take the torch.
	2.Go to the dark side.
	3.back
	"""
	
	next = raw_input("> ")
	
	if next == "1":
		print "You get the torch"
		torch = 1
		second_floor()
	elif next == "2":
		print "Something lurking in the dark attack you..."
	elif next == "3":
		stair()
	else:
		print "Check your spelling."
		print " "
		second_floor()

def stair():
	print key_work_room
	print "Now you're in the 2nd floor."
	print "There are 4 room."
	print "which one do you choose? or Do you want take a look around?"
	print "1. to look door 1."
	print "2. to look door 2."
	print "3. to look door 3."
	print "4. to look door 4."
	print "5. to look around."
	
	next = raw_input("> ")
	
	if next == "1":
		king_throne()
	elif next == "2":
		bed_room()
	elif next == "3":
		veranda()
	elif next == "4":
		work_room()
	elif next == "5":
		second_floor()
	elif next == "exit":
		exit(0)
	else:
		print "Check your spelling."
		print " "
		stair()
		
def living_room():
	print "you find yourself in living room."
	print "You don't remember anything it looks like something hit your head."
	print "You now fully regain your consciousness."
	print "You start to walking and you found a stair and dark corridor."
	
	next = raw_input("> ")
	
	if next == "stair":
		stair()
	elif next == "dark corridor":
		dark_corridor
	elif next == "exit":
		exit(0)
	else:
		print "Check your spelling."
		print " "
		living_room()

def start():
	print "Welcome in Fantasy World."
	print "This is simple game type 'exit' to exit."
	print "choose your destination by type the destination name."
	print "Are you boy or girl?"
	character = raw_input("> ")
	
	if character == "boy" in character or "girl" in character:
		living_room()
	elif character == "exit":
		exit(0)
	else:
		print "Check your spelling."
		print " "
		start()

def dead():
	print "you died and the mystery still uncovered."
	print """Choices:
	1.Play again
	2.Take a rest.
	"""
	choice = raw_input("> ")
	
	if choice == "1":
		start()
	elif choice == "2":
		exit(0)
	else:
		print "Check your spelling."
		print " "
		dead()

start()

it haven't finished yet but i need key to know how make the variable for item work also if you find anything weird in my script please tell mesmile.png .Thank youbiggrin.png

Edited by Kurai Tsubasa
0

Share this post


Link to post
Share on other sites

Your problem is that variables are local to the function by default. So other functions cannot see the variable. To fix this, add a line to make the variable global in the first line in the function.

global key_work_room
1

Share this post


Link to post
Share on other sites

I think a good place to go from here would be to revise your code so that you store the rooms and descriptions in a configuration file (Such as JSON or XML).

 

You could store what items you have using a python dictionary.

 

Doing these things will allow you to expand to your game without having to increase the size of your code.

1

Share this post


Link to post
Share on other sites

 

Your problem is that variables are local to the function by default. So other functions cannot see the variable. To fix this, add a line to make the variable global in the first line in the function.



global key_work_room

Thank you now it works

0

Share this post


Link to post
Share on other sites

I think a good place to go from here would be to revise your code so that you store the rooms and descriptions in a configuration file (Such as JSON or XML).

 

You could store what items you have using a python dictionary.

 

Doing these things will allow you to expand to your game without having to increase the size of your code.

Thank you i t really helping mesmile.png 

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0