Sensing if object already exists
by Andrew H · in Torque Game Builder · 08/24/2011 (7:45 pm) · 10 replies
I'm sure this is going to be a snap for some of you, but I'm new with this engine. I am using a SimObject to store some data, but due to the nature of my programming (I'll save you the explanation) I need to be able to sense if this object (playerProfiles) already exists. How could I do this?
About the author
I do everything for my game company. Including the legal stuff.
#2
08/24/2011 (8:34 pm)
This would work if I could figure out how to use it. Let's say I want it to echo "It exists" if the object exists, and to echo "It doesn't exist" if it doesn't. I'd need an if and an else statement, right? So give me an example. The object would be existTest.
#3
08/25/2011 (5:15 am)
Ah yes....commonly referred to at BAG as the 'Sanity check'...lol.
#4
08/25/2011 (7:09 am)
To complement what Aun posted:if(isObject(existTest))
{
echo("It exists");
}
else
{
echo("It doesn't exist");
}
#5
But it doesn't work. playerProfiles exists, but it says it doesn't.
BTW, I used error() so it sticks out.
08/25/2011 (11:07 am)
Here's the code I am using: if (isObject(playerProfiles))
{
error("playerProfiles exists");
}
else
{
error("playerProfiles doesn't exist");
}But it doesn't work. playerProfiles exists, but it says it doesn't.
BTW, I used error() so it sticks out.
#6
What type of object is ti?
How do you defined?
Where did you defined it?
Where are you checking its existance?
08/25/2011 (11:12 am)
At this point we would need more context to help you sort it out.What type of object is ti?
How do you defined?
Where did you defined it?
Where are you checking its existance?
#7
And I am currently checking it's existence in the same file as I am defining it - but I will wind up writing it to a separate file.
08/25/2011 (11:16 am)
It's a SimObject - it's (currently) defined like this:new SimObject(playerProfiles) {
canSaveDynamicFields = "1";
name1 = "New";
name2 = "New";
name3 = "New";
};And I am currently checking it's existence in the same file as I am defining it - but I will wind up writing it to a separate file.
#8
Try to follow the flow of the code, and check whats going on. Debuging is what rest to do there, as it seems to be related to the structure of your code, rather than the code itself.
08/25/2011 (11:19 am)
That should work, really.Try to follow the flow of the code, and check whats going on. Debuging is what rest to do there, as it seems to be related to the structure of your code, rather than the code itself.
#9
08/25/2011 (11:39 am)
Okay, then. This will be a good exercise in debugging, I suppose.
#10
08/25/2011 (1:41 pm)
Just for anybody out there who needs to know how to do this - you have to declare your object BEFORE you sense if it exists. Unless it doesn't exist, in which case...yeah - it's doing its job.
Torque 3D Owner Aun Taraseina
if(isObject($yourObj)) { echo("yourObj already exsit"); }