Advertisement
Civilization Fanatics' Center  

Welcome to Civilization Fanatics' Center.

You are currently viewing our site as a guest which gives you limited access to our site features. By joining our free community, you will be able to participate in the discussions, search the forum, send private messages, vote in polls, upload your own screenshots to the gallery, and access many other special features. Registration is fast, simple and absolutely free, so sign up today! If you have any problems with the registration process or your account login, please contact support.

Go Back   Civilization Fanatics' Forums > CIVILIZATION IV > Civ4 - Creation & Customization > Civ4 - SDK/Python

Notices

Reply
 
Thread Tools
Old Mar 10, 2011, 06:47 PM   #1
civfan11596
Chieftain
 
Join Date: Feb 2011
Posts: 28
Forcing war via python

My goal was to be able to script when a civ would declare war on another civ fro my scenario mod I'm making. After looking through the API and some other mods for some guidance, I made this:

Code:
## Sid Meier's Civilization 4
## Copyright Firaxis Games 2005

from CvPythonExtensions import *


gc = CyGlobalContext()


def GRMNdowUSSR(): 
gc.getTeam(1).declareWar(0, false, WarPlanTypes.WARPLAN_TOTAL)
However, this isn't working. I've tried some other things but no luck there either. Any suggestions?

Last edited by civfan11596; Mar 11, 2011 at 04:10 PM.
civfan11596 is offline   Reply With Quote
Old Mar 10, 2011, 11:16 PM   #2
davidlallen
Deity
 
davidlallen's Avatar
 
Join Date: Apr 2008
Location: California
Posts: 4,727
Is GRMNdowUSSR() ever called by some other code you wrote?
__________________
Come see the Fury Road sub-forum! Everybody wants post-apocalyptic desert warfare with crossbows!
davidlallen is offline   Reply With Quote
Old Mar 10, 2011, 11:26 PM   #3
Baldyr
"Hit It"
 
Baldyr's Avatar
 
Join Date: Dec 2009
Location: Sweden
Posts: 5,530
I'm don't know if the sample code is complete or not, but what class instance is the name self referring to?

If you enable Python exceptions in CivilizationIV.ini you should be able to pinpoint the issue you're experiencing. Make sure pop-ups are enabled so that you can't miss it.
__________________
How to Make a Python Mod - Python modding tutorial
CivIV Python Class Reference - modding Python API
How to Think Like a Computer Scientist - online Python textbook
CivPlayer - Python scripting tool
Spoiler:
Q: Who is the woman in the avatar image?
A: Miss Li.
Q: Why does she have a brass-eye?
A: It's a conceptual thing. More of the same on the profile page.

Q: What does you title mean?
A: That is the title of Miss Li's latest single.
Baldyr is offline   Reply With Quote
Old Mar 11, 2011, 04:09 PM   #4
civfan11596
Chieftain
 
Join Date: Feb 2011
Posts: 28
I'm not getting any errors.

New Code:
Quote:
## Sid Meier's Civilization 4
## Copyright Firaxis Games 2005

from CvPythonExtensions import *


gc = CyGlobalContext()


def GRMNdowUSSR():
gc.getTeam(1).declareWar(0, false, WarPlanTypes.WARPLAN_TOTAL)
I don't understand why its not working..
in the API this is the entry for the declare war instance:
declareWar (TeamType eTeam, BOOL bNewDiplo, WarPlanType eWarPlan)
which is what I did besides adding the gc.getTeam(1)
civfan11596 is offline   Reply With Quote
Old Mar 11, 2011, 04:12 PM   #5
davidlallen
Deity
 
davidlallen's Avatar
 
Join Date: Apr 2008
Location: California
Posts: 4,727
I am not sure if you have done any programming in python before. You are declaring a function. You are never calling the function. You need to make sure that this function is called at some point when the game is running, for example during startplayerturn.
__________________
Come see the Fury Road sub-forum! Everybody wants post-apocalyptic desert warfare with crossbows!
davidlallen is offline   Reply With Quote
Old Mar 11, 2011, 04:34 PM   #6
civfan11596
Chieftain
 
Join Date: Feb 2011
Posts: 28
Quote:
Originally Posted by davidlallen View Post
I am not sure if you have done any programming in python before. You are declaring a function. You are never calling the function. You need to make sure that this function is called at some point when the game is running, for example during startplayerturn.
Right now I'm just starting the game, going into the python console and hitting "import War" (no quotations) into the console I know how to call the function, I just haven't. Does this effect it?
civfan11596 is offline   Reply With Quote
Old Mar 12, 2011, 12:48 PM   #7
davidlallen
Deity
 
davidlallen's Avatar
 
Join Date: Apr 2008
Location: California
Posts: 4,727
Sorry, let me make sure I understand. You define a function. You import the function. You never call the function. And you don't understand why the function effect does not happen. Is there a part I am missing?

*Does anything happen when you call the function?*
__________________
Come see the Fury Road sub-forum! Everybody wants post-apocalyptic desert warfare with crossbows!
davidlallen is offline   Reply With Quote
Old Mar 12, 2011, 01:27 PM   #8
civfan11596
Chieftain
 
Join Date: Feb 2011
Posts: 28
Quote:
Originally Posted by davidlallen View Post
Sorry, let me make sure I understand. You define a function. You import the function. You never call the function. And you don't understand why the function effect does not happen. Is there a part I am missing?

*Does anything happen when you call the function?*
Yeah, basically. I could make a call, but isn't importing it the same thing? (I understand calls though, I just want to make sure it works before I make one.)
Let me try.

edit***
Nothing. Here's the entry in the Event Manager

Code:
def onBeginGameTurn(self, argsList):
        'Called at the beginning of the end of each turn'
        iGameTurn = argsList[0]
        CvTopCivs.CvTopCivs().turnChecker(iGameTurn)
        ###Downfall
        if iGameTurn == 10:
           War.GRMNdowUSSR

Last edited by civfan11596; Mar 12, 2011 at 01:32 PM.
civfan11596 is offline   Reply With Quote
Old Mar 12, 2011, 02:14 PM   #9
Baldyr
"Hit It"
 
Baldyr's Avatar
 
Join Date: Dec 2009
Location: Sweden
Posts: 5,530
This isn't a function call:
Code:
War.GRMNdowUSSR
Its just a reference to a name - the name of the function. A function call has parenthesis with the arguments (in this case none):
Code:
War.GRMNdowUSSR()
__________________
How to Make a Python Mod - Python modding tutorial
CivIV Python Class Reference - modding Python API
How to Think Like a Computer Scientist - online Python textbook
CivPlayer - Python scripting tool
Spoiler:
Q: Who is the woman in the avatar image?
A: Miss Li.
Q: Why does she have a brass-eye?
A: It's a conceptual thing. More of the same on the profile page.

Q: What does you title mean?
A: That is the title of Miss Li's latest single.
Baldyr is offline   Reply With Quote
Old Mar 12, 2011, 02:30 PM   #10
civfan11596
Chieftain
 
Join Date: Feb 2011
Posts: 28
Move

Quote:
Originally Posted by Baldyr View Post
This isn't a function call:
Code:
War.GRMNdowUSSR
Its just a reference to a name - the name of the function. A function call has parenthesis with the arguments (in this case none):
Code:
War.GRMNdowUSSR()
I have that, I just forgot to copy it :P
civfan11596 is offline   Reply With Quote
Old Mar 12, 2011, 05:48 PM   #11
The_J
Say No 2 Net Validations

 
The_J's Avatar
 
Join Date: Oct 2008
Location: Germany / Netherlands
Posts: 24,864
Images: 51
Are the python exceptions enabled?
__________________
Civ4-BtS-Mod "Mars, Now!"


Steam eats the souls of little gamers!!!
The_J is offline   Reply With Quote
Reply

Bookmarks

Go Back Civilization Fanatics' Forums > CIVILIZATION IV > Civ4 - Creation & Customization > Civ4 - SDK/Python > Forcing war via python

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Advertisement

All times are GMT -6. The time now is 03:10 PM.


Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
This site is copyright © Civilization Fanatics' Center.
Support CFC: Amazon.com | Amazon UK | Amazon DE | Amazon CA | Amazon FR