Game Development Community

[RESOLVED] World Limit problem with Fish tutorial

by Chris Hoopes · in Torque Game Builder · 05/04/2012 (8:38 am) · 7 replies

Hello,

I'm giving Torque 2D a shot and running through the various tutorials, specifically the Fish Game tutorial and part 5: Adding Gameplay docs.garagegames.com/tgb/official/index.html?content/documentation/Interface%20T...

I've got the fish food spawning at random points and speeds and being collected when it collides with the player fish object just fine. However the bit that makes the food respawn when it collides with the bottom of its world object doesn't seem to be working as the tutorial intends. Here's a screenshot of the editor with the FishFood class object selected. You can see what the world limit for the object is along with the Limit Mode being set to NULL and the callback checkbox marked

i.imgur.com/gBgJG.png

And here is the code for fishfood.cs

function FishFood::onLevelLoaded(%this, %scenegraph)
{
   %this.startPositionY = %this.getPositionY();
   %this.setLinearVelocityY(getRandom(%this.minSpeed, %this.maxSpeed));
}

function FishFood::onWorldLimit(%this, %mode, %limit)
{
   if(%limit $= "bottom")
   {
      %this.spawn();
   }
}

function FishFood::spawn(%this)
{
   %this.setPosition(getRandom(-50, 50), %this.startPositionY);
   %this.setLinearVelocityY(getRandom(%this.minSpeed, %this.maxSpeed));
}

function FishFood::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, 
    %contactCount, %contacts)
{
   if(%dstObj.class $= "PlayerFish")
   {
      %srcObj.spawn();
   }
}

That 'if(%limit $= "bottom")' never seems to be getting called either because callback just isn't happening or maybe %limit is a different value. I'm not entire sure how to debug this with the demo version of Torsion so I'm a little stuck there.

Does the code or anything I've done look wrong or is this some bug with the editor itself? Thanks for any help you can give.

#1
05/04/2012 (11:50 am)
It looks correct from what you have posted. It's been a long time since I've used the demo version, so some of this may not be so easily done (aka. I could be wrong :). But, you may want to check the console.log that should get generated when you run the program and see if it lists any errors. Along the same lines, you could try adding an echo("The Limit is"@%limit); to your FishFood::onWorldLimit. This should output that + variable to the log whenever it's executed, so you can see if it's hitting that function or not.
#2
05/04/2012 (11:57 am)
I didn't know about console.log so thanks for that. Literally picked it up today to play around with it. :)

But it seems to be working now. I can't say why this is the case as the only thing that changed from when I posted the question and now is that the Torque editor had been closed and re-launched. Could it just have been some cached or temporary glitch? From working in Xcode and other environments I know that's a problem sometimes.
#3
05/04/2012 (12:58 pm)
@Chris - It is very likely that you ran into the DSO problem. When you write a script and run your game, that script is compiled into a .dso. When a DSO version of your script exists, it will take priority and get loaded instead of your .cs. This means that any changes you make to the .cs will not get loaded unless you delete the DSO file first.
#4
05/04/2012 (1:02 pm)
Ah so that's a known issue? I'm guessing that the temporary fix if I run into something like this again is just to delete all generated .dso files and re-run the game so it'll compile from scratch?
#5
05/04/2012 (3:54 pm)
That should work. The other thing that it does sometimes: if a .cs that fails to compile correctly, it may use the last good .dso... so if there's a bug inserted into the code it will sometimes just keep using the ladt good version instead of crashing out.
#6
05/04/2012 (10:12 pm)
@Chris it's not a known issue it's a feature. You should always delete the .dso when you edit the .cs
#7
05/05/2012 (2:43 pm)
Ah gotcha. I guess I just misinterpreted Michael's "problem" comment. No worries, I'm really enjoying what I'm learning and it's great seeing that there's a good community behind the software. Thanks!