What's wrong with this code?

Thalassicus

Bytes and Nibblers
Joined
Nov 9, 2005
Messages
11,057
Location
Texas
The first test message displays, the second message (and lines following it) do not run:

Code:
for iXLoop in range(iPlotX - 2, iPlotX + 2):
    for iYLoop in range(iPlotY - 2, iPlotY + 2):
        CyInterface().addMessage(CyGame().getActivePlayer(), True, 10, "Testing Plot 1", None, 2, None, ColorTypes(8), 0, 0, False, False)
        pPlot = gc.getMap().getPlot(iXLoop, iYLoop)
        CyInterface().addMessage(CyGame().getActivePlayer(), True, 10, "Testing Plot 2", None, 2, None, ColorTypes(8), 0, 0, False, False)

Any idea what's wrong?
 
Well, firstly I've a feeling that the loop isn't what you want. The range function doesn't include the upper value, so range(0,5) would return 0,1,2,3,4. It'd have to be +3 instead.

Apart form that I can't see anything wrong. What does the log say?
 
The Great Apple said:
The range function doesn't include the upper value
Ah, a few other problems I was having make sense now. Strange that it does it that way...

The Great Apple said:
What does the log say?
It just shows "Testing Plot 1". No error messages or other text display, and the lines following this don't run.
 
Thalassicus said:
Ahh, a few other problems I was having make sense now :)


It just shows "Testing Plot 1". No error messages or other text display...and the lines following this don't run.

Gonne have to turn debug on and see what it reports.
 
(deleted, duplicate post)
 
Thalassicus said:
1) That's the same as cheat mode? I have that enabled.

2) How would I do that?

Use the following for your CivilizationIV.ini:

Code:
[GAME]

; Map Script file name
Map = Continents

; GameType options are singlePlayer/spLoad
GameType = singlePlayer

; Pitboss Turn Time
PitbossTurnTime = 0

; Max number of turns (0 for no turn limit)
MaxTurns = 0

; Handicap for quick play
QuickHandicap = HANDICAP_WARLORD

; GameSpeed options are GAMESPEED_QUICK/GAMESPEED_NORMAL/GAMESPEED_EPIC
GameSpeed = GAMESPEED_NORMAL

; Era options are ERA_ANCIENT/ERA_CLASSICAL/ERA_MEDIEVAL/ERA_RENAISSANCE/ERA_INDUSTRIAL/ERA_MODERN
Era = ERA_ANCIENT

; Sealevel options are SEALEVEL_LOW/SEALEVEL_MEDIUM/SEALEVEL_HIGH
SeaLevel = SEALEVEL_MEDIUM

; Climate options are CLIMATE_ARID/CLIMATE_TEMPERATE/CLIMATE_TROPICAL
Climate = CLIMATE_TEMPERATE

; Worldsize options are WORLDSIZE_DUEL/WORLDSIZE_TINY/WORLDSIZE_SMALL/WORLDSIZE_STANDARD/WORLDSIZE_LARGE/WORLDSIZE_HUGE
WorldSize = WORLDSIZE_STANDARD

; Game Name
GameName = Stalinbulldog

; Save Path - relative to working (Civ4) folder
FileName = 0

; Account Username
Nickname = Kael

; Email Address
Email = whatever

; In-game Alias
Alias = Kael

; Move along
CheatCode = 0

[CONFIG]

; Allow Camera Flying
AllowFlying = 0

; SMTP server login for Pitboss reminder emails
PitbossSMTPLogin = Derek

; SMTP server for Pitboss reminder emails
PitbossSMTPHost = mail

; Allows some memory savings *** ALT-TAB WILL NO LONGER FUNCTION ***
MemSaver = 0

; Use managed interface textures (may be safer but shouldn't be needed, uses more memory)
GUIManagedTextures = 0

; Disable caching of file system (may slow initialization)
DisableFileCaching = 1

; Disable caching of xml and file system (may slow initialization)
DisableCaching = 0

; Set to 1 to page units out when non-visible
DynamicUnitPaging = 1

; Set to 1 for no tech splash screens
NoTechSplash = 0

; The maximum number of autosaves kept in the directory before being deleted.
MaxAutoSaves = 5

; Don't show minimum specification warnings
HideMinSpecWarning = 0

; Number of seconds to accept live game list updates from GameSpy (-1 for initial snapshot only, 0 for no live updates
GameUpdateTime = 10

; Enable voice over IP capture and playback
EnableVoice = 1

; Disable PAK memory mapping (May affect performance)
DisablePAKMemoryMapping = 0

; Don't skip frames if falling behind
BinkNoSkip = 1

; Copy entire image each frame, not just dirty pixels
BinkCopyAll = 1

; Show movies using hi-color, not true-color (may be faster)
Bink16Bit = 0

; Copy ever other scanline during movie playback (faster)
BinkInterlace = 0

; Screenshot format (TGA,JPG,BMP)
ScreenShot Format = JPG

; Enable Trilinear Filtering for the Minimap
MinimapTrilinearFilter = 1

; Enable Tree Region Cutting
CutTrees = 1

; Enable Quick Slide Show Transitions
PopSlides = 0

; Random seed for map generation, or '0' for default
MapRandSeed = 0

; Random seed for game sync, or '0' for default
SyncRandSeed = 0

; Bandwidth options are modem or broadband
Bandwidth = broadband

; QuickStart - SinglePlayer games only!
QuickStart = 0

; Enable/disable background music
PlayMusic = 1

; Allow Screenshots. May affect performance on some video cards
AllowScreenShots = 1

; App Selects Specific IP to use for Multiplayer
SelectIP = 0

; Specify a Mod folder (Mods\Mesopotamia), '0' for none
Mod = 0

; Specify whether to play in fullscreen mode 0/1/ask
FullScreen = 1

; Set max frame rate clamp (0 means none)
SetMaxFrameRate = 0

; Set to 1 for dynamic animation paging
DynamicAnimPaging = 1

; Set to 1 for no in-game movies
NoMovies = 0

; Set to 1 for no python exception popups
HidePythonExceptions = 0

; Specify the number of turns between autoSaves.  0 means no autosave.
AutoSaveInterval = 4

; Enable Audio
AudioEnable = 1

; English(0),French(1),German(2),Italian(3),Spanish(4) - Defaults to user-installed language
Language = 0

; Determines which user profile is loaded on game start
UserProfile = Default Profile

; Sync input to smooth interface (may run slower)
SyncInput = 0

; Force numlock always on while playing
ForceNumlock = 0

[DEBUG]

; Create a dump file if the application crashes
GenerateCrashDumps = 0

; Number of turns to autorun before exit (0 for no limit)
AutorunTurnLimit = 0

; Set App on Auto-Run
Autorun = 0

; Enable D3D9 Queries
D3D9Query = 0

; 
ScreenHeight = 0

; Custom Screen Resolution, ex: 1200x1200 - Normal resolutions can be set in-game and will be used when both values are set to 0
ScreenWidth = 0

; Establish connection to Python Debugger
HAPDebugger = 0

; Show python debug msgs in IDE console
ShowPythonDebugMsgs = 1

; NetComm Port
Port = 2056

; Enable the logging system
LoggingEnabled = 1

; Overwrite old network and message logs
OverwriteLogs = 0

; Enable rand event logging
RandLog = 0

; Enable message logging
MessageLog = 1

; Break on memory allocation order #
BreakOnAlloc = -1
 
You'll probably want to edit that post so that it doesn't have your email in, or you might get quite some spam.

I think the important lines are:
Code:
HidePythonExceptions = 0
ShowPythonDebugMsgs = 1
LoggingEnabled = 1
MessageLog = 1
 
Thalassicus said:
Any idea what would cause this? Unless the API is in error...
API error most likely...

Checking GBM's slightly more reliable API shows that it is. Function should be just:

CyMap().plot(x,y)

This function is also listed in the other API.

BTW, GBM's API is here: http://sthurlow.com/cvDocs/cvDoc/CyMap.htm I prefer the interface of the other one, but if it fails you this one is more likely to give results.
 
The Great Apple said:
You'll probably want to edit that post so that it doesn't have your email in, or you might get quite some spam.

Thanks, I cleaned it up.
 
One more question: how do you create a unit? I tried the initUnit function listed in both API's:

CyUnit* initUnit(UnitTypes iIndex, plotX, plotY, UnitAITypes iIndex)

It returns an arguement mismatch with this code:

pCapturedUnit = playerX.initUnit(pLoser.getUnitType(), pWinner.getX(), pWinner.getY(), -1)

ArguementError: Python argument types in
CyPlayer.initUnit(CyPlayer, int, int, int, int)
did not match C++ signature:
initUnit(class CyPlayer {lvalue}, int, int, int, enum UnitAITypes)
 
Thalassicus said:
One more question: how do you create a unit? I tried the initUnit function listed in both API's:

CyUnit* initUnit(UnitTypes iIndex, plotX, plotY, UnitAITypes iIndex)

It returns an arguement mismatch with this code:

pCapturedUnit = playerX.initUnit(pLoser.getUnitType(), pWinner.getX(), pWinner.getY(), -1)

ArguementError: Python argument types in
CyPlayer.initUnit(CyPlayer, int, int, int, int)
did not match C++ signature:
initUnit(class CyPlayer {lvalue}, int, int, int, enum UnitAITypes)

Could this be caused by a change to that function in a recent patch? I searched in several of the main python files for an occurance of initUnit() to check for usage, without locating it.

Code:
newUnit = playerX.player.initUnit(pLoser.getUnitType(), pWinner.getX(), pWinner.getY(), UnitAITypes.NO_UNITAI)
 
A third question :)

In this code block, coastalPlots is a previously-defined list of CyPlot objects; I then remove plots from the list when visible to any player.

Code:
for pPlot in coastalPlots[:]:
    debugMessage = "A " + str(coastalPlots.count(pPlot))
    if coastalPlots.count(pPlot) == 0: CyInterface().addMessage(CyGame().getActivePlayer(), True, 10, tempMessage, None, 2, None, ColorTypes(7), 0, 0, False, False)
    for n in range(gc.getMAX_PLAYERS()):
        if (n != gc.getBARBARIAN_PLAYER()):
            if (pPlot.isVisible(gc.getPlayer(n).getTeam(), False) == True):
                debugMessage = "B " + str(coastalPlots.count(pPlot))
                if coastalPlots.count(pPlot) == 0: CyInterface().addMessage(CyGame().getActivePlayer(), True, 10, tempMessage, None, 2, None, ColorTypes(7), 0, 0, False, False)
                coastalPlots.remove(pPlot)

The problem is, somehow, the pPlot element doesn't always exist at the removal stage, with an accompanying "element does not exist in list" error. The debug message "A 0" never displays, but "B 0" sometimes does. How is this possible? Could the isVisible function be at fault?
 
Back
Top Bottom