Game Development Community

Passing variables?

by Kevin James · in Torque Game Builder · 04/07/2010 (10:45 am) · 3 replies

function SectorLevel::onLevelLoaded(%this)
{
   $CurSector=%this;
   lblSector.text = "Sector:" SPC %this.sector;
   %this.MakeCell(44,-30);
}

This puts the cell somewhere off scene (not where I want it):
function SectorLevel::MakeCell(%x,%y)
{
   %Cell = new t2dStaticSprite() {
      sceneGraph = $CurSector;
      Position = %x SPC %y;
   };
}

This puts it where I want it, but obviously I need to know why it doesn't work when I pass in the variables from another function:

function SectorLevel::MakeCell(%x,%y)
{
   %x = 44;
   %y = -30;

   %Cell = new t2dStaticSprite() {
      sceneGraph = $CurSector;
      Position = %x SPC %y;
   };
}

About the author

Computer security, digital forensics, and platform jumper enthusiast. shells.myw3b.net/~syreal/


#1
04/07/2010 (10:58 am)
I'm surprised the third function works actually. You %this to $CurSector in the onLevelLoaded but %this is not a scenegraph, it's whatever type of object SectorLevel is. Regardless...

TGB is probably choking because it is exepecting %this to be the first argument passed in a class method but it's getting %x.

Try this:

function SectorLevel::MakeCell(%this, %x,%y)
{
   %Cell = new t2dStaticSprite() {
      imagemap = "IMAGEMAPNAME";
      sceneGraph = $CurSector;
      Position = %x SPC %y;
   };
}
#2
04/07/2010 (11:11 am)
Thanks, adding in %this made it work!

Btw, the SectorLevel class is indeed a scenegraph.

#3
04/07/2010 (11:17 am)
Very well... Glad it's working for you!