if (!isObject(moveMap))
by rennie moffat · in Torque Game Builder · 10/15/2009 (10:42 am) · 11 replies
Hi There, I know this says if this not isObject (moveMap)
but I am wondering, what is the point of this? what is the real meaning? Why is this nessacary?
but I am wondering, what is the point of this? what is the real meaning? Why is this nessacary?
About the author
My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.
#2
Well, there's no point in creating an object that already exists unless you want to destroy and recreate that object. Which, if you have this code in there, you probably don't want to do.
Hmmm... Deep Rennie... In plain Pengiun: "If the object named moveMap doesn't exist, then do something (usually create it)."
Remember that moveMap is the object that holds the details of your input mapping (keyboard and mouse...) and assigns them to various functions.
So say you have a part in your game where you completely change the control scheme. Let's say, it goes from keyboard control to mouse control...
You would first, check that the moveMap object exists (or doesn't).
If you didn't do that check and moveMap didn't exist, your inputs would never switch to the mouse controls.
10/15/2009 (11:10 am)
Quote:What is the point of this?You would use this check to make sure that moveMap doesn't exist. Then, most likely, if it doesn't exist, you would create it.
Quote:Why would you do this?
Well, there's no point in creating an object that already exists unless you want to destroy and recreate that object. Which, if you have this code in there, you probably don't want to do.
Quote:What is the real meaning?
Hmmm... Deep Rennie... In plain Pengiun: "If the object named moveMap doesn't exist, then do something (usually create it)."
Quote:Why is this necessary?
Remember that moveMap is the object that holds the details of your input mapping (keyboard and mouse...) and assigns them to various functions.
So say you have a part in your game where you completely change the control scheme. Let's say, it goes from keyboard control to mouse control...
You would first, check that the moveMap object exists (or doesn't).
if(!isObject(moveMap))
{
//create new moveMap if doesn't exist
}
moveMap.bind(mouse, blah, blah);
moveMap.push();If you didn't do that check and moveMap didn't exist, your inputs would never switch to the mouse controls.
#4
Are you asking about the !isObject part or asking what a moveMap is?
10/15/2009 (11:30 am)
That depends...Are you asking about the !isObject part or asking what a moveMap is?
#5
if(!isObject) says, if this is not this object OR is it, if this isObject does not exist?
(moveMap) - regulates all input, binds keyboard commands etc. So if I have
I am essentially saying, if this objects does not exist, create it.
:? ehn am ai right or am i right?!
;]
10/15/2009 (11:36 am)
Well ok, so if(!isObject) says, if this is not this object OR is it, if this isObject does not exist?
(moveMap) - regulates all input, binds keyboard commands etc. So if I have
if (!isObject(moveMap))
I am essentially saying, if this objects does not exist, create it.
:? ehn am ai right or am i right?!
;]
#6
That line just means "if moveMap does not exist...". If you want to create it under that condition, you need to do this:
10/15/2009 (11:41 am)
Actually, you're only half-right there... The line:if (!isObject(moveMap))
That line just means "if moveMap does not exist...". If you want to create it under that condition, you need to do this:
if (!isObject(moveMap))
{
new ActionMap(moveMap); //creates an ActionMap object named moveMap
}
#7
The line in question simply states that if object does not exist, but stes no conditions or anything.
10/15/2009 (11:43 am)
right so I assumed the creation bit. The line in question simply states that if object does not exist, but stes no conditions or anything.
#8
No, the line states the condition of the object not existing.
An if() statement tests for conditions and returns whether what goes on between its parenthesis returns true or false. So the line:
This is very basic stuff though. More is explained here
10/15/2009 (12:10 pm)
Quote:The line in question simply states that if object does not exist, but stes no conditions or anything
No, the line states the condition of the object not existing.
An if() statement tests for conditions and returns whether what goes on between its parenthesis returns true or false. So the line:
if(%var == 4) //Test to see if %var is equal to 4
{
//Code here is executed if %var is equal to 4
}
else
{
//Code here is executed if %var is not equal to 4
}This is very basic stuff though. More is explained here
#10
is often sited underneath, a return value in this case
would mean that a return of "nothing" is made?
10/15/2009 (3:07 pm)
so another question, return;
is often sited underneath, a return value in this case
if(!isObject(moveMap)) return;
would mean that a return of "nothing" is made?
#11
10/15/2009 (3:14 pm)
In that case, yes.
Torque 3D Owner Ted Southard
Well, it's a conditional saying "don't do what's in the brackets if moveMap doesn't exist". Think about that- can you work with an object that doesn't exist without running into problems? That is why if() is used: To execute code if a condition is met.
Edit: Apparently, I can't spell "if" today...