Entity I/O with Strings

G

golgo32

Guest
I'm having a problem with Entity I/O and Strings. I use COutputString::Set() to set the value of the output and fire it.

Code:
string s;    
...
string_t x = MAKE_STRING( s.c_str() );
newSpeech.Set(x, this, this);


The problem is the strings received by connected entities are garbage. I stepped through the code and have confirmed that the variant_t is being set properly inside of COutputString::Set(). I've tried connecting this output many different entities that take strings as inputs (both ones I've made, and ones that came with hl2) and all receive garbage. As far as I can tell, everything I'm doing is server-side so I don't think it's a client/server issue. I also stepped through the receiving entities' code and have determined that the field type is still correct (FIELD_STRING) on the receiving end.

Any ideas?

Thanks,
-Andrew
 
Just figured it out. The string was out of scope by the time the connected entities received it. So I used AllocPooledString to put it into the global string pool. It can't fall out of scope in there.

-Andrew
 
Back
Top