Question Time! Python related

mrkingkong

Young Padawan
Joined
Apr 19, 2005
Messages
350
Location
Between fantasy and reality
Okay, can anyone tell me why this bit of code is not working as it should?

PHP:
def onLoadGame (self, argslist):
         CyInterface().addImmediateMessage("Welcome back!","")

         return 0

Intended use: to create a welcome back message to be displayed after the user loads up the game

Actual effects: well, nothing as far as i can tell

This is my first foray into Python, and i thought i would start nice and simple. I have put this after def onLoadGame section of the CvEventManager.py.

Please help

mrkingkong
 
Edit: I compared CyInterface to CyGInterfaceScreen, but after having a look at my own mod, I found out that they behave differently and my original message is a huge pile of **** :)

Why not use CvUtil.pyPrint("Welcome back") instead?
 
mrkingkong said:
Okay, can anyone tell me why this bit of code is not working as it should?

PHP:
def onLoadGame (self, argslist):
         CyInterface().addImmediateMessage("Welcome back!","")

         return 0

Intended use: to create a welcome back message to be displayed after the user loads up the game

Actual effects: well, nothing as far as i can tell

This is my first foray into Python, and i thought i would start nice and simple. I have put this after def onLoadGame section of the CvEventManager.py.

Please help

mrkingkong

A few reasons why I think it might not be doing anything:

1.) You have the python file in the wrong spot (for example, in "assets" rather than "assets/python". It's a simple mistake that happens often.
2.) Perhaps the command is working, but the message that's on screen (since it only stays on screen for 10 seconds) has already disappeared before the loading screen falls away and the main screen comes back up.

You might also want to try putting a CvUtil.pyPrint("Hello world!") or something to that affect in that function, then check your log files (make sure python logging is enabled in the ini) for that message. If it's not there then you might have the file misplaced.
 
I hate addImmediateMessage. My first attempts at Civ4 pythoning started by making a method to pemit values to the civ screen. I fought with method for hours and could not get it to work, always somthing about it not getting the right c++ arguments.

I've sense messed with it a few more times and still with no success. I sugget useing the somewhat longer method CyInterface().addMessage.

As an example
Code:
def alertPlayer(iPlayer, message, iColor = 7):

        pPlayer = gc.getPlayer(iPlayer)

        # Return immediately if the player passed in is invalid
	if(pPlayer == None):
		return None
			
	# Return immediately if the player passed in is invalid
	if(pPlayer.isNone()):
		return None

        # If the player isn't human then no need to send a message
        if (not pPlayer.isHuman()):
                return None

        eventMessageTimeLong = gc.getDefineINT("EVENT_MESSAGE_TIME_LONG")
        szIcon = None
        iFlashX = 0
        iFlashY = 0

        szString = str(message)

        CyInterface().addMessage(iPlayer, True, eventMessageTimeLong,
                                 szString, None, 0, szIcon, ColorTypes(iColor),
                                 iFlashX, iFlashY, True, True)

It may seem a little complex at first, but most of that is checking to see if the message is going to a valid player.

To use this to show a message you would just use somthing like this

Code:
alertPlayer(0, "Hello world.")

to show the words Hello world. on the first player's (player 0 is the first player) screen and also in the ingame event log, so if you miss it on the screen you can still see it without having to alt tab to the log files. :)
 
Gerikes said:
2.) Perhaps the command is working, but the message that's on screen (since it only stays on screen for 10 seconds) has already disappeared before the loading screen falls away and the main screen comes back up.

A further question about this (as i suspected the "mrkingkong joins the game" message might well be in the way of my message).

Where is this line of code that displays this message?
And how would i delay my message being displayed for about ten seconds, if this is the case?

Thank you all for the replies, i never knew there were so many ways to add a message to the screen in Civ! :eek:

@Jeckel: the first block of code- is this a new function you have created?or is it already in existence somewhere? And finally (:rolleyes: ), in which files do you create new functions? As in CvUtil, CvDefineEditor,CvEventManager, etc??

Thanks to all who helped/are helping

mrkingkong
 
Back
Top Bottom