Function Returner

Gerikes

User of Run-on Sentences.
Joined
Jul 26, 2005
Messages
1,753
Location
Massachusetts
So, while fooling around with the options screen, I decided to make this mod. The idea is that you can type a python command into the box and get the results. I decided that since I haven't been able to find a way to open up an in-game python shell yet and that since I already had the text box working that I'd take the next step.

Primarily, it could be useful to other people, especially if their mods might involve needing to know the values of certain aspects of the game at various times, such as variables, which the screenshot attached shows an example of. Other things might be testing what functions in the api do, such as the setWinner() function.

I have to warn you, however, that the program runs by utilizing the eval() command. Basically, that means that anything you type in the box WILL be run without remorse. Hopefully, you know that this could be dangerous if a friend who has it in for you and some python knowledge jumped on the computer while Civ4 was running, but I think you should be okay. Besides, you probably can't do more damage then if you were to actually write a python script yourself, right? Just remember, don't blame me if you screw something up. :D

Function Returner (Note that the README is missing where to put the CvOptionsScreenCallbackInterface.py file. This goes in the "python\entrypoints" folder. Thanks kandolf :P)

Bugs:

Probably : o)

Fun functions:

Here are some functions I was able to have some fun with. Search the API for other good ones...

  • CyEngine().setUpdateRate(2) Doubles the "update rate" of the game, graphically. Makes pretty much everything graphically faster (notice I said "faster", not "smoother"). Not sure of any negative impact this may have other than having your battle scenes over in half a millisecond and such. You can set it higher than 2 also and get a more responsive game but without much in terms of animation. To set back to default, set to a rate of 1.
  • CyGame().setWinner(0,2) Win by Conquest Victory
  • CyGlobalContext().getPlayer(0).setGold(10000) Sets your treasury to have 10000 gold. :king:
 

Attachments

  • FunctionReturner.JPG
    FunctionReturner.JPG
    97.8 KB · Views: 183
WTH this is awesome?!!? very handy indeed. will save some ppl a lot of time.

very good job

btw. i can´t get it working.
placed *screen.py into "\Screens" and the *callback*.py into "\entrypoints\"
doesn´t appear in the options, i checked the file, loooks aiight.
 
Gr3yHound said:
btw. i can´t get it working.
placed *screen.py into "\Screens" and the *callback*.py into "\entrypoints\"
doesn´t appear in the options, i checked the file, loooks aiight.

Hmm... not sure. Here are the absolute paths on my computer, just for a doublecheck:

Code:
"C:\Documents and Settings\Gerikes\My Documents\My Games\Sid Meier's Civilization 4\CustomAssets\python\screens\CvOptionsScreen.py"

"C:\Documents and Settings\Gerikes\My Documents\My Games\Sid Meier's Civilization 4\CustomAssets\python\entrypoints\CvOptionsScreenCallbackInterface.py"
kandalf said:
Umm.. the readme doesn't say where to place CvOptionsScreenCallbackInterface.py

Really? Whoops :P

Sorry about that, kinda was jumping between things and I must've stopped mid-sentence. I do that sometimes, especially since...


In any case, I've updated the first post with the info. I probably won't upload a new file unless I ever make a new version, then I'll make sure to have that change.

Thanks for the catch.
 
Hey Gerikes, do you mind if I leave this little bit in my mod for debugging purposes? (So I dont have to remove it every time on release?) Im using it within a Debugging options tab for my realism mod, to turn on/off specific options (natural disasters, etc) but I have it there for testing.

Thanks and let me know!


-jaynus
jaynus@gmail.com
 
:goodjob:Three Thumbs Up!:goodjob:

:goodjob:

Moderator Note: Let's move this to Utilities please. :)
 
jaynus said:
Hey Gerikes, do you mind if I leave this little bit in my mod for debugging purposes? (So I dont have to remove it every time on release?) Im using it within a Debugging options tab for my realism mod, to turn on/off specific options (natural disasters, etc) but I have it there for testing.

Thanks and let me know!


-jaynus
jaynus@gmail.com

Sure, no problem. : o )


All I ask is that if anyone uses this for anything, that you might just drop a line to say how you're using it. If I see that a bunch of people are calling X method (such as getting or setting a variable in the VariableSystem) then I'll add a small panel that might have a place just to do that (so somone doesn't have to keep typing in "CyVariableSystem().getValueFloat" every time).
 
If you have the Cheat Code on you can hit some keyboard button to open up a Python Interpretter. Good Work, but not really needed. :)

Well, at least I read there was.

Edit: Yep, have Cheat Mod on start a game and hit [Shift] + [`] or [~] and you will open the Python interpreter, and all the stuff will work just like you have set up.
 
vbraun said:
If you have the Cheat Code on you can hit some keyboard button to open up a Python Interpretter. Good Work, but not really needed. :)

Well, at least I read there was.

Edit: Yep, have Cheat Mod on start a game and hit [Shift] + [`] or [~] and you will open the Python interpreter, and all the stuff will work just like you have set up.

I knew there was something, but I couldn't find it. Thanks for the heads up.

Edit: Funny though, I can't seem to get any commands to work it in. Even stuff like 4 + 1.. Now I know why...see Edit2..

Edit2: The in-game interpreter doesn't really seem to be an actual interpreter. It pretty much has some of the more important commands you'd use made into their own language that works as an easier to use interface to the underlying python commands. It's helpful for staying out of the nitty gritty of what class to call to set your gold, for example, but I think that's half the fun :P

Built-in command to set gold:
Player.setGold 0,500

Actual interpreter call:
CyGlobalContext().getPlayer(0).setGold(500)

Obviously, you can save yourself some typing, but I'll stick with my mod for now. For one thing, the console's hard to read sometimes. I'm assuming that the console can't be modded, otherwise I'd just change that :P

(P.S. I do however love that the command line has a command called App.Crash....)




I think for the sake of argument they both have their pluses and minuses.
 
Back
Top Bottom