Quick Modding Questions Thread

now such errors popped up (I'm sending the corrected code).
code1.png
 

Attachments

  • code2.png
    code2.png
    654.4 KB · Views: 35
Hi all, fiddling around with the SDK and found that an action costing 59 moves can be done infinitely, but an action that costs 60 moves takes 1 in-game "move" to do. Seems Civ can't handle fractional movement? Is that correct? and if so, why have a denominator of 60 moves?
 
this code should slow the development of technologies discovered by teams in proportion to the number of team members. (they got their learning points) Despite the fact that no information about errors pops up, the code does not affect the test in any way (despite placing the code in the CvEventManager.py file in the onBeginPlayerTurn definition)
code3.png

code4.png
 
error is not displayed, but still this function does not slow down team research.
 

Attachments

  • code7.png
    code7.png
    59.6 KB · Views: 30
How can I create a screen that contains an editable text box?

I would like to do the following: launch a screen that contains a text box and a button, let the player edit the text box, and then take an action (i.e. python function) based on the content of the text box. What can I do to implement that? Is there a similar example somewhere?
 
In the python API http://civ4bug.sourceforge.net/PythonAPI/ there are a whole bunch of functions for making popups. createEditBox seems to be what you're looking for - I've never used it though so can't say how it works exactly.

Edit: CyPopup has no functions to "get" text from anywhere but CyPopupInfo does, it looks like you have to use both. I'm certain I've seen platyping do something with python popups, let me do some searching...

Edit again: No luck finding any examples using the CyPopup functions. Platy seems to exclusively use CyGInterfaceScreen objects. However they share a lot of the same functions so if you want to look at an example here's one https://forums.civfanatics.com/resources/developing-traits.23103/.

CyPopup() definitely allows you to create a popup and there are functions in CyPopupReturn (especially the function "getEditBoxString") that must allow you to use text boxes. I don't exactly know how to get to CyPopupReturn from a popup, but here is how to create a popup in the first place: https://forums.civfanatics.com/threads/how-to-add-popups.183126/
 
Last edited:
Nice, thanks to you both. I was actually basing my attempts on the autoplay window, which is a CyGInterfaceScreen object, but I didn't know how to proceed because I could find sources or examples.
 
Couldn't get the CyGInterfaceScreen text box to work, but CyPopup turned out to work just fine and with less configuration too. The value of the text box is included in the popupReturn object in the response, so it's easy to work with.
 
Couldn't get the CyGInterfaceScreen text box to work, but CyPopup turned out to work just fine and with less configuration too. The value of the text box is included in the popupReturn object in the response, so it's easy to work with.

Would you mind posting the code that ended up working? I would love to see how it works.
 
I don't have it on hand right now, but I will later.
 
Almost forgot, here we go:
Code:
@handler("kbdEvent")
def observerModeShortcut(eventType, key):
   if eventType == events.EventKeyDown and key == InputTypes.KB_A and events.bCtrl:
       popup = CyPopup(4568, EventContextTypes.EVENTCONTEXT_ALL, True)
       
       popup.setHeaderString(text("TXT_KEY_INTERFACE_OBSERVER_MODE_HEADER"), CvUtil.FONT_LEFT_JUSTIFY)
       popup.setBodyString(text("TXT_KEY_INTERFACE_OBSERVER_MODE_BODY"), CvUtil.FONT_LEFT_JUSTIFY)
       popup.createEditBox(str(game.getGameTurnYear()), 0)
       
       popup.launch(True, PopupStates.POPUPSTATE_IMMEDIATE)

@popup_handler(4568)
def handleStartObserverMode(iPlayer, netUserData, popupReturn):
   try:
       iDestinationYear = int(popupReturn.getEditBoxString(0))
       iAutoplayTurns = year(iDestinationYear) - turn()
       
       if iAutoplayTurns > 0:
           startObserverMode(iAutoplayTurns)
   except Exception, e:
       print e
This is beset with custom helper code that I wrote so apologies if something isn't immediately clear, but the important part here is popup.createEditBox("initial text", id) and popupReturn.getEditBoxString(id).

In this case I used it to let the player enter an end year for autoplay ("observer mode") and then use the handler to actually start the autoplay for that number of turns.
 
Back
Top Bottom