GetCurrentResearch Question

Pickly

Prince
Joined
Jun 5, 2009
Messages
535
This is an attempt to use python to, effectively add science production to a city. So far, what I've gotten from the python API and trying out a bunch of functions, is this:

Code:
PyPlayer(iPlayer).getTeam().changeResearchProgress([B]Something[/B].getCurrentResearch(), iScience, pPlayer)

Problem is that nothing I've tried so far in the something slot is actually working. (In the BTS API page its in the CyPlayer section, so I've tried both pPlayer and iPlayer. I also tried nothing, and whichever function gives the team of the player, since the other research function seems ot be based on the team rather than the player.)

Problem is I keep getting an error saying something like "function getCurrentResearch not found in CyPlayer" or something along those lines (I forget the exact warning.) On the API page, its listed as this:

Code:
TechType getCurrentResearch ()
int ()

For the actual questions: Am I using the right function for what I've trying to do (Get the technology that is currently being researched), what needs to go before it to actually get it working, and if it isn't the right function, is there one that will work for what I'm trying to do?

(i did look up in the API for some other technology related functions, and I think I've got the role and the form sort of right from other patterns in the API, but obviously something's missing.)
 
You're still some way from understanding how the API works, this is obvious. So you're not quite ready to do these things. Do you understand the difference between a player ID (PlayerTypes value) and a CyPlayer instance? What about a team ID (TeamTypes) value and a CyTeam instance? And what about CyPlayer/PyPlayer?

If you put forward the right question others will surely be able to answer whatever it is that you're having a hard time with.

This is probably what you wanna do, then. It requires you to know the Player ID defined as ePlayer:
PHP:
iChange = 100
pPlayer = gc.getPlayer(ePlayer) # fetches a CyPlayer instance with CyGlobalContext.getPlayer()
eTeam = pPlayer.getTeam() # fetches the team ID with CyPlayer.getTeam()
pTeam = gc.getTeam(eTeam) # fetches a CyTeam instance with CyGlobalContext.getTeam()
eTech = pPlayer.getCurrentResearch() # fetches the tech ID with CyPlayer.getCurrentReseach()
pTeam.changeResearchProgress(eTech, iChange, ePlayer)
Note that I use the e prefix for the IDs instead of i, but the variables are still basically integers. You can of course use whatever variables names you like.

The thing to realize is that the API is organized after class and the functions are class methods. So you always need to invoke them on a class instance. An instance of a class is like a real game object, like a player or a city or a unit, while the enumerated index number (the ID) is just a integer value. Its sorta like a house has a number, but you can't live in the number, right? And the class is the template that was used for creating that instance. So its like the blueprint of the house, which is then given a number for reference.

If you wanna get somewhere with this Python thing I suggest you read up on the subject. Every hour spent on study will end up saving you ten or a hundred hours of aimless bumbling around, depending on how much scripting you intend to do. You might also wanna check out my ow tutorial.
 
You're still some way from understanding how the API works, this is obvious. So you're not quite ready to do these things.

Whoa, there, no need to start making these sorts of assumptions before asking for some advice. I have used the API to find functions before, including a couple for the rest of what I'm doing with this one, which typically works just fine. If you want to suggest the tutorial, go ahead, but making assumptions about what I've done before is a bit much.

This is probably what you wanna do, then. It requires you to know the Player ID defined as ePlayer:
PHP:
iChange = 100
pPlayer = gc.getPlayer(ePlayer) # fetches a CyPlayer instance with CyGlobalContext.getPlayer()
eTeam = pPlayer.getTeam() # fetches the team ID with CyPlayer.getTeam()
pTeam = gc.getTeam(eTeam) # fetches a CyTeam instance with CyGlobalContext.getTeam()
eTech = pPlayer.getCurrentResearch() # fetches the tech ID with CyPlayer.getCurrentReseach()
pTeam.changeResearchProgress(eTech, iChange, ePlayer)
Note that I use the e prefix for the IDs instead of i, but the variables are still basically integers. You can of course use whatever variables names you like.

This exact didn't function didn't work (another name was needed instead of ePlayer), but something very similar did.
 
Whoa, there, no need to start making these sorts of assumptions before asking for some advice.
I meant no disrespect, but figuring out all these player values is key to working the API. It was very confusing to me also, and it took some effort to sort it out, once and for all. Just guessing and doing it by trial-and-error wasn't really working for either.

This exact didn't function didn't work (another name was needed instead of ePlayer), but something very similar did.
And this proves my point. Because variable names are completely arbitrary. I actually made a point by not using iPlayer as the player ID/PlayerTypes value.
 
This exact didn't function didn't work (another name was needed instead of ePlayer), but something very similar did.

What exactly happened?

I meant no disrespect, but figuring out all these player values is key to working the API. It was very confusing to me also, and it took some effort to sort it out, once and for all. Just guessing and doing it by trial-and-error wasn't really working for either.

Different people, different styles.
I always do trial and error at the beginning, and it works in most times.
 
What exactly happened?
He probably copy pasted the sample code I posted. I had rigged it up so that it wouldn't work without him changing the variable name for the PlayerTypes value.

So the interpreter didn't recognize the name ePlayer. There's a lesson in there, in case anyone cares to learn.

Different people, different styles.
I always do trial and error at the beginning, and it works in most times.
What I mean is that there is a difference between a class instance and the index number of said instances. The difference is like between actual cars and their license plates numbers.

I don't care what "style" anybody adheres to, but you still need to realize how the API is read before you can use it in an efficient manner. Before you do that, you are going to waste countless hours on said trial-and-error. I did. You did. The original poster is doing just that.
 
What exactly happened?

The function has iPlayer as an input rather than ePlayer, so the research part of it uses gc.getPlayer(iPlayer) rather than ePlayer.


Different people, different styles.
I always do trial and error at the beginning, and it works in most times.

This has been true for me as well, I have tried a few times reading about the language, but it doesn't make much sense before fooling around with some actual game functions, where I tend to pick up the patterns more easily.

He probably copy pasted the sample code I posted. I had rigged it up so that it wouldn't work without him changing the variable name for the PlayerTypes value.

So the interpreter didn't recognize the name ePlayer. There's a lesson in there, in case anyone cares to learn.

What I mean is that there is a difference between a class instance and the index number of said instances. The difference is like between actual cars and their license plates numbers.

I don't care what "style" anybody adheres to, but you still need to realize how the API is read before you can use it in an efficient manner. Before you do that, you are going to waste countless hours on said trial-and-error. I did. You did. The original poster is doing just that.

If you actually wish to be useful helping people out, never offer any advice in the future. (You're on ignore now as well.)
 
The function has iPlayer as an input rather than ePlayer, so the research part of it uses gc.getPlayer(iPlayer) rather than ePlayer.
You're still not getting the point. "iPlayer", "ePlayer", whatever is just an arbitrary name. It has nothing to do with how the API itself works.

This has been true for me as well, I have tried a few times reading about the language, but it doesn't make much sense before fooling around with some actual game functions, where I tend to pick up the patterns more easily.
Try understanding the API.

If you actually wish to be useful helping people out, never offer any advice in the future. (You're on ignore now as well.)
Bummer. Because I can totally help you figure out the difference between the various values. But I guess you rather ask for help where you could just learn how to do it yourself?
 
The function has iPlayer as an input rather than ePlayer, so the research part of it uses gc.getPlayer(iPlayer) rather than ePlayer.

No it doesn't. It takes an integer. Any integer. It doesn't matter what you call it. "iPlayer" is just the name of a variable. So is "ePlayer". You could just as easily call it "Fred" or "theSlayerOfWombatsOnAlternateTuesdays". It doesn't matter what it is called as long as you always call it the same thing when using the value that it represents. That was, in fact, his point. Since you evidently don't know this, he was obviously correct that you are a newbie programmer. There is nothing wrong with that - everybody starts out that way. The question is, when will you move past that stage and how much time will you waste doing things the hard way before then?

If you actually wish to be useful helping people out, never offer any advice in the future. (You're on ignore now as well.)

That's silly. He is one of the most active people here when it comes to helping people with their Python problems. He may be a bit insistent that people should learn how to do things rather than just stumble around using cut'n'paste and trial and error, but nobody is perfect (and he is apparently Swedish, in which case English isn't his first language - whatever tone you are reading into his messages may not be what he intended, which can be true even for people who do speak the language natively). He is also correct that if you know how Python, and programming in general, works then you will waste a lot less time trying to get it to do what you want. It's the trade-off of spending a few hours learning things now to save a few dozen hours later. It may slow you down at first, but it can save you a lot of time later - and it might not even really slow you down since it can result in you finishing that first project sooner even though you spent some time learning about programming in Python. It depends on how much programming is necessary in that first project. If it is a lot, or perhaps even a "medium" amount, then you can see the net saving of time in that first project and not have to wait until later for that.
 
Thank you God-Emperor. I would like to take this opportunity to express my regret over the tone of my initial message. I'm truly sorry, especially since this is not the first time this has happened. Please keep pointing it out whenever I manage to let myself down.

And Swedish is only my second language. Making English my third. ;) Does that make Python my fourth? :lol:
 
No it doesn't. It takes an integer. Any integer. It doesn't matter what you call it. "iPlayer" is just the name of a variable. So is "ePlayer". You could just as easily call it "Fred" or "theSlayerOfWombatsOnAlternateTuesdays". It doesn't matter what it is called as long as you always call it the same thing when using the value that it represents. That was, in fact, his point. Since you evidently don't know this, he was obviously correct that you are a newbie programmer. There is nothing wrong with that - everybody starts out that way. The question is, when will you move past that stage and how much time will you waste doing things the hard way before then?

And this is an example of the pointless style of "help" that you guys seem to think your providing. The actual function I'm talking about that is using iPlayer is a doturn function, that as a whole was using iPlayer as an input. So, in the strictest sense, it could use any sort of name as an input, but for how the rest of the thing was written outside of the research part, iPlayer was the one to use. And apparently its impossibly to write this out without going on a big rant about what a waste of time it is (This is just my time, by the way, that I'm supposedly wasting, not just anyone else's.), without simply letting me figure out the learning process on my own.

That's silly. He is one of the most active people here when it comes to helping people with their Python problems. He may be a bit insistent that people should learn how to do things rather than just stumble around using cut'n'paste and trial and error, but nobody is perfect (and he is apparently Swedish, in which case English isn't his first language - whatever tone you are reading into his messages may not be what he intended, which can be true even for people who do speak the language natively). He is also correct that if you know how Python, and programming in general, works then you will waste a lot less time trying to get it to do what you want. It's the trade-off of spending a few hours learning things now to save a few dozen hours later. It may slow you down at first, but it can save you a lot of time later - and it might not even really slow you down since it can result in you finishing that first project sooner even though you spent some time learning about programming in Python. It depends on how much programming is necessary in that first project. If it is a lot, or perhaps even a "medium" amount, then you can see the net saving of time in that first project and not have to wait until later for that.

All this writing about how time might be saved be reading up a python description on the internet may or may not be true. However, to write up a set of code that's deliberately written wrong (as he described in the previous post), instead of simply describing out the functions is both insulting (for a number of reasons), and not very useful. (I'm presumably supposed to go on a search for why it doesn't work. Except that a more straightforward post would still have provided a link, plus a set of working code that I could use as an example, rather than one that doesn't work for reasons that might relate to an incorrect type of variable, or name, or missing bit of punctuation, who knows.). If this is the kind of advice I'm going to get, I'm not interested in using it, and the person giving it should really think through what they think they're doing.

(And, as mentioned previously, all of this seems to continually assume that I haven't figured some of this stuff out yet. both in the programming in college, and as I've done some modding over the past few months, I've noticed that trying to learn a language from scratch has been much harder than looking at previously done work, trying some things out, and going from there. If you think that things would be faster doing things a different way, that's your advice to give, but to talk down to someone else, or be extra confusing, just to try and push that method, is unhelpful and extra confusing as well.)
 
@Pickly - I don't know if it's a smart idea to get involved in this, but all Baldyr tried to do was help you with your problem. There's no need for all of this fuss.
 
The point I was trying to make, that is vital to understand, is that both iPlayer and ePlayer are variable names commonly used for PlayerTypes values (player IDs). Since these are represented by integer values in Python the dual naming convention becomes confusing. Because it makes sense to both call them iPlayer (as its an integer value) and ePlayer (as its an enumerated type inherited from the C++ code corresponding to a CvPlayer instance, which in turn is represented by a CyPlayer object in Python). If anything of this is still unclear you should probably ask someone (other than me) to clarify it for you. Because it would be very helpful to understand the whole context.

The same goes for TeamTypes values (team IDs), by the way. Which is at the heart of your actual problem.

The reason you, Pickly, were clearly way off-base was the fact that you were using the PyPlayer class (from the PyHelpers module)... Your sample code simply made no sense and led me to believe that you had no clue, what-so-ever. :rolleyes: Hence me trying to help out with more than just a copy-paste solution. But I do apologize for my bad manners, once again.
 
Back
Top Bottom