passing strings from cgame to game

Locked
Xamis
Posts: 4
Joined: Mon Feb 15, 2010 12:17 am

passing strings from cgame to game

Post by Xamis »

getting frustrated trying to get this to work

I have a cvar (vmCvar_t gear ) in the config file that I can read using gear.string, from inside cg_ files, no problem there, but I need to pass that string to game files, specifically g_weapon.c and g_client.c. I am really struggling to get this to work.

I tried creating a variable in bg_ that I can use to hold the data, but when I print out the variable inside g_client.c it's value is NULL.
I have had no problems passing other types of data this way, but passing a string of characters just isn't working for me.

Any suggestions on how to accomplish this.
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: passing strings from cgame to game

Post by ^misantropia^ »

Keep in mind that the client and server may run on different machines so global variables are definitely not the way to go. Grep the source for `CG_ConfigString` and `trap_SetConfigstring`, that'll show you how to pass data between them.
Xamis
Posts: 4
Joined: Mon Feb 15, 2010 12:17 am

Re: passing strings from cgame to game

Post by Xamis »

So `CG_ConfigString` and `trap_SetConfigstring` both appear to pass info to cgame from game, server to client . The opposite of what I need. I needed to pass info from a cvar on the client to the server. I figured out how to do it, and it was very easy and straight forward. Look into Info_ValueForKey( ). I passed the info in the clientinfo config string.
nexus024
Posts: 148
Joined: Fri Oct 06, 2006 7:26 pm

Re: passing strings from cgame to game

Post by nexus024 »

Does anyone know of another way a cvar could be passed from cgame to game without using Info_ValueForKey()?
User avatar
Eraser
Posts: 19175
Joined: Fri Dec 01, 2000 8:00 am

Re: passing strings from cgame to game

Post by Eraser »

You oughta specify why the original solution is insufficient for you. Now it's kind of guessing what you need.
nexus024
Posts: 148
Joined: Fri Oct 06, 2006 7:26 pm

Re: passing strings from cgame to game

Post by nexus024 »

I am trying to reverse engineer a mod in order to make mine compatible with it. I printf what gets passed through Info_ValueForKey and that method is not being used to pass the data. How else could the data get sent from cgame to game?
User avatar
Eraser
Posts: 19175
Joined: Fri Dec 01, 2000 8:00 am

Re: passing strings from cgame to game

Post by Eraser »

Info_ValueForKey doesn't send any data, it's a helper function to read data from a special kind of string that contains key/value pairs. The clue is the bit about clientinfo. That is client specific data that's transmitted to the server
nexus024
Posts: 148
Joined: Fri Oct 06, 2006 7:26 pm

Re: passing strings from cgame to game

Post by nexus024 »

Yes, I have checked there to by issuing the clientinfo command, but unfortunately the data is not being stored in there. Any other ways of transferring data between cgame and game??
Locked