[Python] Need Help with event

Discussion in 'Civ4 - SDK/Python' started by Premier Valle, Feb 25, 2008.

  1. Premier Valle

    Premier Valle FF: Babylon 5 Mod Team

    Joined:
    Sep 9, 2007
    Messages:
    675
    Location:
    Ich bin in Mexico Stadt
    Hello everyone, I'm new to python but have more experience with other programming languajes.

    I want to add an event in Final Frontier that will trigger 10% of the times a city/System is colonized, so I tried adding code to the "onCityBuilt" event in "CvFinalFrontierEvents", but I run into several problems, sometimes the code will simply not run, but sometimes I have problems with the game GUI/Interface, maps not showing as they should, or endless exceptions.

    I have read Kael's guide to adding popups, but only the second kind of popups seems to work... sometimes.

    I have tried the following code:
    To discriminate the player (only human) and the 10% chance I use this:
    Code:
    import random
    #############Jon Shafer's FF code##########
    hx_randomNumber = random.randint(1,10)
    hx_CityOwner = pCity.getOwner()
    hx_iPlayer = gc.getPlayer(hx_CityOwner)
    if (hx_iPlayer.isHuman() and hx_iPlayer.isAlive()):
            if (hx_randomNumber != 0):
            ####Popup code here#########
    This seems to work fine, but the problem seems to be the popup, I have tried:
    Code:
    popup = PyPopup.PyPopup(9876, EventContextTypes.EVENTCONTEXT_ALL)
    popup.setHeaderString('Header')
    popup.setBodyString('Body')
    popup.createPullDown(0)
    popup.addPullDownString('str0',0)
    popup.addPullDownString('str1',1)
    popup.launch()
    and:
    Code:
    popupInfo = CyPopupInfo()
    popup.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON)
    popup.setText('Text')
    popup.addPythonButton('btn0','')
    popup.addPythonButton('btn1','')
    popup.addPopup(0)
    When I tested the code on the game's python console it runs perfectly, but when I save the code into the file and run the game, the code doesn't work.

    I've been trying all the last week to figure out why and how, as you can imagine I've failed and I'm getting frustrated, so I come to you seeking enlightment.

    It would be best with CyPopupInfo, as it seems easier to handle returning values with this one. (or even better CyPopup, I believe that pictures can be used with CyPopup).

    As for the handling of the returning values, I haven't tried it (there is little point since the popup can not work), but should be handled with:

    popupInfo.setOnClickedPythonCallback("python_function")

    with python_function being a function defined in "CvScreenInterface".

    :please::please:Any help you can provide will be greatly apreciated, thanks in advance.:please::please:

    Premier Valle
     
  2. Premier Valle

    Premier Valle FF: Babylon 5 Mod Team

    Joined:
    Sep 9, 2007
    Messages:
    675
    Location:
    Ich bin in Mexico Stadt
    Any Ideas? please.
     

Share This Page