News UnrealEd Files Mods FragBU Liandri Archives
BeyondUnreal Forums

Go Back   BeyondUnreal Forums > Unreal Development > Coding

Reply
 
Thread Tools Display Modes
Old 27th Aug 2010, 08:22 AM   #1
Superbabs84321
Registered User
 
Join Date: Oct. 19th, 2009
Posts: 24
Altering MessageTrigger to write Message to Log

To get some statistics (for a single player level) I'd like to alter my MessageTrigger to write the Messages to a Log File (.txt) instead of dumping them on the screen. I slightly altered the MessageTrigger code, but I can't get my trigger to open a log file. Most probably I can't seem to figure to which class the logfile should be appointed to. Here is my code. I have highlighted my changes. Anyone got any advice?

Code:
class MessageTrigger extends Triggers;

var()	enum EMT_MessageType
{
	EMT_Default,
	EMT_CriticalEvent,
	EMT_DeathMessage,
	EMT_Say,
	EMT_TeamSay,
	EMT_WriteToLog
} MessageType;

var() localized string	Message;

var() byte		Team;


event Trigger( Actor Other, Pawn EventInstigator )
{
	local name		MSGType;
	local Controller	C;
	local PlayerController	P;

	switch ( MessageType )
	{
		case EMT_CriticalEvent	: MSGType = 'CriticalEvent';		break;
		case EMT_DeathMessage	: MSGType = 'xDeathMessage';		break;
		case EMT_Say		: MSGType = 'SayMessagePlus';		break;
		case EMT_TeamSay	: MSGType = 'TeamSayMessagePlus';	break;
		case EMT_WriteToLog	: MSGType = 'WriteToLog';			break;
		default			: MSGType = 'StringMessagePlus';	break;
	}

	for ( C=Level.ControllerList; C!=None; C=C.NextController )
	{
		P = PlayerController(C);
		if ( P != None && CheckTeam(P) )
		{
			if (MSGType == 'WriteToLog')
			{
				OpenLog('test');
				Logf(Message);
				CloseLog();
			}    
			else
			{
				P.TeamMessage(C.PlayerReplicationInfo, Message, MSGType);
			}
		}
	}
}
Here is the FileLog from wiki:
http://wiki.beyondunreal.com/UE2:FileLog_(UT2004)

Last edited by Superbabs84321; 27th Aug 2010 at 08:24 AM.
Superbabs84321 is offline   Reply With Quote
Old 27th Aug 2010, 04:09 PM   #2
brold9999
Registered User
 
Join Date: Apr. 5th, 2009
Posts: 142
Firstly, do not alter default packages. Create a new subclass instead of editing the existing MessageTrigger.

Secondly, you have to spawn a FileLog, and call the OpenLog, Logf, and CloseLog on it; the functions aren't visible from the MessageTrigger class.

eg

Code:
local FileLog logObject;

logObject = spawn(class'FileLog');
logObject.openLog(filename);
logObject.logf(message);
logObject.closeLog();
logObject.destroy();
Depending on your purposes, you may want to keep the FileLog around for future writes instead of closing and destroying it immediately.

Also, you may want to move the code that does it outside the loop, else it will write to the log once for each person on the player's team.
brold9999 is offline   Reply With Quote
Old 30th Aug 2010, 05:02 AM   #3
Superbabs84321
Registered User
 
Join Date: Oct. 19th, 2009
Posts: 24
Quote:
Originally Posted by brold9999 View Post
Firstly, do not alter default packages. Create a new subclass instead of editing the existing MessageTrigger.
Yes, I know it's kinda sloppy but this level is for a research project so it's not supposed to be distributed or something.

Quote:
Originally Posted by brold9999 View Post
Secondly, you have to spawn a FileLog, and call the OpenLog, Logf, and CloseLog on it; the functions aren't visible from the MessageTrigger class.
Yes, I was already expecting that I had to construct some entity like that but I didn't know how (I only got some experience with Java) and I didn't know which class to call.

Quote:
eg

Code:
local FileLog logObject;

logObject = spawn(class'FileLog');
logObject.openLog(filename);
logObject.logf(message);
logObject.closeLog();
logObject.destroy();
Thanks! That works!

Quote:
Originally Posted by brold9999 View Post
Depending on your purposes, you may want to keep the FileLog around for future writes instead of closing and destroying it immediately.
You are very right. That would be quite a bit more elegant, but I am not looking for elegant or robust code. I just want it to work with the least amount of effort.

Quote:
Originally Posted by brold9999 View Post
Also, you may want to move the code that does it outside the loop, else it will write to the log once for each person on the player's team.
THe level is only singleplayer but did so nonetheless.

Thank you very much for your help so far. The code works!

PS

I'd like to print also the levelname and the current time (either the gametime, the runtime, or the systemtime will do) together with the message, but I am not sure yet how I access these (wiki says they should be in the LevelInfo). If you got a suggestion...
Superbabs84321 is offline   Reply With Quote
Old 30th Aug 2010, 05:39 AM   #4
Wormbo
 
Wormbo's Avatar
 
Join Date: Jun. 4th, 2001
Location: Germany
Posts: 5,774
Quote:
Originally Posted by Superbabs84321 View Post
Yes, I know it's kinda sloppy but this level is for a research project so it's not supposed to be distributed or something.
The "do not alter default packages" thing affects the game itself, not individual levels. Just by saving a stock package (even without actual modifications) you basically render your entire game useless for online play.
__________________
Wormbo's UT/UT2004/UT3 mods | YouTube channel | PlanetJailbreak/JDN | Unreal Wiki | Liandri Archives
Everything you ever wanted to know about replication| UnrealScript security considerations
<elmuerte> you shouldn't do all-nighters, it's a waste of time and effort
<TNSe> nono
<TNSe> its always funny to find code a week later you dont even remember writing
<Pfhoenix> what's worse is when you have a Star Wars moment
<Pfhoenix> "Luke! I am your code!" "No! Impossible! It can't be!"
Wormbo is offline   Reply With Quote
Old 30th Aug 2010, 05:48 AM   #5
Superbabs84321
Registered User
 
Join Date: Oct. 19th, 2009
Posts: 24
Quote:
Originally Posted by Wormbo View Post
The "do not alter default packages" thing affects the game itself, not individual levels. Just by saving a stock package (even without actual modifications) you basically render your entire game useless for online play.
Perhaps I should have made myself more clear: Not only is the level only for research purposes, but the whole game installation. The computer isn't even connected to the internet.
Superbabs84321 is offline   Reply With Quote
Reply

Tags
log messagetrigger

Thread Tools
Display Modes

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

Forum Jump


All times are GMT -5. The time now is 07:12 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.

Copyright ©1998 - 2012, BeyondUnreal, Inc.
Privacy Policy | Terms of Use
Bandwidth provided by AtomicGamer