Need help merging

I highly, highly recommend that you take a couple afternoons and go through the free online book How to Think Like a Computer Scientist. The third bullet under the DOWNLOAD section of that page has a link to the standard online HTML version so you don't have to download and/or print it.

In the meantime, a parameter is a value that you pass to a function. initUnit() is a function, and you put the parameters between its ()s to tell it what type of unit to initialize, where to put it (x and y), what type of AI it should have, and what direction it should face.

CyUnit.initUnit(eUnitType, x, y, eUnitAI, eFacingDirection)​
 
Nope. This is from the first line of the code you quoted. I've added spaces and colors to make counting the parameters easier.

Code:
initUnit([B][COLOR="Red"]iBestDefender[/COLOR][/B], [B][COLOR="Magenta"]cityX[/COLOR][/B], [B][COLOR="Blue"]cityY[/COLOR][/B], [B][COLOR="Green"]3[/COLOR][/B])

Notice that there are 4 parameters while initUnit requires a fifth parameter: eFacingDirection. You would correct the above code by adding 0 as the direction. I have no idea what direction that is but you could easily look it up or specify a different direction.

Code:
initUnit(iBestDefender, cityX, cityY, 3[B][COLOR="Red"], 0[/COLOR][/B])

You need to check every line that calls initUnit() to make sure it has five parameters.
 
OK i tried, it helped to color code, thx, but still has a problem??
Traceback (most recent call last):

File "CvEventInterface", line 25, in onEvent

File "CvCustomEventManager", line 162, in handleEvent

File "CvCustomEventManager", line 173, in _handleDefaultEvent

File "BarbarianCiv", line 104, in onEndGameTurn

File "BarbarianCiv", line 207, in checkBarbCities

File "BarbarianCiv", line 429, in createBarbCiv

ArgumentError: Python argument types in
CyPlayer.initUnit(CyPlayer, int, int, int, CvPythonExtensions.UnitAITypes, int)
did not match C++ signature:
initUnit(class CyPlayer {lvalue}, int, int, int, enum UnitAITypes, enum DirectionTypes)
ERR: Python function onEvent failed, module CvEventInterface

Spoiler :
Code:
newPlayer.initUnit(gpType,ix,iy,UnitAITypes.NO_UNITAI,-1)

if( not iBestDefender == UnitTypes.NO_UNIT ) : pyNewPlayer.initUnit(iBestDefender,cityX,cityY,3,-1)
                    if( not iWorker == UnitTypes.NO_UNIT ) : pyNewPlayer.initUnit(iWorker,cityX,cityY,1,-1)


                            if( not iCounter == UnitTypes.NO_UNIT ) : pyNewPlayer.initUnit(iCounter,cityX,cityY,2+game.getSorenRandNum(5+extraUnits,'BarbarianCiv: give military infantry'))
                            if( not iAttack == UnitTypes.NO_UNIT ) : pyNewPlayer.initUnit(iAttack,cityX,cityY,2+game.getSorenRandNum(5+extraUnits,'BarbarianCiv: give military mobile'))
                        else :
                            if( not iCounter == UnitTypes.NO_UNIT ) : pyNewPlayer.initUnit(iCounter,cityX,cityY,1+game.getSorenRandNum(4+extraUnits,'BarbarianCiv: give military infantry'))
                            if( not iMobile == UnitTypes.NO_UNIT ) : pyNewPlayer.initUnit(iMobile,cityX,cityY,1+game.getSorenRandNum(4+extraUnits,'BarbarianCiv: give military mobile'))
                            if( not iAttack == UnitTypes.NO_UNIT ) : pyNewPlayer.initUnit(iAttack,cityX,cityY,1+game.getSorenRandNum(4+extraUnits,'BarbarianCiv: give military mobile'))
                        if( city.canConstruct( iBarracks ) ) :

if( not iScout == UnitTypes.NO_UNIT ) : pyNewPlayer.initUnit(iScout,capital.getX(),capital.getY(),1,-1)
                if( not iWorker == UnitTypes.NO_UNIT ) : pyNewPlayer.initUnit(iWorker,capital.getX(),capital.getY(),1,-1)

if( not iSettler == UnitTypes.NO_UNIT ) : pyNewPlayer.initUnit(iSettler,capital.getX(),capital.getY(),1,-1)
                    if( not iBestDefender == UnitTypes.NO_UNIT ) : pyNewPlayer.initUnit(iBestDefender,capital.getX(),capital.getY(),1,-1)
                if( barbSettleType == 2 ) : # Builder
                    if( not iWorker == UnitTypes.NO_UNIT ) : pyNewPlayer.initUnit(iWorker,capital.getX(),capital.getY(),1,-1)
                    if( not iSettler == UnitTypes.NO_UNIT ) : pyNewPlayer.initUnit(iSettler,capital.getX(),capital.getY(),1,-1)
                    if( not iBestDefender == UnitTypes.NO_UNIT ) : pyNewPlayer.initUnit(iBestDefender,capital.getX(),capital.getY(),1)
                    if( not iCounter == UnitTypes.NO_UNIT ) : pyNewPlayer.initUnit(iCounter,capital.getX(),capital.getY(),2,-1)
                    if( capital.canConstruct( iMarket ) ) :

if( not iWorker == UnitTypes.NO_UNIT ) : pyNewPlayer.initUnit(iWorker,capital.getX(),capital.getY(),1,-1)

if( not iCounter == UnitTypes.NO_UNIT ) : pyNewPlayer.initUnit(iCounter,cityX,cityY,1,-1)
                    if( not iMobile == UnitTypes.NO_UNIT ) : pyNewPlayer.initUnit(iMobile,cityX,cityY,2,-1)
                    if( not iAttack == UnitTypes.NO_UNIT ) : pyNewPlayer.initUnit(iAttack,cityX,cityY,1,-1)

if( self.LOG_DEBUG ) : CvUtil.pyPrint("  BC - Giving new civ some boats for raiding")
                                pyNewPlayer.initUnit(iAssaultShip,city.getX(),city.getY(),2,-1)
                            break
:blush:
 
Okay it looks like it insists on having the actual DirectionTypes constant. Try changing the 0 you added to DirectionTypes.DIRECTION_NORTH.
 
Okay it looks like it insists on having the actual DirectionTypes constant. Try changing the 0 you added to DirectionTypes.DIRECTION_NORTH.

I changed it with: ,-1)
not: ,0) as stated by jojoweb???:crazyeye:

See post # 37.

So now change all the ,-1) to: ,DirectionTypes.DIRECTION_NORTH)
 
All of these lines are still missing that last direction argument.

Code:
                            if( not iCounter == UnitTypes.NO_UNIT ) : pyNewPlayer.initUnit(iCounter,cityX,cityY,2+game.getSorenRandNum(5+extraUnits,'BarbarianCiv: give military infantry'))
                            if( not iAttack == UnitTypes.NO_UNIT ) : pyNewPlayer.initUnit(iAttack,cityX,cityY,2+game.getSorenRandNum(5+extraUnits,'BarbarianCiv: give military mobile'))
                        else :
                            if( not iCounter == UnitTypes.NO_UNIT ) : pyNewPlayer.initUnit(iCounter,cityX,cityY,1+game.getSorenRandNum(4+extraUnits,'BarbarianCiv: give military infantry'))
                            if( not iMobile == UnitTypes.NO_UNIT ) : pyNewPlayer.initUnit(iMobile,cityX,cityY,1+game.getSorenRandNum(4+extraUnits,'BarbarianCiv: give military mobile'))
                            if( not iAttack == UnitTypes.NO_UNIT ) : pyNewPlayer.initUnit(iAttack,cityX,cityY,1+game.getSorenRandNum(4+extraUnits,'BarbarianCiv: give military mobile'))

As is this one:

Code:
                    if( not iBestDefender == UnitTypes.NO_UNIT ) : pyNewPlayer.initUnit(iBestDefender,capital.getX(),capital.getY(),1)

If you don't feel like specifying a direction, you can use "DirectionTypes.NO_DIRECTION". It still ends up pointing in some direction, of course. I'm not sure which direction it turns out to be but I think it is up (north).

I have no idea what effect adding the random number to the 4th parameter has - selecting a random unit AI type seems odd, particularly when the range seems variable as well; the first one ends up with a number from 2 to 6+extraUnits, which seems like it could be more than the number of different unit AI types, depending on how many there actually are and how big "extraUnits" is. Are you sure this is right?
 
All of these lines are still missing that last direction argument.

Is this better:
Spoiler :
Code:
if( not iCounter == UnitTypes.NO_UNIT ) : 

pyNewPlayer.initUnit(iCounter,cityX,cityY,2+game.getSorenRandNum(5+extraUnits,'BarbarianCiv: give military 

infantry'),-1)
                            if( not iAttack == UnitTypes.NO_UNIT ) : 

pyNewPlayer.initUnit(iAttack,cityX,cityY,2+game.getSorenRandNum(5+extraUnits,'BarbarianCiv: give military mobile'),-1)
                        else :
                            if( not iCounter == UnitTypes.NO_UNIT ) : 

pyNewPlayer.initUnit(iCounter,cityX,cityY,1+game.getSorenRandNum(4+extraUnits,'BarbarianCiv: give military 

infantry'),-1)
                            if( not iMobile == UnitTypes.NO_UNIT ) : 

pyNewPlayer.initUnit(iMobile,cityX,cityY,1+game.getSorenRandNum(4+extraUnits,'BarbarianCiv: give military mobile'),-1)
                            if( not iAttack == UnitTypes.NO_UNIT ) : 

pyNewPlayer.initUnit(iAttack,cityX,cityY,1+game.getSorenRandNum(4+extraUnits,'BarbarianCiv: give military mobile'),-1)


As is this one:

whats wrong in the second one??


I have no idea what effect adding the random number to the 4th parameter has - selecting a random unit AI type seems odd, particularly when the range seems variable as well; the first one ends up with a number from 2 to 6+extraUnits, which seems like it could be more than the number of different unit AI types, depending on how many there actually are and how big "extraUnits" is. Are you sure this is right?


I dont understand this part your saying, sorry.


I still get this:

Spoiler :
Traceback (most recent call last):

File "CvEventInterface", line 25, in onEvent

File "CvCustomEventManager", line 162, in handleEvent

File "CvCustomEventManager", line 173, in _handleDefaultEvent

File "BarbarianCiv", line 104, in onEndGameTurn

File "BarbarianCiv", line 207, in checkBarbCities

File "BarbarianCiv", line 429, in createBarbCiv

ArgumentError: Python argument types in
CyPlayer.initUnit(CyPlayer, int, int, int, CvPythonExtensions.UnitAITypes, int)
did not match C++ signature:
initUnit(class CyPlayer {lvalue}, int, int, int, enum UnitAITypes, enum DirectionTypes)
ERR: Python function onEvent failed, module CvEventInterface
Traceback (most recent call last):
 
Okay it looks like it insists on having the actual DirectionTypes constant. Try changing the 0 you added to DirectionTypes.DIRECTION_NORTH.

OK, i also tried it this way, and got this error??

Traceback (most recent call last):

File "CvEventInterface", line 25, in onEvent

File "CvCustomEventManager", line 162, in handleEvent

File "CvCustomEventManager", line 173, in _handleDefaultEvent

File "BarbarianCiv", line 104, in onEndGameTurn

File "BarbarianCiv", line 207, in checkBarbCities

File "BarbarianCiv", line 523, in createBarbCiv

TypeError: initUnit() takes at most 5 arguments (6 given)
ERR: Python function onEvent failed, module CvEventInterface


EDIT: Line 523: Is this 4,5,or 6?
Code:
if( not iBestDefender == UnitTypes.NO_UNIT ) : pyNewPlayer.initUnit(iBestDefender,cityX,cityY,3,DirectionTypes.DIRECTION_NORTH)
 
The 3 should be a UnitAITypes constant. Here's the signature for initUnit():

Code:
CyUnit initUnit(UnitType iIndex, INT iX, INT iY, UnitAIType eUnitAI, DirectionType eFacingDirection)

I dunno what's going on here. Are you definitely using this file in your testing?
 
The 3 should be a UnitAITypes constant. Here's the signature for initUnit():

Code:
CyUnit initUnit(UnitType iIndex, INT iX, INT iY, UnitAIType eUnitAI, DirectionType eFacingDirection)

I dunno what's going on here. Are you definitely using this file in your testing?

So you only count the thingys in the ( -, -, -, -, -)?:crazyeye:


I'd be alot easier if someone would just look at the file? constants/variables/parameters, (what the H --- ??) This is just like taking a Mechanic to do Surgery? HUH?
 
There are two downsides to having one of us do it for you:

1. We're busy folks who take time away from our own projects to help others learn. I love helping people learn. I dislike doing other people's work for them. I speak for myself only, of course.

2. If you don't learn, you'll forever need to ask someone else to do this for you, for the next feature you want to add, and the next one, and so on . . . .

"Give a man a fish, and you feed him for a day. Teach a man to fish, and you feed him for a lifetime."
 
There are two downsides to having one of us do it for you:

1. We're busy folks who take time away from our own projects to help others learn. I love helping people learn. I dislike doing other people's work for them. I speak for myself only, of course.

2. If you don't learn, you'll forever need to ask someone else to do this for you, for the next feature you want to add, and the next one, and so on . . . .

"Give a man a fish, and you feed him for a day. Teach a man to fish, and you feed him for a lifetime."

Nice quote, LOL, now back to my problem? LOL So whats next??:crazyeye::confused:

I understand what your saying, but right now i have three (3) BarbarianCiv files:
1. with ,0)
2. ,-1)
3. ,DirectionTypes.DIRECTION_NORTH)

It would be nice if someone would take a look and make sure i did do what i was asked, thats all i am saying, if it weren't for you'll , i'd never get anything done, hows that!! So where's everyone ELSE?? All the big time python people here on CFC??
I always try to help as many people as i can here, no matter how busy i am.
 
You should take the third file ;).

A bit easier:
InitUnit needs
(TheUnitType, a number, a number, UnitAITypes.someunitAI, DirectionTypes.DIRECTION_somewhere)

Unit type is most something like:
- eUnit
- iUnit
- gc.getInfoTypeForString("UNIT_WHATEVER")
- or any name, but before has something to be like anyname = gc.getInfoTypeForString("UNIT_WHATEVER")

The 2 numbers: It's the position on the map. So it can be:
- Just to numbers
- position from somewhere else, most named like iX, iY or myX, myY
- or a direct position, like oldunit.getX(),oldunit.getY()

The an UnitAIType, you have examples in your files.
And a facing direction. Is completly unimportant, just take the example from EF.
 
Kick the "3" out, then it should work.

I tried this and got this:

Traceback (most recent call last):

File "CvEventInterface", line 25, in onEvent

File "CvCustomEventManager", line 162, in handleEvent

File "CvCustomEventManager", line 173, in _handleDefaultEvent

File "BarbarianCiv", line 104, in onEndGameTurn

File "BarbarianCiv", line 207, in checkBarbCities

File "BarbarianCiv", line 545, in createBarbCiv

AttributeError: PyCity instance has no attribute 'setHasRealBuildingIdx'
ERR: Python function onEvent failed, module CvEventInterface
Traceback (most recent call last):

So i put it back the way it was with the direction.north thingy.
 
You want setNumRealBuilding() which takes two parameters: the BuildingTypes such as eBuilding and the number of buildings--probably 1 for your case.
 
You want setNumRealBuilding() which takes two parameters: the BuildingTypes such as eBuilding and the number of buildings--probably 1 for your case.

Right now, which BarbCiv am i supposed to be using?? Then lets get back on course.:(:(
 
You said you tried the third file (which is the correct one to use), and it's now giving you an entirely new error. This is good. I posted the fix for that error, but now you want to go back to the first error which is gone? I'm confused. :confused:
 
Top Bottom