SimSetIterator Code
by RedCore · in Torque Game Engine · 04/20/2004 (7:31 pm) · 5 replies
I'm trying to cycle through all my RadioData Datablocks.. i wrote this code..
ConsoleMethod( Player, ChangeStation, bool, 2, 2, "()")
{
return object->ChangeStation();
}
bool Player::ChangeStation()
{
Con::printf("The Function was called.. now what..");
// Find the Replicator Set.
SimSet *RadioList = dynamic_cast(Sim::findObject("RadioData"));
if (!RadioList)
{
// Console Warning.
Con::warnf("Radio Controler - Cannot locate the 'RadioData', this is bad!");
return false;
}
// Cycle through Object(s).
for (SimSetIterator itr(RadioList); *itr; ++itr)
{
// Fetch the Radio Datablock.
RadioData* Radio = static_cast(*itr);
if(Radio->Active)
{
CurrentStation = Radio->Station;
Con::printf("Current Station is %d", CurrentStation);
}
Con::printf("Is this Station Active? %d", Radio->Active);
Con::printf("What is this Stations type? %s", Radio->Type);
Con::printf("We Are looping through the Radio Datablocks..");
}
return true;
}
Everything works except getting the variables from the current radio datablock.. so Radio->Active is always 0 and the other variable arent set or something..
it *could* have to do with the class.. but i figured it has to do with this code..
thx for the help..
ConsoleMethod( Player, ChangeStation, bool, 2, 2, "()")
{
return object->ChangeStation();
}
bool Player::ChangeStation()
{
Con::printf("The Function was called.. now what..");
// Find the Replicator Set.
SimSet *RadioList = dynamic_cast
if (!RadioList)
{
// Console Warning.
Con::warnf("Radio Controler - Cannot locate the 'RadioData', this is bad!");
return false;
}
// Cycle through Object(s).
for (SimSetIterator itr(RadioList); *itr; ++itr)
{
// Fetch the Radio Datablock.
RadioData* Radio = static_cast
if(Radio->Active)
{
CurrentStation = Radio->Station;
Con::printf("Current Station is %d", CurrentStation);
}
Con::printf("Is this Station Active? %d", Radio->Active);
Con::printf("What is this Stations type? %s", Radio->Type);
Con::printf("We Are looping through the Radio Datablocks..");
}
return true;
}
Everything works except getting the variables from the current radio datablock.. so Radio->Active is always 0 and the other variable arent set or something..
it *could* have to do with the class.. but i figured it has to do with this code..
thx for the help..
About the author
#2
04/22/2004 (2:26 pm)
I corrected the static_cast problem.. but i think the pointers are still not valid.. they are not returning anything..
#3
04/22/2004 (3:56 pm)
Then the types are not compatible. Consult your memory for C++'s typecasting rules.
#5
I did a tree() in the game.. and saw that the char variables were not being stored in the engine.. but the F32 variables were.. but that stil doesnt make sense why Radio->active isnt true.. for atleast one of the datablocks..
@LabRat
Huh?
04/22/2004 (9:06 pm)
Could it have anything to do with me using TypeS8 in my addfield()'s.. is that the right type to use for chars? eXoDus told me to use them.. hem..I did a tree() in the game.. and saw that the char variables were not being stored in the engine.. but the F32 variables were.. but that stil doesnt make sense why Radio->active isnt true.. for atleast one of the datablocks..
@LabRat
Huh?
Associate Kyle Carter
Do you know that your pointers are valid?