Game Development Community

Storing image locations in array variables

by Jacob Wood · in Torque Game Engine · 12/06/2006 (7:09 pm) · 5 replies

I'm using the GuiChunkedBitmapCtrl to load images dynamically into the interface of my game.

So I decided that it would be best if I stored the image directory locations in an array variable within the namespace of that gui control.

The way it works is that I name all of the images like this: image0, image1 and so one. Then I put it in a folder named "Images." Then I just have script cycle through all of those images to store the strings of their locations in the datablock field of the control:

function Picture::fillImageStorage(%this,%directory,%fillIndex)
{
   %i = 0;
   while(%i<%fillIndex)
   {
      //the format of the images are to be "image0, image1" and so on
      %currentImage = %this.directory@"image"@%i;
      %this.image[%i] = %currentImage;
      %i++;
      echo("Loading: "@%this.image[%i]); // doesn't work
      echo("Loading: "@%currentImage);  // works
   }
}

My problem here is that when I echo out %this.image, it doesn't say anything is in them and no errors show up in the console about it. However, if I echo out the %currentImage variable, they show up just fine so i'm creating the string the way it needs to be, but it's not going into the array at all for some reason.

Any ideas?

Thanks in advance for any advice.

#1
12/06/2006 (7:36 pm)
Did you echo %this.image[0] or %this.image ??

Aun
#2
12/07/2006 (1:58 pm)
I echoed %this.image[0]
#3
12/07/2006 (2:05 pm)
That's because %this is out of scope as soon as you exit the function. To echo the contents, use the name of whatever %this is referring to. Or did you do the echo from within the function?
#4
12/07/2006 (2:11 pm)
It was within the function, I'll go ahead and actually add in where I echoed from in my example above.
#5
12/07/2006 (2:17 pm)
Omg, I just realized my problem after I added the echoes into my example.

The %i variable gets incremented before the echoes. So technically, there wasn't anything in the array at the time of the echo!

function Picture::fillImageStorage(%this,%directory,%fillIndex)
{
   %i = 0;
   while(%i<%fillIndex)
   {
      //the format of the images are to be "image0, image1" and so on
      %currentImage = %this.directory@"image"@%i;
      %this.image[%i] = %currentImage;
      echo("Loading: "@%this.image[%i]); // works now
      echo("Loading: "@%currentImage);  // works
      [b]%i++;[/b]
   }
}

Such a little thing too! lol, thanks for the support guys!