Game Development Community

Better way to get value of global script variable?

by Frank Carney · in Torque Game Engine · 02/19/2007 (8:33 pm) · 4 replies

Here is how I am getting and setting a global script variable from C++.
Getting value:
StringTableEntry mCopiedCellList;
mCopiedCellList = StringTable->insert("$clipboard::cells");
SimObject *tobj = Sim::findObject(Con::evaluatef("return %s;",mCopiedCellList));

Setting value:
Con::evaluatef("%s=%d;",mCopiedCellList,clipboard->getId());

Is there a better way?
It works, but seems a little clunky.

Thanks,
Frank

About the author

I Started programming in HS and have never stopped. Now an 18 year vet of programming anything from assembler on a NES console to a nuclear waste processing system. If it can be programmed I may have tried to program it!


#1
02/19/2007 (9:03 pm)
Look in console.cc around line 561. You should find: setVariable(), setLocalVariable(), setBoolVariable(), setIntVariable() and setFloatVariable().

Hope this helps. :)
#2
02/19/2007 (9:42 pm)
Oh yes. This is excellent. It also looks like it has get versions of the above too. I am guessing this faster than the evaluatef command. Although, it is kind of neat to be able to run script from the C++ interface too. I should have known to look in the console.h/.cc files a little closer. That is where I got evaluatef from.

Thanks,
Frank
#3
02/20/2007 (7:37 pm)
Perfect:
Con::getVariable(mCopiedCellList)
instead of:
Con::evaluatef("return %s;",mCopiedCellList)

and:
Con::setIntVariable(mCopiedCellList,clipboard->getId());
instead of:
Con::evaluatef("%s=%d;",mCopiedCellList,clipboard->getId());

Thank you Chris,
Frank
#4
02/20/2007 (8:21 pm)
Glad I could help. :)