Python help please

derwin

Chieftain
Joined
Aug 2, 2006
Messages
3
Code:
CustomEventManager.py:
resc = Resource.Resource()
...
	def onEndGameTurn(self, argsList):
		'Called at the end of the end of each turn'
		self.parent.onEndGameTurn(self, argsList);
		resc.use()
...
Code:
Resource.py:
...
class Resource:
...
	def use():
		resStr=['Aluminum','Coal','Copper','Horse','Iron','Marble','Oil','Stone','Uranium']
		for iplayer in range (cg.countCivPlayersEverAlive()):
			CyInterface().addMessage(iplayer, 1, 100, 'Beginning your resource calculations', '', 0, '', CyGame().getReplayMessageColor(0), 0, 0, 0, 0)
.....
This code produces an error: "The function use() requires no arugments, (1 given)
I have checked the traceback to make sure that the custome events line is the only place that calls this code.
I am a novice when it comes to python, so I am wondering if this is some simple mistake I am overlooking that would cause it to think I am passing an argument to the use function, or is there something else you can spot?
Thanks a lot,
Derwin
 
derwin said:
Code:
CustomEventManager.py:
resc = Resource.Resource()
...
	def onEndGameTurn(self, argsList):
		'Called at the end of the end of each turn'
		self.parent.onEndGameTurn(self, argsList);
		resc.use()
...
Code:
Resource.py:
...
class Resource:
...
	def use():
		resStr=['Aluminum','Coal','Copper','Horse','Iron','Marble','Oil','Stone','Uranium']
		for iplayer in range (cg.countCivPlayersEverAlive()):
			CyInterface().addMessage(iplayer, 1, 100, 'Beginning your resource calculations', '', 0, '', CyGame().getReplayMessageColor(0), 0, 0, 0, 0)
.....
This code produces an error: "The function use() requires no arugments, (1 given)
I have checked the traceback to make sure that the custome events line is the only place that calls this code.
I am a novice when it comes to python, so I am wondering if this is some simple mistake I am overlooking that would cause it to think I am passing an argument to the use function, or is there something else you can spot?
Thanks a lot,
Derwin

Member functions in python need to have "self" as the first argument. In other words, if your function is part of a class, you need to use the "self" argument as the first argument. The "def use()" line should be "def use(self)".
 
Back
Top Bottom