Requesting following features

maybe you should return to that chapter! (the return goes back to the code where the function was called and continues)
 
right an exception has occured

Traceback (most recent call last):

File "CvEventInterface", line 23, in onEvent

File "CvEventManager", line 188, in handleEvent

File "CvEventManager", line 383, in onBeginGameTurn

File "CatapultConstruction", line 195, in process

File "CatapultConstruction", line 108, in constructionTimer

File "CatapultConstruction", line 148, in enableUnitAI

File "CatapultConstruction", line 152, in setUnitAI

RuntimeError: unidentifiable C++ exception
ERR: Python function onEvent failed, module CvEventInterface

Code:
        def setUnitAI(self, eUnitAI):
                self.getUnit().setUnitAIType(eUnitAI)
 
I am having a problem with an event:

Traceback (most recent call last):
File "CvEventInterface", line 23, in onEvent
File "CvEventManager", line 188, in handleEvent
File "CvEventManager", line 393, in onBeginGameTurn
File "ModEvents", line 153, in eventReinforce
File "Helpers", line 69, in flipCity
RuntimeError
:
unidentifiable C++ exception

The code:
Code:
##ERE Reinforce##
iNumCities = 4
iReinforceDate = "395:4"
tERETop = (55, 30)
tEREBottom = (40, 23)
reinforceMessage = "TXT_KEY_MODEVENTS_REINFORCE_MESSAGE"
pByzantium = instance(eByzantium)
iEREUnits = 3
def eventReinforce():
    if getNumPlayerCities(eByzantium) < iNumCities and isDate(iReinforceDate) and pByzantium.isAlive():
        print "Reiforce triggered!"
        for pCity in [b]findAreaCities(tEREBottom, tERETop)[/b]:
            if not pCity.isCapital():
                [b]flipCity(eByzantium, pCity)[/b]
                spawnCityGarrison(pByzantium, pCity, iEREUnits)
                addMessage(reinforceMessage, (), eWhite) #Blue/Cyan?
Code:
def findAreaCities(tCoords1, tCoords2):
        """
        Used for looping. When supplied with the map coordinates of a area defined by its
        lower left corner (tCoords1) and its upper right corner (tCoords2), the function
        yields all cities (CyCity instances) in order.
        """
        iX1, iY1 = tCoords1
        iX2, iY2 = tCoords2
        for iX in range(iX1, iX2 + 1):
                for iY in range(iY1, iY2 + 1):
                        pPlot = Map.plot(iX, iY)
                        #pPlot = getPlot((iX, iY))
                        if pPlot.isCity():
                                yield pPlot.getPlotCity()
                                #yield getPlotCity((iX, iY))
Code:
def flipCity(ePlayer, pCity, bConquored = False, bTrade = False):
        instance(ePlayer).get(CyPlayer).acquireCity(pCity, bConquored, bTrade)

and I making some kind of stupid mistake with mixing up class instances and things?

on a side note I have some code which uses the flipCity function correctly:

flipCity(eRome, getPlotCity(tByzantium))

where tByzantium = (46, 27)

and getPlotCity()
Code:
def getPlotCity(tCoords):
       return getPlot(tCoords).getPlotCity()
with getPlot being:
Code:
def getPlot(tCoords): 
        """ 
        Returns the CyPlot instance of the plot at tCoords. 
        """ 
        iX, iY = tCoords 
        return Map.plot(iX, iY)
and Map = CyMap()
 
Both of these recent exceptions are of the "unidentifiable C++ error" variety, and this is the bad kind. Because the error occurs on the SDK side of things - and this is why the Python exception is lacking in any real... substance. Most of the time the error occurs due to invalid parameters/arguments that are passed on to the C++ version of the method/function.

The thing you could do, however, is to add debug lines (print commands) that reveal what values are being used at key junctures. Other than that you could look up the corresponding method in the SDK - and try to fathom what isn't computing. The solution to these issues, and others like them, might well be to use a "debug DLL" and thus get to see the actual C++ error message. But I wouldn't know anything about any of that... :p
 
thanks! I will have to try that debug dll at some point!
 
For nitram:

Spoiler :




To baldyr:

I am thinking of remodelling the Catapult construction code btw as it is causing new problems with setting unit ai... when this error appears a catapult is spawned right next to one of my cities everyturn... Unidentifiable C++ error though so when I get the debug going I might try and fix it all up...
 

Attachments

  • i.jpg
    i.jpg
    146.5 KB · Views: 160
three files

1) 5TenseVerbDictionary.py
Spoiler :

Code:
#See below
#To User: Press f5 to run
# -*- coding: cp1252 -*-
#Add these to xml with [reflexive] verbs
import xml.dom.minidom as mini
from Graphics import *
document = 'FrenchData.xml'
message = "Welcome to the five tense french verb dictionary!\nAll input is to be entered in LOWERCASE\n\
There can be two types of verbs in this dictionary, 'reflexive' and 'normal', because of this, when you find a reflexive pronoun infront of a verb include it\
. For example j'appelle and je m'appelle are two different things. so when using option 4, entering in appelle will tell you je form of present tense of appeler\
, however m'appelle will tell you the je form of the present tense of appeler [reflexive]. typing in appeler into option 3 will tell you BOTH to call and to be called\
. Entering in to be called into option 2 will give you appeler [reflexive]. Note that reflexive infintives start with se or s' but they are not written with these within the program!\n"
xml = mini.parse(open(document))
graphical = True
class Dict:

    ##API##
    #Dict(xml).removeBrackets() - removes brackets during infinitive convertion
    #Dict(xml).getEnglishInfinitiveAsFrench() - Gets the french meaning of an english infinitive
    #Dict(xml).getFrenchInfinitiveAsEnglish() - Gets the english meaning of a french infinitive
    #Dict(xml).getEnglishForPart() - when supplied with any french verb part gets the english meaning
    #Dict(xml).getPartForVerb() - when supplied with a verb, tense and part, it will supply the part of the verb
    #Dict(xml).getListVerbs() - lists all verbs defined within the xml
    #Dict(xml).getAccents() - converts xml standard accents into unicode strings
    #Dict(xml).fixAccents() - fixes the input accents into readable ones for use within the code

    ##Nodes##
    #enInfinitive = 1
    #frInfinitive = 3
    #Present = 5
    #   Je = 1
    #   Tu = 3
    #   Il = 5
    #   Elle = 7 
    #   Nous = 9
    #   Vous = 11
    #   Ils = 13
    #Perfect = 7 
    #Imperfect = 9
    #Simple = 11
    #Conditional = 13
    #Pastparticiple = 15

    def __init__(self, data):
        self.data = data

    def removeBrackets(self, word, has = False):
        x = len(word)
        lWord = list()
        for char in word:
            lWord.append(char)
        n = 0
        while n < x:
            if lWord[n] == "[" and lWord[n-1] == " ":
                if has: return True
                lWord.reverse()
                a = 0
                while a <= x-n:
                    lWord.remove(lWord[0])
                    a+=1
                lWord.reverse()
                break
            n+=1
        word = ""
        for char in lWord:
            word += char
        return unicode(word)
    
    def getEnglishInfinitiveAsFrench(self, english, Return = False):
        end = False
        verbs = list()
        for verb in self.data.getElementsByTagName("Verb"):
            if Dict(self.data).removeBrackets(Dict(self.data).getAccents(verb.childNodes[1].childNodes[0].data)) == english:
                if Return: verbs.append(Dict(self.data).getAccents(verb.childNodes[3].childNodes[0].data))
                if not Return: print Dict(self.data).getAccents(verb.childNodes[3].childNodes[0].data)
                end = True
        if not end:
            if Return: return ["Verb not in dictionary, check spelling and accents"]
            print "Verb not in dictionary, check spelling and accents"
        if Return: return verbs

    def getFrenchInfinitiveAsEnglish(self, french, Return = False):
        end = False
        verbs = list()
        for verb in self.data.getElementsByTagName("Verb"):
            if Dict(self.data).removeBrackets(Dict(self.data).getAccents(verb.childNodes[3].childNodes[0].data)) == french:
                if Return: verbs.append(Dict(self.data).getAccents(verb.childNodes[1].childNodes[0].data))
                if not Return: print Dict(self.data).getAccents(verb.childNodes[1].childNodes[0].data)
                end = True
        if not end:
            if Return: return ["Verb not in dictionary, check spelling and accents"]
            print "Verb not in dictionary, check spelling and accents"
        if Return: return verbs

    def getEnglishForPart(self, french, Return = False):
        end = False
        parts = list()
        for verb in self.data.getElementsByTagName("Verb"):
            for x in range(16):
                if x % 2 != 0 and x>0:
                    if (x == 15 or x == 3 or x == 1):
                        if Dict(self.data).getAccents(Dict(self.data).getAccents(verb.childNodes[x].childNodes[0].data)) == french:
                            if not Return: print Dict(self.data).getAccents(verb.childNodes[x].nodeName), "of", Dict(self.data).getAccents(verb.childNodes[3].childNodes[0].data)
                            if Return: parts.append(Dict(self.data).getAccents(verb.childNodes[x].nodeName) + " of " + Dict(self.data).getAccents(verb.childNodes[3].childNodes[0].data))
                            end = True
                    else:
                        for y in range(14):
                            if (y % 2 != 0 and y>0) and Dict(self.data).getAccents(verb.childNodes[x].childNodes[y].childNodes[0].data) == french:
                                if not Return: print "English Infinitive:", Dict(self.data).getAccents(verb.childNodes[1].childNodes[0].data)
                                if not Return: print "French Infinitive:", Dict(self.data).getAccents(verb.childNodes[3].childNodes[0].data)
                                if not Return: print Dict(self.data).getAccents(verb.childNodes[x].childNodes[y].nodeName),"form of",Dict(self.data).getAccents(verb.childNodes[x].nodeName),"tense"
                                if not Return: print ""
                                if Return: parts.append("English Infinitive: " + Dict(self.data).getAccents(verb.childNodes[1].childNodes[0].data) + "\n" + "French Infinitive: " + Dict(self.data).getAccents(verb.childNodes[3].childNodes[0].data) + "\n" + Dict(self.data).getAccents(verb.childNodes[x].childNodes[y].nodeName) + " form of " + Dict(self.data).getAccents(verb.childNodes[x].nodeName) + " tense\n")
                                end = True
        if not end:
            if Return: return ["Verb not in dictionary, check spelling and accents"]
            print "Verb not in dictionary, check spelling and accents"
        if Return: return parts
                                
    def getPartForVerb(self, infinitive, tense):
        end = False
        for verb in self.data.getElementsByTagName("Verb"):
            if Dict(self.data).removeBrackets(Dict(self.data).getAccents(verb.childNodes[3].childNodes[0].data)) == infinitive:
                if Dict(self.data).removeBrackets(Dict(self.data).getAccents(verb.childNodes[3].childNodes[0].data), True): print Dict(self.data).getAccents(verb.childNodes[3].childNodes[0].data)
                for x in range(14):
                    if (x % 2 != 0 and x>0):
                        a = Dict(self.data).getAccents(verb.childNodes[tense].childNodes[x].childNodes[0].data)[0]
                        if (a != u"a" and a != u"e" and a != u"é" and a != u"è" and a != u"h" and a != u"i") or x != 1:
                            print Dict(self.data).getAccents(verb.childNodes[tense].childNodes[x].nodeName), Dict(self.data).getAccents(verb.childNodes[tense].childNodes[x].childNodes[0].data)
                            end = True
                        elif x == 1:
                            print "J'" + Dict(self.data).getAccents(verb.childNodes[tense].childNodes[x].childNodes[0].data)
                            end = True
                print "\n"
        if not end:
            print "Verb not in dictionary, check spelling and accents"
                
    def getListVerbs(self, Return = False):
        verbs = list()
        for verb in self.data.getElementsByTagName("Verb"):
            En = Dict(self.data).getAccents(verb.childNodes[1].childNodes[0].data)
            Fr = Dict(self.data).getAccents(verb.childNodes[3].childNodes[0].data)
            if Return: verbs.append(Fr + " : " + En)
            if not Return: print Fr, ":", En
        if Return: return verbs

    def getAccents(self, word):
        x = len(word)
        lWord = list()
        for char in word:
            lWord.append(char)
        n = 0
        while n < x:
            if lWord[n] == "^" and lWord[n-1] == "(":
                if lWord[n-2] == "e":
                    lWord[n-2] = u"ê"
                elif lWord[n-2] == "o":
                    lWord[n-2] = u"ô"
                elif lWord[n-2] == "u":
                    lWord[n-2] = u"û"
                elif lWord[n-2] == "i":
                    lWord[n-2] = u"î"
                elif lWord[n-2] == "a":
                    lWord[n-2] = u"â"
                lWord.remove(lWord[n+1])
                lWord.remove(lWord[n])
                lWord.remove(lWord[n-1])
                n+=-2
                x+=-3
            elif lWord[n] == "," and lWord[n-1] == "(":
                if lWord[n-2] == "c":
                    lWord[n-2] = u"ç"
                lWord.remove(lWord[n+1])
                lWord.remove(lWord[n])
                lWord.remove(lWord[n-1])
                n+=-2
                x+=-3
            elif lWord[n] == ":" and lWord[n-1] == "(":
                if lWord[n-2] == "e":
                    lWord[n-2] = u"ë"
                elif lWord[n-2] == "i":
                    lWord[n-2] = u"ï"
                elif lWord[n-2] == "u":
                    lWord[n-2] = u"ü"
                lWord.remove(lWord[n+1])
                lWord.remove(lWord[n])
                lWord.remove(lWord[n-1])
                n+=-2
                x+=-3
            elif lWord[n] == ">" and lWord[n-1] == "(":
                if lWord[n-2] == "e":
                    lWord[n-2] = u"é"
                lWord.remove(lWord[n+1])
                lWord.remove(lWord[n])
                lWord.remove(lWord[n-1])
                n+=-2
                x+=-3
            elif lWord[n] == "`" and lWord[n-1] == "(":
                if lWord[n-2] == "e":
                    lWord[n-2] = u"è"
                elif lWord[n-2] == "u":
                    lWord[n-2] = u"ù"
                elif lWord[n-2] == "a":
                    lWord[n-2] = u"à"
                lWord.remove(lWord[n+1])
                lWord.remove(lWord[n])
                lWord.remove(lWord[n-1])
                n+=-2
                x+=-3
            n+=1
        word = ""
        for char in lWord:
            word += char
        return unicode(word)

    def fixAccents(self, word):
        x = len(word)
        lWord = list()
        for char in word:
            lWord.append(char)
        n = 0
        while n < x:
            if lWord[n] == "é":
                lWord[n] = u"é"
            elif lWord[n] == "à":
                lWord[n] = u"à"
            elif lWord[n] == "è":
                lWord[n] = u"è"
            elif lWord[n] == "ù":
                lWord[n] = u"ù"
            elif lWord[n] == "â":
                lWord[n] = u"â"
            elif lWord[n] == "ê":
                lWord[n] = u"ê"
            elif lWord[n] == "î":
                lWord[n] = u"î"
            elif lWord[n] == "ô":
                lWord[n] = u"ô"
            elif lWord[n] == "û":
                lWord[n] = u"û"
            elif lWord[n] == "ë":
                lWord[n] = u"ë"
            elif lWord[n] == "ï":
                lWord[n] = u"ï"
            elif lWord[n] == "ü":
                lWord[n] = u"ü"
            elif lWord[n] == "ç":
                lWord[n] = u"ç"
            n+=1
        word = ""
        for char in lWord:
            word += char
        return unicode(word) 

def program(xml):
    print message
    loop = True
    while loop:
        loop2 = True
        print "These are your options:\n\n1) Display list of available verbs\n2) English to French (infinitives)\n3) French to English (infinitives)\n\
4) Get infinitive of a part of a verb\n5) Enter in infinitive and tense and display tense\n6) Quit\n"
        option = int(raw_input("Enter in option number: "))
        if option == 1:
            print ""
            Dict(xml).getListVerbs()
            print ""
        elif option == 2:
            while loop2:
                print ""
                infinitive = str(raw_input("English infinitive (enter 0 to quit): "))
                print ""
                if infinitive == "0": break
                Dict(xml).getEnglishInfinitiveAsFrench(Dict(xml).fixAccents(infinitive))
        elif option == 3:
            while loop2:
                print ""
                infinitive = str(raw_input("French infinitive (enter 0 to quit): "))
                print ""
                if infinitive == "0": break
                Dict(xml).getFrenchInfinitiveAsEnglish(Dict(xml).fixAccents(infinitive))
        elif option == 4:
            while loop2:
                print ""
                part = str(raw_input("Word such as suis (enter 0 to quit): "))
                print ""
                if part == "0": break
                Dict(xml).getEnglishForPart(Dict(xml).fixAccents(part))
        elif option == 5:
            while loop2:
                loop3 = True
                print ""
                infinitive = str(raw_input("French infinitive (enter 0 to quit): "))
                print ""
                if infinitive == "0": break
                while loop3:
                    print "Available tenses:\n\n1) Present\n2) Perfect (Past tense)\n3) Imperfect\n4) Simple Future\n5) Conditional\n"
                    tense = int(raw_input("Tense number (0 to quit): "))
                    if tense == 0: break
                    print ""
                    if tense == 1:
                        trueTense = 5
                    elif tense == 2:
                        trueTense = 7
                    elif tense == 3:
                        trueTense = 9
                    elif tense == 4:
                        trueTense = 11
                    elif tense == 5:
                        trueTense = 13
                    Dict(xml).getPartForVerb(Dict(xml).fixAccents(infinitive), trueTense)
        else:
            print ""
            Quit = str(raw_input("Do you wish to quit (y/n): "))
            if Quit == "y" or Quit == "Y":
                print "Thanks for using FrenchDictionary.py!"
                loop = False
            elif Quit == "n" or Quit == "N":
                print "Ok!"
            else:
                print "Invalid option"

def errorHandler(xml):
    try:
        program(xml)
    except ValueError or TypeError or IOError:
        print "\n"
        print "Error: Reloading"
        print "\n"
        errorHandler(xml)

if not graphical: errorHandler(xml) #Standard IDLE
else: Graphics(message, Dict(xml).getListVerbs, Dict(xml).getFrenchInfinitiveAsEnglish, Dict(xml).getEnglishInfinitiveAsFrench, Dict(xml).getEnglishForPart, Dict(xml).getPartForVerb) #Graphical BETA


2. FrenchData.xml
Spoiler :

Code:
<?xml version="1.0"?>
<!-- XML verb entry guide -->
<!-- 
     copy out the form from <verb> to </verb> and paste in the alphabetical place to create
     a new verb. Entering accents requires special notation behind the accented letter, for
     example: an acute e is expressed as e(>). a grave accent is (`), a circumflex is (^), a 
     cedilla is (,), a umlaut is (:) and acute is (>) if you need to add a comment regarding 
     full verb meaning such as: to know (someone) or to know (a fact). then enter it as: to 
     know [a fact] where the square bracket is one space from the end of the word, everything
     after the brackets is ommited from the word. after pasting the form you can fill in the
     fields. Note that the Perfec tense needs to have the auxillary verb in front of it: 
     "ai regarde(>)"!
-->
<Verbs>
	<Verb>
		<enInfinitive>to have</enInfinitive>
		<frInfinitive>avoir</frInfinitive>
		<Present>
			<Je>ai</Je>
			<Tu>as</Tu>
			<Il>a</Il>
			<Elle>a</Elle>
			<Nous>avons</Nous>
			<Vous>avez</Vous>
			<Ils>ont</Ils>
		</Present>
		<Perfect>
			<Je>ai eu</Je>
			<Tu>as eu</Tu>
			<Il>a eu</Il>
			<Elle>a eu</Elle>
			<Nous>avons eu</Nous>
			<Vous>avez eu</Vous>
			<Ils>ont eu</Ils>
		</Perfect>
		<Imperfect>
			<Je>avais</Je>
			<Tu>avais</Tu>
			<Il>avait</Il>
			<Elle>avait</Elle>
			<Nous>avions</Nous>
			<Vous>aviez</Vous>
			<Ils>avaient</Ils>
		</Imperfect>
		<Simple>
			<Je>aurai</Je>
			<Tu>auras</Tu>
			<Il>aura</Il>
			<Elle>aura</Elle>
			<Nous>aurons</Nous>
			<Vous>aurez</Vous>
			<Ils>auront</Ils>
		</Simple>
		<Conditional>
			<Je>aurais</Je>
			<Tu>aurais</Tu>
			<Il>aurait</Il>
			<Elle>aurait</Elle>
			<Nous>aurions</Nous>
			<Vous>auriez</Vous>
			<Ils>auraient</Ils>
		</Conditional>
		<PastParticiple>eu</PastParticiple>
	</Verb>
</Verbs>


3. Graphics.py
Spoiler :

Code:
#Graphical display handling for French dictionary!
from Tkinter import *
import tkFont
import tkSimpleDialog
import tkColorChooser
import tkMessageBox

defaultColour = (255, 255, 155)

def Graphics(MSG, VerbList, FrenchToEnglish, EnglishToFrench, Infinitives, Parts):
    MSG = message = "Welcome to the five tense french verb dictionary!\nAll input is to be entered in LOWERCASE\n\
There can be two types of verbs in this dictionary, 'reflexive' and 'normal', because of this, when you find a reflexive pronoun infront of a verb include it\
.\n For example j'appelle and je m'appelle are two different things. so when using option 4, entering in appelle will tell you je form of present tense of appeler\
, \nhowever m'appelle will tell you the je form of the present tense of appeler [reflexive]. Typing in appeler into option 3 will tell you BOTH to call and to be called\
.\n Entering in to be called into option 2 will give you appeler [reflexive]. Note that reflexive infintives start with se or s' but they are not written with these within the program!\n"
    
    def colourPicker():
        tkColorChooser.askcolor(defaultColour)

    def List():
        message = ""
        for verb in VerbList(True):
            message = message + verb + "\n"
        tkMessageBox.showinfo("Result", message)
        
    def FRtoEN():
        IN = tkSimpleDialog.askstring("French to English", "Enter in a french infinitive here!")
        message = ""
        for verb in FrenchToEnglish(IN, True):
            message = message + verb + "\n"
        tkMessageBox.showinfo("Result", message)

    def ENtoFR():
        IN = tkSimpleDialog.askstring("English to French", "Enter in an english infinitive here!")
        message = ""
        for verb in EnglishToFrench(IN, True):
            message = message + verb + "\n"
        tkMessageBox.showinfo("Result", message)

    #def Part():
    #    IN = tkSimpleDialog.askstring("English to French", "Enter in an english infinitive here!")
    #    message = ""
    #    for verb in EnglishToFrench(IN, True):
    #        message = message + verb + "\n"
    #    tkMessageBox.showinfo("Result", message)

    def Infinitive():
        Part = tkSimpleDialog.askstring("Get an infinitive", "Enter in a part of a verb here!")
        message = ""
        for verb in Infinitives(Part, True):
            message = message + verb + "\n"
        tkMessageBox.showinfo("Result", message)

    def Quit():
        root.destroy()
    
    root = Tk()
    menu = Menu(root)
    toolbar = Frame(root)

    font10 = tkFont.Font(family="Comic Sans MS", size=10)
    root.title("5 Tense Verb Dictionary")

    root.config(menu=menu)
    menu.add_command(label="Change Colour", command=colourPicker)    
    menu.add_command(label="Quit", command=Quit)
    
    b = Button(toolbar, text="List", bg = "light yellow", command=List)
    b.pack(side=LEFT)
    b = Button(toolbar, text="English to French", bg = "light yellow", command=ENtoFR)
    b.pack(side=LEFT)
    b = Button(toolbar, text="French to English", bg = "light yellow", command=FRtoEN)
    b.pack(side=LEFT)
    b = Button(toolbar, text="Get infinitive for part", bg = "light yellow", command=Infinitive)
    b.pack(side=LEFT)
    toolbar.pack(side=TOP)

    w = Label(root, text=MSG, font=font10, bg="light yellow")
    w.pack()

    root.mainloop()


to run edit file 1 with idle and run from there! remember this is 2.7.2
 
Here it is:
Code:
    def Popup(name, text, button):
        def exit():
            popup.destroy()
        
        popup = Tk()
        popup.title(name)
        body = Label(popup, text=text)
        body.pack(side=TOP, fill=X)
        btn = Button(popup, text=button, command=exit)
        btn.pack(side=BOTTOM, fill=X)

How to use:
Code:
Popup("Result", message, "OK")
 
Top Bottom