Problem related to onUpdateScene()
by StickFigs · in Torque Game Builder · 08/08/2007 (8:17 pm) · 5 replies
I'm trying to make a simple platformer using TGB but I've come across a problem I don't know how to solve when trying to script enemy behaviour.
Part of my player controlled object's script contains this:
this bit of code is actually from the tutorial here:
http://tdn.garagegames.com/wiki/TGB/MiniPlatformerTutorial#Creating_a_Player
My problem is that the enemy's script also needs this code in it as it has an updateMovement(); function too, but the problem is that I can't reference the enemy objects with a global variable because if there is more than one both can't be defined as $enemyGuy = %this because they'll both be sharing the variable $enemyGuy right?
So basically I need something like Enemies.updateMovement(); but I don't think that works right. I was thinking maybe I had to utilize the SuperClass variables? But I don't know what that is for or how to use it I am just speculating.
So does anyone understand what I mean? How can I make this work?
Part of my player controlled object's script contains this:
function PlatformerSceneGraph::onUpdateScene()
{
if (isObject($pGuy))
{
$pGuy.updateMovement();
}
}this bit of code is actually from the tutorial here:
http://tdn.garagegames.com/wiki/TGB/MiniPlatformerTutorial#Creating_a_Player
My problem is that the enemy's script also needs this code in it as it has an updateMovement(); function too, but the problem is that I can't reference the enemy objects with a global variable because if there is more than one both can't be defined as $enemyGuy = %this because they'll both be sharing the variable $enemyGuy right?
So basically I need something like Enemies.updateMovement(); but I don't think that works right. I was thinking maybe I had to utilize the SuperClass variables? But I don't know what that is for or how to use it I am just speculating.
So does anyone understand what I mean? How can I make this work?
About the author
#2
The only thing I can't figure out now is where do I enable the onUpdate() callback?
08/09/2007 (12:38 pm)
Thanks, that's exactly what I was trying to do. :DThe only thing I can't figure out now is where do I enable the onUpdate() callback?
#3
08/09/2007 (12:45 pm)
You could have something like this:function enemy::onAddToScene(%this)
{
%this.enableUpdateCallback();
}This would enable the onUpdate() callback for any object that belonged to the enemy class. :) The onAddToScene callback should work with objects that are created in the editor or in the code.
#4
What gives? :(
EDIT: Turns out it's "function enemy::onUpdate(%this)" not "onUpdateScene".
It works now, thanks for the help!
08/09/2007 (2:12 pm)
It doesn't seem like the method you suggested is working, I did all that but it seems like onUpdateScene isn't looping like it should be, but if I type $pGuy.onUpdateScene(); into the console it fires it off once so I know it would work if it was looping correctly.What gives? :(
EDIT: Turns out it's "function enemy::onUpdate(%this)" not "onUpdateScene".
It works now, thanks for the help!
#5
08/09/2007 (3:04 pm)
Ah yes onUpdate() is the new callback--sorry, wasn't sure if you what version you were using. Glad it works!
Torque Owner Melissa Niiya
Otherwise, you're on the right track. If your enemies' class is "enemy" then you could just write a function like this:
function enemy::onUpdateScene(%this) { %this.updateMovement(); } function enemy::updateMovement(%this) { ...your enemy's update movement code... }And this code will call whatever enemy::updateMovement() function you have. Or you could use a superclass in a similar way (ie, Ships::onUpdateScene() ). Also, don't forget to enable the onUpdate() callback when you create the objects. :)