Game Development Community

Resource location problem

by Phillip O'Shea · in Torque Game Builder · 01/08/2008 (10:57 pm) · 4 replies

Create a new template with the following code:

$instantResource = new ScriptObject()
{
   Class = "testResource";
   Name = "testResource";
   User = "TGB";
   LoadFunction = "testResource::LoadResource";
   UnloadFunction = "testResource::UnloadResource";
};
 
function testResource::LoadResource( %this )
{
    error(expandFileName("./"));
}
 
function testResource::UnloadResource( %this )
{
}
 
$instantResource.Data = new SimGroup();

You will notice that when you add the resource to TGB it will reference the TGBInstallDir/resources folder. If you reload TGB while keeping the resource loaded in the project you will see it now reference the MyGame/resources folder instead.

About the author

Head of Violent Tulip, a small independent software development company working in Wollongong, Australia. Go to http://www.violent-tulip.com/ to see our latest offerings.


#1
04/21/2009 (4:10 am)
There must be something I'm doing wrong with this. Am I supposed to create a new resource called testResource and add this script as a new resourceDatabase.cs or am I just supposed to modify my existing resource code with the following code within the loadResource function?

error(expandFileName("./"));

Maybe I'm just completely wrong. Any help with this issue would be greatly appreciated. I'm so tired of rebuilding hundreds of animations every time tgb crashes on me or I change projects.
#2
04/21/2009 (4:36 am)
Glenn, the example resource here was just to demonstrate the problem with TGB when adding a new resource to your project.

Instead of copying the files to your project folder and then loading the resource, it would load the resource and then copy the files.

What is the problem you are experiencing?
#3
04/21/2009 (7:48 am)
I try to create a new resource and instead of loading the image maps and animations i created it loads blank imageMaps.

My resource folder structure within my game is resources/NinjaPrototypeArt/Data/Images.

Within the the images folder are two imagemaps I'm testing with.

Within my NinjaPrototypeArt Folder is my resourceDatabase.cs file.

The code reads:

//-----------------------------------------------------------------------------
//  Ninja Prototype Game Assets
//  Copyright (C) No Comp Studios
//  
//  Ninja Prototype Assets - Ninja based prototype resources
//-----------------------------------------------------------------------------

// Create Resource Descriptor
$instantResource = new ScriptObject()
{
   Class          = "NinjaPrototypeArt";
   Name           = "NinjaPrototypeArt";
   User           = "TGB";
   LoadFunction	  = "NinjaPrototypeArt::LoadResource";
   UnloadFunction = "NinjaPrototypeArt::UnloadResource";
};

// Load Resource Function
function NinjaPrototypeArt::LoadResource( %this )
{
	
}

// Unload Resource Function
function NinjaPrototypeArt::UnloadResource( %this )
{
   // Remove all of the objects we use
   if( isObject( %this.Data ) && %this.Data.GetCount() > 0 )
   {      
      while( %this.Data.getCount() > 0 )
      {
         %datablockObj = %this.Data.getObject( 0 );
         %this.Data.remove( %datablockObj );
         if( isObject( %datablockObj ) )
            %datablockObj.delete();
      }
   }
}

// Resource Data
$instantResource.Data = new SimGroup() 
{
   //---------------------------------------------------------------------------
   // Audio Datablocks
   //---------------------------------------------------------------------------
   
   
   
   //---------------------------------------------------------------------------
   // Graphics
   //---------------------------------------------------------------------------
      new t2dImageMapDatablock(rockLeeAttackSSImageMap) {
      imageName = "~/data/images/rockLeeAttackSS.png";
      imageMode = "CELL";
      frameCount = "-1";
      filterMode = "SMOOTH";
      filterPad = "1";
      preferPerf = "1";
      cellRowOrder = "1";
      cellOffsetX = "0";
      cellOffsetY = "0";
      cellStrideX = "0";
      cellStrideY = "0";
      cellCountX = "-1";
      cellCountY = "-1";
      cellWidth = "80";
      cellHeight = "80";
      preload = "1";
      allowUnload = "0";
   };
   new t2dImageMapDatablock(rockLeeNavSSImageMap) {
      imageName = "~/data/images/rockLeeNavSS.png";
      imageMode = "CELL";
      frameCount = "-1";
      filterMode = "SMOOTH";
      filterPad = "1";
      preferPerf = "1";
      cellRowOrder = "1";
      cellOffsetX = "0";
      cellOffsetY = "0";
      cellStrideX = "0";
      cellStrideY = "0";
      cellCountX = "-1";
      cellCountY = "-1";
      cellWidth = "80";
      cellHeight = "80";
      preload = "1";
      allowUnload = "0";
   };
   new t2dAnimationDatablock(RockLeeIdleAnimation) {
      imageMap = "rockLeeNavSSImageMap";
      animationFrames = "1 2 3 4 5 6";
      animationTime = "0.857143";
      animationCycle = "1";
      randomStart = "0";
      startFrame = "0";
   };
   new t2dAnimationDatablock(RockLeeRunAnimation) {
      imageMap = "rockLeeNavSSImageMap";
      animationFrames = "9 10 11 12 13 14";
      animationTime = "0.6";
      animationCycle = "1";
      randomStart = "0";
      startFrame = "0";
   };
};


I deleted quite a few animations blocks to save space.

#4
04/22/2009 (11:44 pm)
I figured my problem out. I had a "~" instead of a "." in front of my image name field. That's because I copied the resource code from the code TGB generates when you create an image map or animation within the editor.