Trouble finishing mod

RenaissanceFan

Warlord
Joined
Mar 15, 2011
Messages
125
Hello again. I got the backbone for one of my mods almost done, but I'm having trouble to make it work. Please tell me what am I doing wrong. Two things:

1) I created a button at the Domestic Advisor for calling a popup, but the handleInput function doesn't seem to be working:

- Button declaration:
Code:
screen.setImageButton( "CreateProvince", "", self.nScreenWidth - 165, self.nScreenHeight - 45, 28, 28, WidgetTypes.WIDGET_ACTION, -1, -1 )
screen.setStyle( "CreateProvince", "Button_HUDLog_Style" )

- handleInput part of code:
Code:
if (inputClass.getFunctionName() == "CreateProvince"):
if (inputClass.getNotifyCode() == NotifyCode.NOTIFY_CLICKED):
pPlayer = gc.getActivePlayer()

CityChoice = CyPopupInfo()

CityChoice.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON)
CityChoice.setText("Choose your new province's capital:")
CityChoice.setOnClickedPythonCallback("makeProvince")
(pLoopCity, iter) = pPlayer.firstCity(false)
while(pLoopCity):
if (pLoopCity.isCapital() != True):
CityChoice.addPythonButton(pLoopCity.getName())
i += 1
(pLoopCity, iter) = player.nextCity(iter, false)
CityChoice.addPopup(pPlayer)

2) Here's the function that the popup calls. Also, where should I place it?
Code:
def makeProvince (self, argsList):
ButtonID = argsList[0]
pPlayer = gc.getActivePlayer()
tPlayer = gc.getActivePlayer().getTeam()

for i in range(0, gc.getMAX_CIV_PLAYERS()) :
if( not gc.getPlayer(i).isEverAlive() and not gc.getPlayer(i).isAlive() ) :
newPlayerId = i
break
game.addPlayer(i, gc.getInfoTypeForString("LEADER_GOVERNOR", gc.getInfoTypeForString("CIVILIZATION_PROVINCE"))
iVassal = gc.getPlayer(i)
tVassal = gc.getPlayer(iVassal).getTeam()

gc.getPlayer(iVassal).acquireCity(pPlayer.getCity(ButtonID+1), False, True)
for iTech in range(gc.getNumTechInfos()):
if (tPlayer.isHasTech(iTech)):
iVassal.setHasTech(iTech, True, iVassal, False, False)
pPlayer.assignVassal(gc.getPlayer(iVassal).getTeam(), True)
 
If you repost your stuff with
Code:
 tags someone knowleadgeable would actully be able to help you.
 
Baldyr,
Is it true from your experience, that civ iv is selectly compliant with working with lists and dictionaries, at the core python dll level within the game.

I tried this out on the command line python 2.7, but i'll be dammed if it will work in the game.

>>> test = [[45, 56, 19], [23, 12, 11]]
>>> test.remove(test[0])
>>> test
>>> [23, 12, 11]

Now in my game code:

def somefunction(self, args):
test = args
test.remove(test[0])
gc.addImmediateMessage(str(test), "")
return true

I throughly isolated the issue down to the second lines of the somefunction method.
I tried pop test.pop(0), also nothing works.
What is even more madding, is in one class method I wrote,
this code snipet works

del args["aKey"] #where args is a {dictionary}
test = args.keys()

yet in another part of my.py
It does not, and it is using the same dictionary passed as a method argument
It is not my first time, out dancing with Oops.
What gives, does your experience with civ iv, tell ya thatCiv iv's complience, with python is not truely to spec when it comes to list and dictionaries within the core python api.

A futher note would be, what version of python does civ iv implement that has been shown to be 100% true to a given version's api.
Thanks in advance.

NusRa
 
Civ4 uses Python 2.4 (which was the newest version when the game was originally published).

When you say it doesn't work - what does it do? How can you tell if it works? What parameters are being sent to somefunction and what does it do as a result?
 
Baldyr,
Is it true from your experience, that civ iv is selectly compliant with working with lists and dictionaries, at the core python dll level within the game.
I never experienced any of the problems you mention working with Python within the framework of CivIV modding. Dictionaries, lists, tuples and other arrays work just like they I'd expect them to. Works for me. :dunno:

Have you enabled Python exceptions? Because one of those would inevitably make your code fail.
 
If figured it out late last night, actually after a power nap and a jolt of sugar to shock the system.
The issue was purely my synesis understanding of python. The code was logically sound, however the nuts and bolts was the memory address pointer to the variable in question, became corrupted in the for loop condition within the method, when I changed the keys length, qed the len(keys)

In java that would not have happened, but in python once the key length no longer matched the runtime length in the loop it crashed. a simple return true/false at the right spot solved the issue.

I will be happy to share the .py with you once I get the ai to use it.
And, am happy with how the game mantains balance within CvCity, my thinking, is gross over use should have negative reprecussion in city health leading to Pericles type events, ie. plagues.

So far it it shaping up to be lovely example of programming elegance.
My goal is to make the game more vicious when it comes to bonus reasources.
In my humble opion, the underlying snesthesia to why man's first started throwing stones at each each other.

The .py has to do with two techs i've xml'ed into a scenario, the techs are cultivate and domesticate.

Thanks for reply.
Mark
 
Back
Top Bottom