NoneType error even with "if iVariable:" ... how to get rid of it?

Cybah

Emperor
Joined
Jun 22, 2007
Messages
1,481
Code:
iCunResearchTech = pPlayer.getCurrentResearch()

[B]if iCunResearchTech[/B]:
	lDiscovered****echStrs = gc.getTechInfo(iCunResearchTech).getDescription()

the bold does not seem to have any effect. I get a NoneType error for the next getDescription line if there is no current research (no current research can happen when running AI Autoplay or when no city is founded = at starting round).

The code stores the description (e.g. "Fishing") of the current research if there is a current research. the code should stop if there is no current research. "if iCunResearchTech" does not work to get rid of the NoneType error.

My English is not that good, I hope you understand what I want.

Error message:

attachment.php
 
if iCunResearchTech

This will give a TRUE (and let the indent happen) if iCunResearchTech != 0, as 0 is the boolean false, and everything else is the boolean true. Everything else includes -1, which is what a nonetype tech provides for a number.

if iCunResearchTech != -1:

or

if iCunResearchTech > -1:

ought to work better.
 
To clarify, getCurrentResearch() does not return the special Python value None; it returns the integer -1. getTechInfo() returns None if you pass in an invalid TechTypes value: < 0 or >= getNumTechInfos().

xienwolf's solution is exactly what you need.
 
Back
Top Bottom