Getting the ai to not build a unit

I mean what you post here, you need to put in code tags, so that we can read it. Not in the actual python file (if you put code tags in the actual python source, it'll just break things, python wol't know what the hell it means).

Edit: In general code you post in the forum is just more readible when in code tags. But especially for python code, you absolutely must use them, because your issue very well could be one of whitespace, which without code tags, we would never see.
 
Oops, sorry:
Code:
                    iRobo-Warriors = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_ROBO_WARRIORS')
            iRobo-Armor = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_ARMOR')
            iRobo-Battleloid = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_BATTLELOID')

        if (eUnit == iRobo-Warriors or eUnit == iArmor or eUnit == iBattleloid):
            return True

So, I guess that 1st line is out of whack?
 
OK, I tried copying the exact same lines excluding Starbases to not let barbs build planetary defense units, but I'm still losing the interface... Do I need a special editor for Python or what?:confused:
 
All your whitespace is out of wack. You have your variable initializations indented off of the check that follows. Python uses indentation to nest functions (C++ uses {}), so you're telling Python the variable initializations are done inside some other function (I can't see because it's above or outside the code you're showing), and so since the function exists outside them, they will no longer exist by the time you're doing your function check. Also your variables aren't consistent, you define iRobo-Armor as UNIT_ARMOR, then below in your function you reference iArmor which has never been initialized and so doesn't exist (well none of your variables exist to the function, because they are nested outside of it due to your indentation, but assuming you lined it up properly, it'd still be messed up, because you're not refrencing your variables correctly). One last thing it's impossible to see what your function does as you're just showing us your little snippet. Which all we can see is saying:

Initialize this variable as this string
Initialize this variable as this string
Initialize this variable as this string

if we are looking at any of these variables, apply the base function.

Thing is none of us have any idea what function is returning true. We'd need to see the relevant code this function is nested in to really know if it's working right. Anyway fix the indentation, and your variable calls, and then re post the entire relevant code and we can look at it.
 
:blush: Can't believe I missed this:

iRobo-Armor = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_ARMOR')
iRobo-Battleloid = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_BATTLELOID')


OK, will check and let you know what.
 
OK, I now have this:

Code:
    def canTrain(self,argsList):
        pCity = argsList[0]
        eUnit = argsList[1]
        bContinue = argsList[2]
        bTestVisible = argsList[3]
        return False

    def cannotTrain(self,argsList):
        pCity = argsList[0]
        eUnit = argsList[1]
        bContinue = argsList[2]
        bTestVisible = argsList[3]
        
        # Block out the rest
        return False
        
        iStarbaseI = CvUtil.findInfoTypeNum(gc.getUnitInfo, gc.getNumUnitInfos(), "UNIT_STARBASE_I")
        iStarbaseII = CvUtil.findInfoTypeNum(gc.getUnitInfo, gc.getNumUnitInfos(), "UNIT_STARBASE_II")
        iStarbaseIII = CvUtil.findInfoTypeNum(gc.getUnitInfo, gc.getNumUnitInfos(), "UNIT_STARBASE_III")
        
        if (eUnit == iStarbaseI or eUnit == iStarbaseII or eUnit == iStarbaseIII):

        return True

        iRobo-Warriors = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_ROBO_WARRIORS')
        iArmor = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_ARMOR')
        iBattleloid = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_BATTLELOID')

        if (eUnit == iRobo-Warriors or eUnit == iArmor or eUnit == iBattleloid):

        return True

        return False

    def canConstruct(self,argsList):
        pCity = argsList[0]
        eBuilding = argsList[1]
        bContinue = argsList[2]
        bTestVisible = argsList[3]
        bIgnoreCost = argsList[4]
        
        return False
And this is what I put in:

Code:
        iRobo-Warriors = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_ROBO_WARRIORS')
        iArmor = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_ARMOR')
        iBattleloid = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_BATTLELOID')

        if (eUnit == iRobo-Warriors or eUnit == iArmor or eUnit == iBattleloid):

        return True
I copied the Starbase section, replacing the Robo-Warriors/Armor/Battleloid names for the Stabrase names. (I was wondering if the problem was with the Return true and/or Return false lines; the section I put in should have the same indent as the Starbase section, as I merely copied it.)
 
You still have whitespace issues :crazyeye:
Edit: also I think the hyphen isn't a valid character for defining a variable. Use iRoboWarrior instead.

try this:
Code:
    def cannotTrain(self,argsList):
        pCity = argsList[0]
        eUnit = argsList[1]
        bContinue = argsList[2]
        bTestVisible = argsList[3]
        
        # Block out the rest
        return False
        
        iStarbaseI = CvUtil.findInfoTypeNum(gc.getUnitInfo, gc.getNumUnitInfos(), "UNIT_STARBASE_I")
        iStarbaseII = CvUtil.findInfoTypeNum(gc.getUnitInfo, gc.getNumUnitInfos(), "UNIT_STARBASE_II")
        iStarbaseIII = CvUtil.findInfoTypeNum(gc.getUnitInfo, gc.getNumUnitInfos(), "UNIT_STARBASE_III")
        
        if (eUnit == iStarbaseI or eUnit == iStarbaseII or eUnit == iStarbaseIII):
                return True

        iRoboWarrior = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_ROBO_WARRIORS')
        iArmor = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_ARMOR')
        iBattleloid = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_BATTLELOID')

        if (eUnit == iRoboWarrior or eUnit == iArmor or eUnit == iBattleloid):
                return True
 
You should really activate the python exceptions (search in the Civ4Config.ini for it), they show most times really clear, where's the problem.


Why no interface:
In general, there are several functions called from CvMainInterface.py, and if one of these functions horribly fails, the CvMainInterface.py totally crashes.
 
Sounds helpful. But how can I open the ini. file? (I tried via Notepad, but that's no good.)

I tried adding the # after the 1st return false, but still have no interface.
 
You are using the code that is in my post above and it still gives no interface?

Turn on Python exceptions, you can use notepad.
 
I used the Coded section from your post + deanej's # after 1st return false parameter, getting the same loss of interface. Trying to open the ini. file w/Notepad gives me a message saying where to look for it...:crazyeye: Is there another way to open the ini. file maybe?
 
OK, I'll be more specific then, and show the outside functions as well like you did in your post.

Code:
    def canTrain(self,argsList):
        pCity = argsList[0]
        eUnit = argsList[1]
        bContinue = argsList[2]
        bTestVisible = argsList[3]
        return False

    def cannotTrain(self,argsList):
        pCity = argsList[0]
        eUnit = argsList[1]
        bContinue = argsList[2]
        bTestVisible = argsList[3]
        
        # Block out the rest
        return False

        iRoboWarrior = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_ROBO_WARRIORS')
        iArmor = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_ARMOR')
        iBattleloid = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_BATTLELOID')

        if (eUnit == iRoboWarrior or eUnit == iArmor or eUnit == iBattleloid):
            return True

    def canConstruct(self,argsList):
        pCity = argsList[0]
        eBuilding = argsList[1]
        bContinue = argsList[2]
        bTestVisible = argsList[3]
        bIgnoreCost = argsList[4]
        
        return False

Removed the Starbase this time because it's handled in the XML I guess.

But yes, you should turn on python exceptions if you're messing with it. Download and install Notepad++ Use that to open your main ini file. It's the Civilization4 ini file found in the main BtS folder that you need to edit.
 
Trying to open the ini. file w/Notepad gives me a message saying where to look for it...:crazyeye: Is there another way to open the ini. file maybe?

You can open it with every program, which can edit textfiles.
Notepad, Wordpad, Word, the OpenOffice-Word-Clone, or download Notepad++.
 
What are you opening your python source with? Regular notepad wol't work for that you know. You need to be using notepad++ or some such codewriting utility.
 
Getting conflicting signals here...:crazyeye:

Haven't tried C++ yet, as I was out and just now started up my home PC.

I suspect he may be opening the shortcut to it instead of the file itself.

The Civ4 ini. file has a shortcut? I went for what's listed in the Civ4 directory.
 
Top Bottom