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

Reply
 
Thread Tools Display Modes
Old 05-02-2012, 04:08 AM   #1
ChadReitsma
 
Join Date: Feb 2012
Reputation: 4
Posts: 91
Accessing a Vector generated inside a Con_command

Hey all,
Was wondering if someone could help me out here...

I've got a CON_COMMAND inside of Player.cpp, it takes a vector that is passed from the client...

Here's the code I have:
Code:
CON_COMMAND(MyCommand, "Retrieval of client commands...")
{

	Vector tempAng;
	tempAng.x = atof(args.Arg(1));
	tempAng.y = atof(args.Arg(2));
	tempAng.z = atof(args.Arg(3));
	
	
	return;
	
};
This works great, but I need to Access tempAng in another file... I've tried using a gpGlobals and failed, and I've also tried using extern declarations but i think I'm doing it wrong...

Could anyone give me a simple example of how to do this?
I really appreciate the help!

Thanks,
C

Last edited by ChadReitsma: 05-03-2012 at 02:35 AM.
ChadReitsma is offline  
Reply With Quote
Old 05-02-2012, 03:57 PM   #2
IBeMad
 
 
 
Join Date: Jan 2011
Reputation: 1
Posts: 116
Without knowing what the rest of the code looks like: here's the simplest answer:

Code:
Vector g_vecTempAng;
CON_COMMAND(MyCommand, "Retrieval of client commands...")
{
	g_vecTempAng.x = atof(args.Arg(1));
	g_vecTempAng.y = atof(args.Arg(2));
	g_vecTempAng.z = atof(args.Arg(3));	
};
Then, where you want to use this variable, use
Code:
extern Vector g_vecTempAng;
outside of a function.

Note that using global variables in this way is considered very bad practice, and if you have the ability to access this instance of the player class from your "other file", you should instead make vecTempAng a member variable (put it in the .h file).
IBeMad is offline   Reply With Quote
Old 05-02-2012, 04:21 PM   #3
ChadReitsma
 
Join Date: Feb 2012
Reputation: 4
Posts: 91
Awesome, thank-you Mad!
I'll try it out right now.


Edited:
Couldn't get it to Build on the Client side because it says:
:: unresolved external symbol "class Vector g_vecTempAng"

I guess I'll have to figure out a better way, I'm trying access that variable inside of a SharedFile, so it builds fine in the Server Solution (because we declared it in player.cpp), but when I try to Build the Client Solution it can't find that variable... is there a way to make this work?

Last edited by ChadReitsma: 05-02-2012 at 04:41 PM.
ChadReitsma is offline   Reply With Quote
Old 05-02-2012, 04:52 PM   #4
ChadReitsma
 
Join Date: Feb 2012
Reputation: 4
Posts: 91
Ok, I changed the name of it, and added it to Player.h like this:
Code:
Vector g_vecFiringAng;
And I changed the con_command to this: (sorry if this is bad!) I'm a Php guy...

Code:
CBasePlayer *pPlayerTemp;
CON_COMMAND(MyCommand, "Retrieval of client commands...")
{

	pPlayerTemp->g_vecFiringAng.x = atof(args.Arg(1));
	pPlayerTemp->g_vecFiringAng.y = atof(args.Arg(2));
	pPlayerTemp->g_vecFiringAng.z = atof(args.Arg(3));	

};
When I start to type the -> I can see that g_vecFiringAng is available. So that should store it correctly right?

NOW, I get this ing error inside of Weapon_machinegun when I try to access it!

:: error C2039: 'g_vecFiringAng' : is not a member of 'C_BasePlayer' WTF?!
ChadReitsma is offline   Reply With Quote
Old 05-02-2012, 05:26 PM   #5
ChadReitsma
 
Join Date: Feb 2012
Reputation: 4
Posts: 91
The way that this engine handles client/server communication is truly mind boggling, how can I simply tell the server to use a new firing angle which is defined in that con_command? Like ...

It's like the weapon file looks client side for the angles, but the server uses something else?? ... guhhhhhhh
ChadReitsma is offline   Reply With Quote
Old 05-02-2012, 06:22 PM   #6
ChadReitsma
 
Join Date: Feb 2012
Reputation: 4
Posts: 91
[Solved]

YESSSSSSSSSSSSSSSSSS... FINALLY!!!

Thank you to everyone who helped me, I will post the solution in my other thread here! :

http://forums.steampowered.com/forum....php?t=2558215
ChadReitsma is offline   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 10:11 PM.


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