Namespaces won't work on static sprites?
by Leroy Frederick · in Torque Game Builder · 09/11/2006 (5:02 am) · 10 replies
Hiya all,
This whole namespace thing is a little confusing, althought i've already read a few different materials on it (i understand the benefits)...
Anyhow, this is a weird one, my namespace 'player::updateMovement' is only recognised when a set my sprite as a 't2dAnimatedSprite', but when it is set as a 't2dStaticSprite', it says function does not exist?
What am i doing wrong, have i got the concept confused, any ideas, or are you not allowed to use namespace on a static sprites.
Thanks in advance! :0)
This whole namespace thing is a little confusing, althought i've already read a few different materials on it (i understand the benefits)...
Anyhow, this is a weird one, my namespace 'player::updateMovement' is only recognised when a set my sprite as a 't2dAnimatedSprite', but when it is set as a 't2dStaticSprite', it says function does not exist?
What am i doing wrong, have i got the concept confused, any ideas, or are you not allowed to use namespace on a static sprites.
Thanks in advance! :0)
#2
Basicially, when i set the my code as this
but when it's set as this
In both cases, the two types do not co-exist. Could it be something to do with the way my 't2dImageMapDatablock()' is setup?
09/11/2006 (5:31 am)
Thanks Michael, but by that am i right in assuming i should be able to use namespacing on a single static sprite?Basicially, when i set the my code as this
$SpriteObjId = new t2dAnimatedSprite($namespaceId)all works fine
but when it's set as this
$SpriteObjId = new t2dStaticSprite($namespaceId)it no longer works (Unknown command updateMovement. Object player1(2924) player1 -> t2dStaticSprite -> t2dSceneObject -> SimObject)?
In both cases, the two types do not co-exist. Could it be something to do with the way my 't2dImageMapDatablock()' is setup?
#3
09/11/2006 (5:58 am)
Do you get any error messages in the console?
#4
Unknown command updateMovement. Object player1(2924) player1 -> t2dStaticSprite -> t2dSceneObject -> SimObject
EDIT:
This doesn't come up if it's set as a animated sprite!? simply changing '$SpriteObjId = new t2dStaticSprite(namespaceId)' to '$SpriteObjId = new t2dAnimatedSprite(namespaceId)' and adding 'animationName = "ImageMapAnimation";' stops this error from coming up?
09/11/2006 (6:12 am)
Yeah, sorry i edited without updating the post. Here it is again:Unknown command updateMovement. Object player1(2924) player1 -> t2dStaticSprite -> t2dSceneObject -> SimObject
EDIT:
This doesn't come up if it's set as a animated sprite!? simply changing '$SpriteObjId = new t2dStaticSprite(namespaceId)' to '$SpriteObjId = new t2dAnimatedSprite(namespaceId)' and adding 'animationName = "ImageMapAnimation";' stops this error from coming up?
#5
09/11/2006 (6:31 am)
'player::updateMovement' should be ''player1::updateMovement' because looking at the console output that is the name of the object. The only reason I can think that doesnt cause an error with the animated sprite is because you have a 't2dAnimatedSprite::updateMovement'.
#6
09/11/2006 (6:39 am)
Wow, Thanks Tom, that worked! :) But as far as i know i don't have a 't2dAnimatedSprite::updateMovement' function (i'll double check in case!) setup in any of my scripts, so im still unsure why it worked for an animatedSprite and not a Static one?
#7
Anyhow, thanks Tom & Michael.
The only thing is, the staticSprite route restricts me to having to have player1 & player2... for each namespace, whereas the animatedSprite approach would allow me to cater for however many players in the one function 'player::updateMovement', is there any way i can achieve this with staticSprite route?
Thanks in advance!
09/11/2006 (6:47 am)
Yep, checked, i don't have a t2dAnimatedSprite::updateMovement function in any scripts, so unless it's a standard function of tge i'm still confused why one works and the other doesn't :SAnyhow, thanks Tom & Michael.
The only thing is, the staticSprite route restricts me to having to have player1 & player2... for each namespace, whereas the animatedSprite approach would allow me to cater for however many players in the one function 'player::updateMovement', is there any way i can achieve this with staticSprite route?
Thanks in advance!
#8
EDIT: Thinking on, just give both player1 and player2 the same class, like "class = someClass;", then 'someClass::updateMovement' will hopfully work. I say hopefully....
09/11/2006 (7:21 am)
Try 't2dStaticSprite::updateMovement'. I'm still not completely clued up on namespaces but any staticsprite will call this function unless there is an updateMovement function for its name,class etc (I think!).EDIT: Thinking on, just give both player1 and player2 the same class, like "class = someClass;", then 'someClass::updateMovement' will hopfully work. I say hopefully....
#9
Thanks for your help guys :)
EDIT: Man, I got it to work at last hallelujah! I think you were right Michael, my code was running the same function 6 times (createPlayers) because i had a duplicate call in my game.cs script hence it was probably trying to create a duplicate static/animated sprite with the same namespace id too :S Thanks again :0)
09/11/2006 (8:36 am)
Tried both, still got a problem with t2dStaticSprite it seems, i don't know if this is a bug or what, but i won't let it be a deal breaker, i'll just use the traditional function method updateMovement(%this) instead, namespaces is getting a bit over my head and it's not that bad not being able to have player:: stuck in front of your functions ;)Thanks for your help guys :)
EDIT: Man, I got it to work at last hallelujah! I think you were right Michael, my code was running the same function 6 times (createPlayers) because i had a duplicate call in my game.cs script hence it was probably trying to create a duplicate static/animated sprite with the same namespace id too :S Thanks again :0)
#10
In addition to the revelations above, if anyone wants any more background/info on namespaces, i found the following 2 links/threads useful to some degree or another:
tdn.garagegames.com/wiki/TorqueScript/Namespaces www.garagegames.com/mg/forums/result.thread.php?qt=2269 (for this one, className doesn't seem to work, probably because its a 2001 post (it's class and superClass now), but the principal remains largely the same ;) )
edit: - another one -
www.garagegames.com/mg/forums/result.thread.php?qt=50373
09/11/2006 (9:47 am)
Not bumping or anything, just thought i must update this. Tom, 't2dStaticSprite::updateMovement' does work, so thanks for that, pointing any class/superclass of a datablock ::updateMovement (or whatever function your need) also works according to my tests!In addition to the revelations above, if anyone wants any more background/info on namespaces, i found the following 2 links/threads useful to some degree or another:
tdn.garagegames.com/wiki/TorqueScript/Namespaces www.garagegames.com/mg/forums/result.thread.php?qt=2269 (for this one, className doesn't seem to work, probably because its a 2001 post (it's class and superClass now), but the principal remains largely the same ;) )
edit: - another one -
www.garagegames.com/mg/forums/result.thread.php?qt=50373
Torque Owner Michael Woerister