Page 1 of 1

How RF2 Uses Existing Python Abilities

Posted: Sat Jul 08, 2006 6:01 pm
by AndyCR
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.

Posted: Tue Jul 11, 2006 5:11 am
by steven8
Cool. ImageLists. Very neat and tidy. :D