How do you declare a string in the engine?
by Altedor · in Torque Game Engine · 03/31/2006 (1:01 pm) · 11 replies
Hi,
this will probably have a simple answer, but how do you declare a string variable in the engine source because String var is not right
is there a list of var types and what they're used for?
this will probably have a simple answer, but how do you declare a string variable in the engine source because String var is not right
is there a list of var types and what they're used for?
About the author
#3
then if I remember correctly
It is "StringResource"
but I have been Once wrong before..
I was mistaken.
otherwise if its script then Bruno has your answer there.
Also look this up in the source as you'll find its only a define i'm sure to a char * type
what you prolly wanna do is grep the source and see the other ways it handled and compare them to your usage case.
either case looking for StringResource should bring you down the right path.
03/31/2006 (1:30 pm)
If you mean the c++ then if I remember correctly
It is "StringResource"
but I have been Once wrong before..
I was mistaken.
otherwise if its script then Bruno has your answer there.
Also look this up in the source as you'll find its only a define i'm sure to a char * type
what you prolly wanna do is grep the source and see the other ways it handled and compare them to your usage case.
either case looking for StringResource should bring you down the right path.
#4
03/31/2006 (1:34 pm)
Hmmm StringResource does not seem to work
#5
help....
03/31/2006 (1:45 pm)
Ok im really confused im not actually sure it is a string I want because what im trying to do is get the datablock of an object then store it in a local variable named data to be used in conditional statements and lark so basiclly its a name of a class so should I be triying to get a pointerhelp....
#7
hmmmpphh.. I Must be getting Old.
I Swear it is torque that uses that define.
I'm at work and dont have the source so I cannot help much.
so let me get this straight your trying to get a Datablock pointer?
a string is prolly not what you want.
I'm not to sure what you want to do but.. getting a pointer to a Datablock sounds abusive as well :)
how bout just upping what is you want to do?
03/31/2006 (2:11 pm)
Searching for StringResource brought no results?hmmmpphh.. I Must be getting Old.
I Swear it is torque that uses that define.
I'm at work and dont have the source so I cannot help much.
so let me get this straight your trying to get a Datablock pointer?
a string is prolly not what you want.
I'm not to sure what you want to do but.. getting a pointer to a Datablock sounds abusive as well :)
how bout just upping what is you want to do?
#8
I am pretty sure the variable type of Data is wrong
edit: no wait is just need to get rid of the get id bit I think
03/31/2006 (2:17 pm)
Here is what i have at the moment,what I have done in the past 5 mins so the syntax is full of mistakesI am pretty sure the variable type of Data is wrong
void TerrainRender::addSelection(U32 index, SimObject* obj, ColorF color)
{
/*
Function Function:
1) If obj has RTSSquadData datablock then call unitselectdraw per member in array member[]
2) If obj has RTSUnitData datablock then get squad and do step 1
3) Just call function for Building
*/
char * data;
data = obj->mdatablock->getId();
switch(data)
{
case RTSSquadData:
for(S32 xbx;obj.squadmembermax; xbx++;)
{
}
case RTSUnitData:
case RTSBuildingData:
}edit: no wait is just need to get rid of the get id bit I think
#9
so RTSSquadData is an integer type?
if so then if the id match's this variable (RTSSquadData)
then you should simple be using an int no?
do all sim objects have a datablock member?
hmm
you will prolly need to cast SimObject to I believe GameBase (been a long time) to get access to the db
Im thinking you need to pull up some more example code that targets something along the lines of what you are doing.
look for the function that returns the datablock from the base class (GameBase im sure)
search for the usage of that function.
see how the object is managed previous to the usage of the datablock
I dont think SimObject is your starting point.
Edit:
I know you said only five minutes but..
Do Not write for loops like that!! :)
you Need to initialize that var.. heh and then iterate forever?
be carefull out there.. its murky water.
03/31/2006 (2:45 pm)
Does this compile?so RTSSquadData is an integer type?
if so then if the id match's this variable (RTSSquadData)
then you should simple be using an int no?
int dbId = obj->mdatablock->getId();
switch(dbId)
{
case RTSSquadData:
for(S32 xbx;obj.squadmembermax; xbx++;)
{
}
break;
case RTSUnitData:
break;
case RTSBuildingData:
break;
}do all sim objects have a datablock member?
hmm
you will prolly need to cast SimObject to I believe GameBase (been a long time) to get access to the db
Im thinking you need to pull up some more example code that targets something along the lines of what you are doing.
look for the function that returns the datablock from the base class (GameBase im sure)
search for the usage of that function.
see how the object is managed previous to the usage of the datablock
I dont think SimObject is your starting point.
Edit:
I know you said only five minutes but..
Do Not write for loops like that!! :)
you Need to initialize that var.. heh and then iterate forever?
be carefull out there.. its murky water.
#10
getid() returns a datatype named SimObjectPtr which is the class "Handle" which cannot be treated as an int
I think im on track now, it ended up not being anything to do with strings but comparing the ids i just need to get through my really bad knowledge of c++ syntax now
ps
Im not totally sure on how to use the -> & . operators on hericey are they wrong?
and you cannot use int it is declared as U32(Unsigned Integer) in torque im fairly sure
thanks for all the help
03/31/2006 (3:18 pm)
All the RTSSquaddata RTS.. are classes (datablocks in script) so if I use the getid() function on them and compare it with the datablock from the object it is the same as comparing the name.getid() returns a datatype named SimObjectPtr which is the class "Handle" which cannot be treated as an int
I think im on track now, it ended up not being anything to do with strings but comparing the ids i just need to get through my really bad knowledge of c++ syntax now
ps
Im not totally sure on how to use the -> & . operators on hericey are they wrong?
and you cannot use int it is declared as U32(Unsigned Integer) in torque im fairly sure
thanks for all the help
#11
But what if I don't know how many I want to save? That's where the little * comes in. It makes the var a pointer which allows for a dynamic (more or less) number of character.
I may be wrong as I use string.h in my programs but that is not used in the engine so char functions are not my forte.
04/02/2006 (2:26 pm)
A string - well char * will allow you to save characters of any length (as well as Const Char *). The problem with that is I'm not sure if you can combine strings that easily as you are using a pointer. Char (the var type) is only one character - so in order to save more then one you need to have an array (I.E. Char data[32]; would let you save 32 letters).But what if I don't know how many I want to save? That's where the little * comes in. It makes the var a pointer which allows for a dynamic (more or less) number of character.
I may be wrong as I use string.h in my programs but that is not used in the engine so char functions are not my forte.
Torque Owner Bruno Grieco
%MyLocalVariable = "String 1";
or
$MyGlobalVariable = "String 1";