How RF2 Uses Existing Python Abilities

Discuss the development of Reality Factory 2
Post Reply
User avatar
AndyCR
Posts: 1449
Joined: Wed Jul 06, 2005 5:08 pm
Location: Colorado, USA
Contact:

How RF2 Uses Existing Python Abilities

Post by AndyCR » Sat Jul 08, 2006 6:01 pm

In making RF2 we have been very careful to still 'play by the rules' of Python itself. RF2 throws standard Python exceptions, such as IOError when an image cannot be found, with the filename of the image.

In addition, RF2 utilizes some important features of Python. One of which is the List.

Here is how the buttons are loaded onto the main page:

Code: Select all

self.buttonnames = ['newgame', 'loadgame', 'savegame', 'multiplayer', 'options', 'credits', 'quitmain']
self.buttons = []

for button in self.buttonnames:
	try:
	self.buttons.append(menuelementbutton.loadbutton(self.menuini, self.bitmapdirectory, self.designoffset, button))
	except:
		pass
Here it is, again, line by line with comments.

Code: Select all

self.buttonnames = ['newgame', 'loadgame', 'savegame', 'multiplayer', 'options', 'credits', 'quitmain'] # Make a list of all the fields containing buttons for the main page - can be used later to get named buttons - search the list for neagame, and you know it's index is the index of the button itself in the buttons list, etc.
self.buttons = [] # Make an empty list to hold all buttons on this page
		
for button in self.buttonnames: # Go through all the names of the buttons
	try: #Try to:
		self.buttons.append(menuelementbutton.loadbutton(self.menuini, self.bitmapdirectory, self.designoffset, button)) # Load the button in question from menu.ini, and add it to the list
	except: # If the button could not be found
		pass # Do nothing - no error if a button is missing
Sorry, the code tags messed up the indentation, but the idea's the same.

User avatar
steven8
Posts: 1487
Joined: Wed Aug 24, 2005 9:08 am
Location: Barberton, OH

Post by steven8 » Tue Jul 11, 2006 5:11 am

Cool. ImageLists. Very neat and tidy. :D
Steve Dilworth - Resisting change since 1965!

Post Reply