Go Back   Steam Users' Forums > Steam Tool Discussions > Source Coding

Reply
 
Thread Tools Display Modes
Old 10-10-2009, 05:59 AM   #1
fcIndigo
 
Guest
Posts: n/a
Msg(), DevMsg() and Warning()

Hello,

I am trying to learn coding with the SDK. So I started reading some articles at the valve developer wiki, and stumbled across the 'Your First Entity' tutorials.
After reading these carefully and hacking the code into VS 2008, I compiled and tested the logical entity as well as the model entity these tutorials describe. After creating the necessary .fgd file and placing the newly created entities into a map, using hammer, I went in-mod to test. Everything went fine so far, both entities were working nicely in-game/in-mod.

Now I tried adding some console output to the logical entity, on it's Tick() Input, using Msg() DevMsg() and Warning(). ( Like described at the 'Developer Console Control' wiki entry. )
Somehow the output won't show in game tho, although the Tick() input gets fired, and now I'm pretty clueless why it won't print to console. Same with the 'model entity', when I add Msg() DevMsg() or Warning(), there is no output to the in-game console.
So the following might sound like stupid questions though, and I am aware that I need to read and learn way more. Any links to more tutorials or SDK API/functions/classes overviews are welcome!

Doesn't the output get printed to console because the class is not networked? Did I miss including some header that is required for console output?


On that subject, I noticed that when I #include some garbage header file name, and the file doesn't exist, VS2008 doesn't give me any warnings about the missing header file on compilation. I'm used to gcc, so I kind of expected to be warned about missing files, but VS2008 compiled the mod just fine, even though the header file I tried including didn't even exist.

I am aware that DevMsg() wouldn't output to the console unless I enable developer mode. However, Msg() and Warning() should print to console even without developer mode enabled. When I add them to other files that are already part of the SDK, the output to console just works fine. But not with the files I generated as described at the tutorials I mentioned above.

So any hints how I could get console output in my custom files to work, and why VS2008 doesn't report missing files, or links to further tutorials will be highly appreciated.

With Best Regards.


P.S: I append my code here, so you can compare what I'm trying. I even tried getting console output with UTIL_ClientPrintFilter(), see below.
Still, I don't get anything printed to the in game console.

Code:
#include "cbase.h"
#include "sdk_gamerules.h"
#include <thisfiledoesnotexist.h>


class CMyLogicalEntity : public CLogicalEntity
{
public:
	DECLARE_CLASS(CMyLogicalEntity, CLogicalEntity);

	DECLARE_DATADESC();

	// Constructor
	CMyLogicalEntity()
	{
		m_nCounter = 0; 
	}

	// Input Function
	void InputTick(inputdata_t &inputData);

private:
	int m_nThreshold;
	int m_nCounter;

	COutputEvent m_OnThreshold;


};

LINK_ENTITY_TO_CLASS(my_logical_entity, CMyLogicalEntity);

BEGIN_DATADESC(CMyLogicalEntity)
	DEFINE_FIELD(m_nCounter, FIELD_INTEGER),
	DEFINE_KEYFIELD(m_nThreshold, FIELD_INTEGER, "threshold"), 
	DEFINE_INPUTFUNC(FIELD_VOID, "Tick", InputTick),
	DEFINE_OUTPUT(m_OnThreshold, "OnThreshold"),
END_DATADESC()

void CMyLogicalEntity::InputTick(inputdata_t &inputData)
{
	m_nCounter++;
	Msg("Tick!\n");
	DevMsg("Tick!\n");
	Warning("Tick!\n");
	Msg("Tick! Counter is %i\n", m_nCounter);
	DevMsg(1, "Tick! Counter is %i\n", m_nCounter);
	Warning("Tick! Counter is %i\n", m_nCounter);

	CRecipient filter;
	filter.Addrecipient(this);
	filter.MakeReliable();

	Q_snprintf(sz_text, sizeof(sz_text), "Tick! Counter is %i\n", m_nCounter);
	UTIL_ClientPrintFilter(filter, HUD_PRINTCONSOLE, sz_text);

	if(m_nCounter >= m_nThreshold)
	{
		m_OnThreshold.FireOutput(inputData.pActivator, this);
		m_nCounter = 0;
	}
}
 
Reply With Quote
Old 10-10-2009, 06:59 AM   #2
Varsity
 
Join Date: Jun 2004
Reputation: 489
Posts: 17,359
Very strange, there's nothing wrong with your code. It's as simple as Msg( "Hello\n").

Are you 100% sure the function is actually being called? Try placing a breakpoint.
Varsity is offline   Reply With Quote
Old 10-10-2009, 09:23 AM   #3
fcIndigo
 
Guest
Posts: n/a
Here is what I've done to the logic_entity:

created a logic_timer that fires an output ("OnTimer" "my1,Tick,,1,-1") every second to the logic_entity, so that should be increasing the tick count.
The logic_entity has the "OnThreshold" output, so when a given amount of "ticks" occurred it fires that output.
I linked that to a game_text, which clearly shows up in-game then.
Furthermore I made the "OnThreshold" output fire at the other tutorial entity, the model_entity one, so this receives it's "Toggle" input then.
In other words, each time the logic_entity hits it's maximum threshold, the model_entity either starts or stops moving. This seems to work perfectly well, the model_entity starts moving every 5 seconds, then stops for 5, then starts moving again for 5 seconds.

So I'm 99% sure the Tick() I placed the Msg() into is being called, unless there is some really weird things happening I can't have any clue about.

I'll try placing a breakpoint now tho, to make 100% sure Tick() is being called.

I am half-way convinced that it's got something to do with missing headers, and VC2008 not giving errors about missing files. Notice that one header file I tried including in above code, <thisfiledoesnotexist.h> - this file does not exist, as the name is suggesting. xD
  Reply With Quote
Old 10-10-2009, 11:41 AM   #4
Winston
 
Join Date: Jul 2007
Reputation: 84
Posts: 2,170
Quote:
Originally Posted by fcIndigo View Post
Notice that one header file I tried including in above code, <thisfiledoesnotexist.h> - this file does not exist, as the name is suggesting. xD
Are you sure that's compiling?
I get
Code:
fatal error C1083: Cannot open include file: 'thisfiledoesnotexist.h': No such file or directory
when I do that.
Winston is offline   Reply With Quote
Old 10-10-2009, 01:37 PM   #5
fcIndigo
 
Guest
Posts: n/a
oh yes, I am absolutely sure it's compiling under VS 2008.
I cleaned and rebuild the project several times now, and all other changes I did to some files seem to work fine when trying in-game.

Furthermore I even manually deleted client.dll and server.dll from the mod's folder, and compiled again, and the 2 files automatically got copied there after compiling.

Oh, and the 2 entities are working in-game, like I said above. So that's another sign my code really compiled, even with the invalid header #include.
What's still not working is the Msg() console output. -.-

This really left me puzzled, I am used to gcc and being prompted about missing files. So I assume it's some VS 2008 setting I am missing here, like some "Do-what-I-want-policy".
I tried disabling the usage of pre-compiled headers in the project's options btw, didn't help.
  Reply With Quote
Old 10-10-2009, 02:44 PM   #6
Varsity
 
Join Date: Jun 2004
Reputation: 489
Posts: 17,359
There is no special configuration required. Msg() and all that is provided by cbase.h.

Did the breakpoint hit?
Varsity is offline   Reply With Quote
Old 10-11-2009, 02:31 AM   #7
Winston
 
Join Date: Jul 2007
Reputation: 84
Posts: 2,170
There is no "ignore missing headers" option in VS that I am aware of. Is this file definately part of the project, and is set to be compiled rather than to be ignored? I have never heard of the compiler ignoring a missing header, this should generate an error and stop it from being able to begin processing the rest of the file...

It strikes me that it might even be the case (never checked) that the My First Entities tutorial entities might already be in the code, hence they would work whatever you do with VS. Try putting Msg("blah\n"); in CHL2MP_Player::PostThink. (or CSDK_Player::PostThink if using scratch, or CHL2_Player::PostThink if using single player).

If that doesn't show up in the console... I'd be pretty certain its not compiling the dll. If it does, I'd guess that its just not compiling your logical entity file.
Winston is offline   Reply With Quote
Old 10-11-2009, 06:25 AM   #8
fcIndigo
 
Guest
Posts: n/a
*EDIT*
After digging some more into that subject, and starting a windows search on my project, for all files that have "my_logical_entity" in them, I discovered that Winston was right. The SDK really already has the tutorial entities in it. I can't tell how stupid I feel now. There is no way I could have expected those tutorial entities are already part of the SDK, I would have never guessed so.
I deleted those from the project now, and look, I finally get the desired error message about the missing header. Hooray! xD
Finally I can continue getting used to the SDK more, by adding stuffs.
So thanks a lot Winston for pointing me to that, and also thanks to Varsity for his suggestions.
*/EDIT*


Hello,

took me quite some time to get the debug build to work.
The breakpoint I set on my logical entity, at it's void CMyLogicalEntity::InputTick(inputdata_t &inputData) function does hit.
Not after I right clicked the breakpoint tho, chose "storage location" and checked "Allow differences between source code and original version".
I am using a translated version of VS2008, so these might not be the exact translations for english versions. I know this isn't really helpful.

I noticed I get some warnings about missing debug symbols.
The Installing and Debugging the Source Code article at the valve developer wiki suggests this can be ignored tho.
(3. If you get a warning that hl2.exe has no debugging information, ignore it.)

Point blank, the breakpoint hits every time the Tick() function of the logical entity I added receives an input.

Afterwards I tried what Winston suggested, and placed a Msg() into sdk_player.cpp :
Code:
void CSDKPlayer::PostThink()
{
	Msg("CSDKPlayer::PostThink()\n");
...
This gets printed to console just fine, several thousands of times. As expected I guess.

Now, I did a full search on "my_logical_entity" throughout all included files. The only occurrences of that string are in the file I created. If the tutorial entities are already part of the sdk, they would be named "my_logical_entity" as well, the exact same name as in the .fgd file, right?
Otherwise Hammer wouldn't know what entity to use I guess.

The more I look into this, the more I am convinced the cause of this very weird behavior I am facing is nothing a beginner like me can deal with. Might be my copy of the SDK is somehow garbled. Might be VS2008 just doesn't work too good with compiling the SDK. Might be anything else I can't think of.
So I probably better become more experienced with VS2008 and the valve SDK first, before looking into this again.

Thanks for all your help and suggestions!

Last edited by fcIndigo: 10-11-2009 at 08:15 AM.
  Reply With Quote
Old 10-11-2009, 02:45 PM   #9
Varsity
 
Join Date: Jun 2004
Reputation: 489
Posts: 17,359
I'm surprised that the project compiled with two identical classes. Surely that would lead to redefinition errors? We should also change the pages to tell people to remove the pre-existing entity...
Varsity is offline   Reply With Quote
Old 10-24-2009, 11:53 AM   #10
christianclavet
 
Guest
Posts: n/a
Thanks. That fixed my problem also. I didnt had any MSG coming out. Now it's working.
  Reply With Quote
Reply

Go Back   Steam Users' Forums > Steam Tool Discussions > Source Coding


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



All times are GMT -7. The time now is 02:42 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site Content Copyright Valve Corporation 1998-2014, All Rights Reserved.