[Python Help] CYTechChooser.py

MrUnderhill

Civ-loving Hobbit
Joined
Dec 6, 2005
Messages
655
I've finally gotten down to modding Civ4 in Python and I've already run into a bug. I've gotten it so that "and" prereqs get arrows drawn for them instead of "or" prereqs, but to make it more compatible with the existing tech tree (and other mods), I want to make it so that if a tech has only 1 "or" prereq, it gets treated like an "and" and gets an arrow drawn for it. But this doesn't work.
Code:
maxPrereqs=gc.getDefineINT("NUM_OR_TECH_PREREQS")

for j in range(maxPrereqs):

        eTech = gc.getTechInfo(i).getPrereqOrTechs(j)

        if ( eTech > -1 ):
                if (maxPrereqs = 1):
                        fX = fX - X_INCREMENT

                        iX = 30 + ( (gc.getTechInfo(i).getGridX() - 1) * ( ( BOX_INCREMENT_X_SPACING + BOX_INCREMENT_WIDTH ) * PIXEL_INCREMENT ) )
                        iY = ( gc.getTechInfo(i).getGridY() - 1 ) * ( BOX_INCREMENT_Y_SPACING * PIXEL_INCREMENT ) + 5

                        szTechPrereqID = "TechPrereqID" + str((i * 1000) + j)
                        screen.addDDSGFCAt( szTechPrereqID, "TechList", gc.getTechInfo(eTech).getButton(), iX + fX, iY + 6, TEXTURE_SIZE, TEXTURE_SIZE, WidgetTypes.WIDGET_HELP_TECH_PREPREQ, eTech, -1, False )

                        #szTechPrereqBorderID = "TechPrereqBorderID" + str((i * 1000) + j)
                        #screen.addDDSGFCAt( szTechPrereqBorderID, "TechList", ArtFileMgr.getInterfaceArtInfo("TECH_TREE_BUTTON_BORDER").getPath(), iX + fX + 4, iY + 22, 32, 32, WidgetTypes.WIDGET_HELP_TECH_PREPREQ, eTech, -1, False )

j = 0

The above code crashes the event manager. When I change the "=" in "if (maxPrereqs = 1)" to a ">", it doesn't crash but still draws all prereqs as icons, rather than drawing them only if there are 2 or more.
I have tried to work my way around it several times, but none of them worked entirely, so I came here for help.
 
Firstly, it should be:
Code:
if (maxPrereqs == 1):
If you had error debugging on it should have told you this.

Secondly, I can't tell much from the snippet you've posted. It would seem to be saying that if the tech has one "or" prequesite then it will draw an icon in the corner for it, otherwise it won't do anything. Am I right?
 
Ah, that might do it. I'm used to Basic where you only need the one "=".
Actually that snippet is just a test script for the equals sign problem. I was planning on putting an "else" on the end of it so it would draw an arrow for 1 prereq and the normal icons when there are more.

Thanks, I'll give it a shot!
 
Okay, it's not crashing event manager anymore, but I can't seem to get the number of prereqs per tech right.

I think "gc.getDefineINT("NUM_OR_TECH_PREREQS")" gets the number of prereqs in the tech tree, not for the actual tech, which explains why it's printing either all arrows or all icons.

Is there a way to get the number of "or" prereqs for an individual tech?
 
That's still not going to work. You've gotten the maximum allowed number of or prereqs. What you need is the number of prereqs for this tech. I don't know offhand where to get that, but you can trying walking your iNumMaxPrereqs range called techinfo's getPrereqOrTechs(INT i) and seeing with the resultant tech is -1 or isNone(), depending on that that returns (I don't recall).
 
Top Bottom