HELP! SorenRand giving me too many calls!

sab89

Chieftain
Joined
Mar 6, 2008
Messages
25
At the start of a turn, if it's player 0 and they win a 50% rand roll, I want to trigger something. Currently, if they win, it triggers it 5+ times!?

Code:
	def onBeginPlayerTurn(self, argsList):
		'Called at the beginning of a players turn'
		iGameTurn, iPlayer = argsList
		py = PyPlayer(iPlayer)
		pPlayer = gc.getPlayer(iPlayer)
		unitList = py.getUnitList()



		for iPlayerLoop in range(4):  #loop through all the players
			
			pPlayer = gc.getPlayer(iPlayerLoop)
			pyPlayer = PyPlayer(iPlayerLoop)
			
			if (iPlayerLoop == 0): #if it's player 0, do this...if not, move on...right?

				chance = CyGame().getSorenRandNum(100, "")
				if chance >= 50: #if the roll is above 50, print the message below....ONCE!
					self.addPopup('this message appears more than once')
:crazyeye:
 
That happens because that function runs for every player's turn. Instead of looping through all of the players just check to see if the current player is player 0 and leave the loop out of there.

Code:
	def onBeginPlayerTurn(self, argsList):
		'Called at the beginning of a players turn'
		iGameTurn, iPlayer = argsList
		py = PyPlayer(iPlayer)
		pPlayer = gc.getPlayer(iPlayer)
		unitList = py.getUnitList()

		if (iPlayer == 0): #if it's player 0, do this...if not, move on...right?
			chance = CyGame().getSorenRandNum(100, "")
			if chance >= 50:
				self.addPopup('this message appears more than once')
 
Seven05 is right, you're making the same mistake that you've made here:

I changed it to:
Code:
		if gc.getActivePlayer().getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_J'):

This works, but displays 5 messages, instead of just one. :crazyeye:
 
Back
Top Bottom