How To Make Python Action Buttons

I admit that my action will require such SDK work. How do I declare a "real mission" in the SDK ?

Unfortunately, I have no idea. That was why I used python buttons and made this tutorial- instead of messing around in the SDK to make it work.

I suggest asking at xienwolf's Idiot's Guide to Editing the SDK tutorial, also in this forum, or asking in the SDK and Python forum.
 
I'm trying to implent your simplebutton script at the moment and hit the same problem WilliamOfOrange had. I put the two python files into a clear mod folder, so no other mods can cause this error. I've enabled enabling python exceptions and get these error messages, I'm using BTS 3.17 btw:

Code:
Traceback (most recent call last):
File "<string>", line 1, in ?
File "<string>", line 52, in load_module
File "CvEventInterface", line 13, in ?
File "<string>", line 52, in load_module
File "CvEventManager", line 12, in ?
File "<string>", line 52, in load_module
File "CvScreensInterface", line 3, in ?
File "<string>", line 35, in load_module
File "<string>", line 13, in _get_code
File "
CvMainInterface
", line
3160


g_pSelectedUnit.changeMoves(60)

(lots of empty error windows)

^
Syntax Error
:
Invalid syntax

Failed to load python module CvEventInterface

The error must occur in the second part of the CvMainInterface.py, because when this input is commented out the game starts with no problems and the button appears, but of course has no effect when activated.
Any ideas?
 
Aha! I had missed a parenthesis on the line that came before the change moves line. As a result, it was failing to load the interface file and thus causing an error.

The corrected line looks like this. It's also been fixed in the tutorial.

Code:
						pProspect.setBonusType(gc.getInfoTypeForString("BONUS_IRON"))
 
Ah, much better. The game starts now with no problems. But when the button is pushed, the following error occures (screenshot).
 

Attachments

  • pythonerror.jpg
    pythonerror.jpg
    90.8 KB · Views: 262
Ah, much better. The game starts now with no problems. But when the button is pushed, the following error occures (screenshot).

Not this error again... the problem is that you need a check in getBonusType to see which civilization is looking at the bonus. (To see if any bonus is actually there, regardless of who can see it, you use a value of -1). So, here is the fixed line:


Code:
			if pProspect.getBonusType(-1) == -1:

It's also been fixed in the tutorial.


I'm going to add the fourth button soon (or parts of it, at least), as suggested by Civ Fuehrer, a nuke effect using the ping graphics.
 
Okay, on to the next error. :)
The button works now with no problem as long as the prospection is not succesful (I guess). If it is, I get this (screenshot).
 

Attachments

  • pythonerror2.jpg
    pythonerror2.jpg
    71.9 KB · Views: 286
After adding the s the program has no errors anymore. However, no iron appears no matter how often the button is pushed. Also, the button can be activated all the time, even after being pushed already in that turn and even when the worker has no movement points left.
 
I found this awesome thread some time ago so tried adding my own button. It should appear to worker and it lets you plant trees. Right now I'm getting python exception:
Code:
Traceback (most recent call last):
  File "CvScreensInterface", line 657, in handleInput
  File "CvMainInterface", line 3146, in handleInput
AttributeError
: 
'int' object has no attribute 'getX'

ERR: Python function handleInput failed, module CvScreensInterface
Here's my code:
from def updateSelectionButtons( self ): CvMainInterface.py
Code:
## Plant forest mod start ##
					pUnit = g_pSelectedUnit
					iUnitType = pUnit.getUnitType()
					pUnitOwner = gc.getPlayer( pUnit.getOwner( ))
					if pUnitOwner.isTurnActive( ):
						if iUnitType == gc.getInfoTypeForString('UNIT_WORKER'):
							screen.appendMultiListButton( "BottomButtonContainer", gc.getFeatureInfo(gc.getInfoTypeForString('FEATURE_FOREST')).getButton(), 0, WidgetTypes.WIDGET_GENERAL, 300, 300, False )
							screen.show( "BottomButtonContainer" )
							iCount = iCount + 1
## Plant forest mod end ##
from def handleInput (self, inputClass): CvMainInterface.py
Code:
def handleInput (self, inputClass):

## Plant forest mod start ##
		if (inputClass.getNotifyCode() == 11 and inputClass.getData1() == 300 and inputClass.getData2() == 300):
			self.iPushedButtonUnit = g_pSelectedUnit
			[B]iX = self.iPushedButtonUnit.getX()[/B]
			iY = self.iPushedButtonUnit.getY()
			pForestPlot = CyMap().plot(iX, iY)
			if pForestPlot.getFeatureType() == -1:
				pForestPlot.setFeatureType(gc.getInfoTypeForString( "FEATURE_FOREST" ), 1)
				##g_pSelectedUnit.changeMoves(60)
## Plant forest mod end ##

		return 0
from def getWidgetHelp(self, argsList): CvGameUtils
Code:
	def getWidgetHelp(self, argsList):
		eWidgetType, iData1, iData2, bOption = argsList
		
## Plant forest mod start ##
		iType = WidgetTypes.WIDGET_GENERAL
		if (eWidgetType == iType):
			if (iData1 == 300):
				return CyTranslator().getText("TXT_KEY_BUTTON_PLANT_FOREST",())
## Plant forest mod end ##		
		
		return u""
the bold line is what gives the exception. If someone could explain me what's wrong in it?
 
The problem is, that you do not have the unit itself, only it's index number in the xml.
You have to get the unit instance, so that you can get the coordinates.
:blush: don't know the command, i'm not at my civ pc.


But for this, i would suggest creating a fake improvement, that just after onImprovementBuild adds a forest to a plot and is directly destroyed.
 
I can't get the first TUT to work.

It won't let me use any of my buttons, (ex. my settler won't settle).
I have check and used all the fixes that I have seen in the post. Nothing is working.

I was wondering if my XML isn't working right.

for my CIV4ArtDefines_Interface.xml, I have:

<InterfaceArtInfo>
<Type>INTERFACE_PROSPECT</Type>
<Path>Art/Interface/Buttons/Actions/Axe.dds</Path>
</InterfaceArtInfo>

Do I need to have something in the missioninfo.xml in the Units folder?
 
Did you activate python exceptions in the BtS.ini?
Because there might something be completely wrong.

I have this set:

; Custom XML and Python from user folder are not loaded
NoCustomAssets = 0
I tried it at = 1, and all my Python buttons didn't work.

Maybe the other mods have have meraged with my mod isn't letting thsi button work? FOr I have copyed and pasted .py code. But they all work as they should be, when I don't have this TUT button in.

Or I have have a spelling mistake that I can't catch, some where in the coding.
 
That's not Python exceptions- the correct tg should be "HidePythonExceptions=0" (set to 1 by default).

Also, you need to edit in the Civilization.ini file, not the modname.ini file. Civilization.ini is "_Civ4Config" in the BTS folder (this is a shortcut to the real file, which for some reason is in My Games).
 
hey, i did the first tutorial, and even manipulated it some to add various types of bonuses instead of only iron. So i'm trying to add a button that will make my unit invisible for a turn or two and then has to recharge for a certain number of turns....how do i do that?
 
Because of the reminder in the other thread: Oops :blush:, seems this has got forgotten.

At the problem: Making a single unit temporary invisible is sadly not possible in python :/ (unless you are creating a unit which will only occure once in the whole game, but i don't think that's your intention...).
 
I should be able to use this to make an assassinate command which kills certain noncombatants on a tile.. just have to ponder on how to do it yet :p
 
This is alot to take in at once! I can't wait to try it though. I had the idea recently of a 'seed forest' function for workers. That way I could seed/chop/repeat tiles, or not have to worry about chopping where I'll want mid-game lumber mills. The thing is though, I think it'd be too powerful a game mechanic early on, so I wanted to associate it with a tech. If anyone knows how to do that, (or if it was in the article, I only skimmed over the last half) please let me know!
 
Back
Top Bottom