[NOOB Python] Why won't they attack damn it!

Feeder74

Chieftain
Joined
Oct 31, 2007
Messages
57
I am trying to make a total war situation at 50 turns of play, where everybody is forced to suddenly be at war with one another.
I have written this into the CvEventManager.py
Code:
	def onBeginPlayerTurn(self, argsList):
		'Called at the beginning of a players turn'
		iGameTurn, iPlayer = argsList
		if (iGameTurn==50):
			team=gc.getTeam(gc.getPlayer(iPlayer).getTeam())
			if (team.isAlive()):
				for i in range(gc.getMAX_PLAYERS()):
					team2=gc.getTeam(gc.getPlayer(i).getTeam())
					if (i!=iPlayer and team2.isAlive()):
					team.declareWar(team2,false);
It doesn't work, could someone with a bit of python exp tell me what I am doing wrong here?
 
Code:
					if (i!=iPlayer and team2.isAlive()):
					team.declareWar(team2,false);

There is no tabulation with this test , team2 must be an integer in declareWar , the ";" is a synthax error i think ... you're code doesn't prevent 2 players of the same team to declare war each other (don't know what happen in this case ) . You should enable the debugger to check python error .

Tcho !
 
Well I changed it to this...
Code:
		if (iGameTurn==50):
			team=gc.getTeam(gc.getPlayer(iPlayer).getTeam())
			if (team.isAlive()):
				for i in range(gc.getMAX_PLAYERS()):
					team2=gc.getTeam(gc.getPlayer(i).getTeam())
					if (i!=iPlayer and team2.isAlive()):
						team.declareWar(i,false)
and it still isn't working for me, but thanks sto, on the note of poor indenting and syntax, is there a good IDE somewhere for this stuff, I am just using notepad at the moment.
I have Code::Blocks already installed as of last night, but since I can't get the SDK to compile, I am wondering now if it can be configured to do python, anyhow will have a look straight after this ;)
I have the debugger enabled - just can't follow the error message it spit out last time - I will have a look again in a few minutes to find out what it says this time :)

Well I had a good look through the error messages, looks 1,688KB of this message to me...
Code:
Traceback (most recent call last):

  File "CvEventInterface", line 23, in onEvent

  File "CvEventManager", line 164, in handleEvent

  File "CvEventManager", line 464, in onUnitMove

ValueError: too many values to unpack
ERR: Python function onEvent failed, module CvEventInterface
...anyhow this means diddly to me, as it isn't even refering to the edits I made :(
 
Here the python tutorial where you can find python an how to debug ( if not just search python with google ) . This is a strange bug , you have made no change in onUnitMove ? and what is the line where you get an error ? . Notepad is not a good editor because it can cause some tab problems ( a mix of spaces and tab ) . Anyway , the code will not work in a game with a team . You should make a loop with teams and not players (perhaps place this function in onBeginGameTurn ) . You should check if the team canDeclareWar also .

If you have some problems , do not hesitate to post your file with all the changes you've made in it , the version you play .

Tcho !
 
thanks for the link to the tut - I hadn't seen that one - and it is very helpfull for where I am at ;)
As for the 1,688KB of error messages I mentioned above - I think this may hve been caused by using Vanilla file instead of BTS3.13

Anyhow after some mucking around I ended up with this...
Code:
	def onBeginGameTurn(self, argsList):
		'Called at the beginning of the end of each turn'
		iGameTurn = argsList[0]
		CvTopCivs.CvTopCivs().turnChecker(iGameTurn)
		#***Start of edit!***
		if (iGameTurn==50):
			for iPlayerLoop in range(gc.getMAX_PLAYERS()):
				pPlayer=gc.getPlayer(iPlayerLoop)
				for iPlayerLoop2 in range(gc.getMAX_PLAYERS()):
					pPlayer2=gc.getPlayer(iPlayerLoop2)
					if (pPlayer.getTeam()!=pPlayer2.getTeam()):
						gc.getTeam(iPlayerLoop).declareWar(gc.getPlayer(iPlayerLoop2).getTeam(),false,0)
it does what was intended, and I'd just like to say thanks heaps for getting me started with this - I sometimes find it hard to come to a new API and get the layout of it the first few time, hopefully next time, I might have something a bit more elaborate for you to wrap your minds around ;)
PS: If you see anyways of optimizing that last line of code - I'd love to hear it - to me it seems - well ugly, and that isn't good, and prolly isn't bad either since it does do what it was meant too, but I like my stuff to look nice too ;)
 
Top Bottom