Is Player:CanResearch broken?

Harald B

Warlord
Joined
Oct 20, 2010
Messages
135
I'm trying to determine in lua which techs a given civ can research (ie which techs they have met all the preqs for, but do not have yet). From the looks of it Player:CanResearch sounds like the function I need, but it seems to simply return false all the time.
Case in point: after setting pHB=Players[0], running
Code:
for tech in GameInfo.Technologies() do print(pHB:CanResearch(tech.ID)) end
in the LiveTuner just returns false for each tech, and the same is true for other players.
So is this function as broken as it seems to be? And if yes, is there anything I can use instead?
 
As it's used by the TechTree code it's very unlikely to be broken.

And a quick test in LiveTuner (making a minor mod to your print statement as it produces many false and few true entries) gets
Code:
> pHB = Players[0]
> for tech in GameInfo.Technologies() do if(pHB:CanResearch(tech.ID)) then print(tech.Type) end end
 WorldView: TECH_COMPASS
 WorldView: TECH_EDUCATION
 WorldView: TECH_STEEL
 WorldView: TECH_PRINTING_PRESS

which is exactly what I can currently research
 
:blush: Well. On trying it again it does work as it should. I suspect when I last tested it was before either me or the AI had founded a city. (It returns false if you don't have one.) Also I was being sloppy with conditions and uses of "not" which explains why I didn't see the debugging print statements I had put in the mod I was testing.
Sorry, and thanks for putting up with me.
 
Without any cities you're not producing any science (which is a function of population) so you won't be able to research anything. Not broken, but expected behaviour.
 
Back
Top Bottom