I need immediate help: spell prereqs are not working!

Deon

Lt. of Mordor
Joined
Jan 13, 2008
Messages
2,956
Location
St.Petersburg, Russian Federation
All of sudden all the spells which have prereqs are grayed out. I don't know what could I break because all I did is created another spell and added a few units... What can cause such a damage?!
 
All of sudden all the spells which have prereqs are grayed out. I don't know what could I break because all I did is created another spell and added a few units... What can cause such a damage?!

Run, flee for your very lives!!!!!!!!

Check you closed all of your tags and stuff. See if removing the spell you added fixes it.
 
Code:
def spellJobMining(caster):
	iGold = 1
	pPlot = caster.plot()
	iPlayer2 = pPlot.getOwner()
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	pPlayer2 = gc.getPlayer(iPlayer2)
	if iPlayer2 != iPlayer
		pPlayer1.changeGold(iGold)
		CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_JOB_MINING",()),'',1,'Art/Interface/Buttons/Freelancer/Jobs/job_mining.dds',ColorTypes(8),caster.getX(),caster.getY(),True,True)
	if iPlayer2 == iPlayer
				CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_JOB_MINING_SELF",()),'',1,'Art/Interface/Buttons/Freelancer/Jobs/job_mining.dds',ColorTypes(8),caster.getX(),caster.getY(),True,True)

This is what causes it... Hmmm...

P.S. I have 2 additional tabs in the last line... Can it break the whole file?
 
Python can be incredibly picky about indentation.

What error message is it displaying (if any) ?
 
I've found that any syntax error at all will stop this file from loading. It isn't essential fr the game to load, so you don't get any warning other than the fact that no spell that relies on python prereqs will work.

(I guess it would display an error if you have python debugging on, but patches tend to turn that off I always forget to reactivate it.)


I always make sure to check my python file in IDLE before loading them. I despise using IDLE to actually make any changes (how can you have a python editor that can't graphically show the difference between spaces and tabs?! How!?), but it is good for finding what lines are messed up. Of course, it is even more picky than Civ when it comes to using python, so the few places where Kael has a single space before the tabs (in the steal spell) are always the first (and, as it only finds one bug at once, only until you change them) problems found.
 
I haven't found a way. That is why I hate using it for the actual editing.

Oh, and IDLE's recommendation for how to fix having tabs inserted as spaces is to replace all the tabs with 4 spaces. How is that useful? How?! All that means if you must manually fix every line in the program instead of just 1! It doesn't make any sense!

Notepad2 or Notepad++ are much better programs to use in general, but IDLE is more useful for catching bugs.
 
OK, it was totally my fault. I forgot to put ":" after "if".
Also I used iPlayer1 instead of iPlayer to give gold.

So, here comes another question: it looks like I can't compare this way ( if iPlayer != iPlayer2: )

What is the right way to compare 2 players here? For now I use a comparison of caster's team and city's team (if caster.getTeam() != pCity.getTeam(): ) but I'd like to know.

P.S. You know, when you start to script after a few years of not touching any language (I wrote programs on C 5 years ago for my university... It was the last time I coded) you tend to make a lot of stupid errors :).
 
So, here's the code which is not working because I'm bad at API.

Code:
def spellJobMining(caster):
	iGold = 1
	pPlot = caster.plot()
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	iPlayer2 = pPlot.getOwner()
	pPlayer2 = gc.getPlayer(iPlayer2)
	if caster.getTeam() != pPlayer2.getTeam():
		pPlayer.changeGold(iGold)
		CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_JOB_MINING",()),'',1,'Art/Interface/Buttons/Freelancer/Jobs/job_mining.dds',ColorTypes(8),caster.getX(),caster.getY(),True,True)
	if caster.getTeam() == pPlayer2.getTeam():
		CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_JOB_MINING_SELF",()),'',1,'Art/Interface/Buttons/Freelancer/Jobs/job_mining.dds',ColorTypes(8),caster.getX(),caster.getY(),True,True)

I want to check if the plot belongs to another team and if so give 1 gold and display a text, in another case I want to give nothing and display another text.

It's not working because I try to get owner of plot in a wrong way (comparison works fine if I try to do it on a tile with city and use pPlayer2 = pCity.getOwner() as in the 1st post). Can someone clever like MC fix it and tell me what's my error?
 
OK, I've managed to fix it this way:
Code:
	pPlot = caster.plot()
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	if caster.getTeam() != pPlot.getTeam():
        .....

and it works. Here I get caster -> plot, then plot -> team and it's correct.

In the previous case I tried to get caster -> plot, then plot -> owner, then owner -> team and for some reason I did it wrong.

I'd highly appreciate if you helped me to fix it :).

if anyone can spend a bit of his own time to help me I'd be the most grateful and I think that I am able to attain my object one day and become a good modder :).
 
Uhm, another question: what should I check to know if the plot has culture on it?

I tried if (pPlot.getOwner != -1) but it's not working this way. I use -1 here because someone in Python/SDK forum told me that default "none" for Civ4 is -1. However 0 is not working here... What does getOwner return for a noone's plot?
 
The method "CyPlot.getOwner()" returns "PlayerTypes.NO_PLAYER" as a default for unowned tiles, which is a constant with a value of "-1". It should work. Don't forget the parantheses.

If it returns 0, then the first player is the owner, which is usually the human player.
 
Oh, XienWolf, thank you :)

Jean,

if pPlot.getOwner() != -1

didn't give me a correct result for some reason...

pPlot.isOwned() works perfectly :).

P.S. Which parentheses do you mean, after getOwner()?
 
Back
Top Bottom