Image Datablock Utility
by Chris Newman · in Torque Game Builder · 02/27/2005 (12:39 pm) · 16 replies
I just went through the tut and it does a good job on helping me understand whats going on. But it brings up a question about the tilemap.
I noticed in the scripts you need to define the images for the tilemap like...
datablock fxImageMapDatablock2D(bgCloud1ImageMap)
{
mode = full;
textureName = "~/client/images/bg_cloud_1";
};
But if you forget one image your tilemap layer does not show up.
Is there a way that you can skip defining the images in scripts for tilemaps?
I tend to forget all names of the images i am using in my maps. I think it would be awsome that when you load up a tilemap it automaticly creates the datablocks for the images that it needs for you and all you have to do is feed it the dir that the images are stored in.
*edit
wow now after looking at all the stuff the tilemaps can do, such as animated tiles, this would only be valid for static tilemaps.
I noticed in the scripts you need to define the images for the tilemap like...
datablock fxImageMapDatablock2D(bgCloud1ImageMap)
{
mode = full;
textureName = "~/client/images/bg_cloud_1";
};
But if you forget one image your tilemap layer does not show up.
Is there a way that you can skip defining the images in scripts for tilemaps?
I tend to forget all names of the images i am using in my maps. I think it would be awsome that when you load up a tilemap it automaticly creates the datablocks for the images that it needs for you and all you have to do is feed it the dir that the images are stored in.
*edit
wow now after looking at all the stuff the tilemaps can do, such as animated tiles, this would only be valid for static tilemaps.
#2
Know what, I think im on it as soon as i finish this lil clone of bricks.
02/27/2005 (3:28 pm)
Yeah, that would be a great idea.Know what, I think im on it as soon as i finish this lil clone of bricks.
#3
02/27/2005 (10:08 pm)
We will have a tool like this eventually, but if you guys wanted to build one in the mean time, that'd rock. I would highly suggest doing it directly in TorqueScript + Torque GUI. It would be so much better, and built right into Torque 2D! This is how our tool will work, and if you get it up and running as such, it might just form the basis for the "official" version. :)
#4
This is a good way for me to learn gui controls too.
Now i wish 2 years ago when i bought the SDK i wasn't being so stuborn and jumping from engine to engine and even a few of my own. But im here now and going to give 100% to this community.
02/28/2005 (5:14 pm)
Im on it right now.This is a good way for me to learn gui controls too.
Now i wish 2 years ago when i bought the SDK i wasn't being so stuborn and jumping from engine to engine and even a few of my own. But im here now and going to give 100% to this community.
#5
I too have been stubborn and jumping from engine to engine and working on my own homebrewed one.
Thank you T2D for saving my games.
02/28/2005 (8:17 pm)
Chris I feel your pain.I too have been stubborn and jumping from engine to engine and working on my own homebrewed one.
Thank you T2D for saving my games.
#6
02/28/2005 (9:23 pm)
If you need help just hollar Chris... lately I've been working with some hefty file writing in TorqueScript (was/am working on a Torquescript database)
#7
If you could point me in the direction of how to read file names in a dir, string manipulation and writing to a file. It would be very much appreciated.
*edit i found a lot of info in the .gui files, but any additional info is good. :)
03/01/2005 (6:32 pm)
@King BobIf you could point me in the direction of how to read file names in a dir, string manipulation and writing to a file. It would be very much appreciated.
*edit i found a lot of info in the .gui files, but any additional info is good. :)
#8
03/01/2005 (6:39 pm)
@Josh: Is there documentation from TGE that covers file manipualtion and such? Shouldn't we get access to those "private" sections which overlap between T2D and TGE? Would help the learning curve a good bit. :)
#9
All docs for scripting are freely avaiable.
The private sections for TGE deals with the c++ source code.
03/01/2005 (6:52 pm)
@JasonAll docs for scripting are freely avaiable.
The private sections for TGE deals with the c++ source code.
#11
this is from "Tork" snippets should help with looking at file...
Here is a couple string helper functions I made for my torquescript DB... should help you identify string manipulation...
03/01/2005 (7:58 pm)
function compileAutostartFiles(%dir)
{
if(%dir $= "")
%dir = "~/autostart";
// exec every cs file in the folder
%search = %dir @ "/*.cs";
for(%file = findFirstFile(%search); %file !$= ""; %file = findNextFile(%search))
{
echo("\n--------------------- game.cs: Autostarting " @ %file @ " ------------");
exec(%file);
}
}this is from "Tork" snippets should help with looking at file...
Here is a couple string helper functions I made for my torquescript DB... should help you identify string manipulation...
function JournalDemo::getTagName(%this, %string)
{
%endChar = strLen(%string);
%firstChar = getSubStr(%string, 0, 1);
if(%firstChar $= "<")
{
%totalChar = %endChar - 2;
} else
{
%totalChar = %endChar - 1;
}
%stringToReturn = getSubStr(%string, 1, %totalChar);
return %stringToReturn;
}
function JournalDemo::returnStringAfter(%this, %string, %char)
{
%endChar = strLen(%string);
for(%i=0;%i<%endChar;%i++)
{
%charToCheck = getSubStr(%string, %i, 1);
if(%charToCheck $= %char)
{
%startChar = %i + 1;
}
}
%totalChar = %endChar - %startChar;
%stringToReturn = getSubStr(%string, %startChar, %totalChar);
return %stringToReturn;
}
function JournalDemo::returnStringBefore(%this, %string, %char)
{
%endChar = strLen(%string);
for(%i=0;%i<%endChar;%i++)
{
%charToCheck = getSubStr(%string, %i, 1);
if(%charToCheck $= %char)
{
%startChar = %i;
}
}
%totalChar = %startChar;
%stringToReturn = getSubStr(%string, 0, %totalChar);
return %stringToReturn;
}
#12
03/01/2005 (8:00 pm)
This is my parsing function for my torqueScript DB warning this code is long and not very clean, feel free to examine it as reference (it works) and if you have any questions, just figured I'd give you too much reference rather than too little lol
#13
03/01/2005 (8:02 pm)
function JournalDemo::loadPlainFile(%this)
{
%file = new FileObject();
$journalNextMenu = "typeMenu";
//Set basic variables to initiate the journal file
$journalArrayCount = 0;
%entryCount = 0;
%count = 0;
$mainTagCount = 0;
for(%i=0;%i<100;%i++)
$subTagCount[%i] = 0;
$sub2TagCount = 0;
%subTagNum = 0;
%sub2TagNum = 0;
%mainValueCount = 0;
%subValueCount = 0;
%sub2ValueCount = 0;
$journalSubTags = new ScriptObject();
for(%i=0;%i<100;%i++)
{
$journalSubTags.contents[%i] = new ScriptObject();
}
$journalSub2Tags = new ScriptObject();
for(%i=0;%i<100;%i++)
{
$journalSub2Tags.contents[%i] = new ScriptObject();
}
//MATT YOU MODIFIED THIS
$mainValueArray = new ScriptObject();
for(%i=0;%i<100;%i++)
$mainValueArray.contents[%i] = 0;
//MATT YOU MODIFIED THAT
//Sub Value Array to hold all of the values for each Sub Property
$subValueArray = new ScriptObject();
for(%i=0;%i<100;%i++)
{
$subValueArray.contents[%i] = new ScriptObject();
for(%j=0;%j<100;%j++)
{
$subValueArray.contents[%i].contents[%j] = new ScriptObject();
}
}
$sub2ValueArray = new ScriptObject();
for(%i=0;%i<100;%i++)
{
$sub2ValueArray.contents[%i] = new ScriptObject();
for(%j=0;%j<100;%j++)
{
$sub2ValueArray.contents[%i].contents[%j] = new ScriptObject();
}
}
//opening config file for initial scan for values
if(%file.openForRead("Dark.Game/data/journal/config.txt"))
{
echo("CONFIG file has been opened");//for debug
while(!%file.isEOF())
{
echo("file is NOT EOF");
%line = %file.readLine();
%tag = getSubStr(%line, 0, 1);
if(%tag $= "<")
{
echo("main tag");
%searchMode = "main";
} else if(%tag $= "-")
{
%tag = getSubStr(%line, 1, 1);
if(%tag $= "-")
{
echo("sub2 tag");
%searchMode = "sub2";
} else
{
echo("sub tag");
%searchMode = "sub";
}
}
//search for menus or properties
echo("searchmode:" SPC %searchmode);
echo(%count);
%count++;
switch$(%searchmode)
{
case "main":
%tag = %this.getTagName(%line);
if((getSubStr(%tag,0,1)) $= "/")
{
%subTagNum = 0;
%sub2TagNum = 0;
echo("end tag");
} else
{
echo("looking for a main");
echo("Returned Main Tag:" SPC %tag);
$journalMainTags[$mainTagCount] = %tag;
%mainTagNum = $mainTagCount;
$mainTagCount++;
}
case "sub":
echo("looking for a sub");
%tag = %this.getTagName(%line);
echo("Sub Tag:" SPC %tag);
$journalSubTags.contents[%mainTagNum].contents[%subTagNum] = %tag;
$subTagCount[%mainTagNum]++;
%subTagNum++;
case "sub2":
echo("looking for a sub");
%tag = %this.getTagName(%line);
echo("Sub2 Tag:" SPC %tag);
$journalSub2Tags.contents[%mainTagNum].contents[%sub2TagNum] = %tag;
$sub2TagCount++;
%sub2TagNum++;
}
}
echo("CONFIG file scan ENDED");
}
%file.close();
................... (this function is too long for one post)
#14
03/01/2005 (8:03 pm)
...... continued
//if file is able to be opened for reading we will start the process
if(%file.openForRead("Dark.Game/data/journal/journal.txt"))
{
echo("scanning file to find end");//for debug
while(!%file.isEOF())
{
echo("file loop");
$journalArrayCount++;
%line = %file.readLine();
//check tags for main, sub, or sub 2 menu/ property searches
%tag = getSubStr(%line, 0, 1);
if(%tag $= "<")
{
%searchMode = "main";
%subValueCount = 0;
} else if(%tag $= "-")
{
%tag = getSubStr(%line, 1, 1);
if(%tag $= "-")
{
%searchMode = "sub2";
} else
{
%searchMode = "sub";
}
}
//search for menus or properties
echo("searchmode:" SPC %searchmode);
echo(%count);
%count++;
switch$(%searchmode)
{
case "main":
//search for start and end entry tags
%tag = %this.getTagName(%line);
echo(%tag);
for(%i=0;%i<$mainTagCount;%i++)
{
if(%tag $= $journalMainTags[%i])
{
echo("found" SPC $journalMainTag[%i]);
//MATT YOU MODIFIED THIS
$mainValueArray.contents[%i]++;
//MATT YOU MODIFIED THAT
if(%i > %mainTag)
%mainValueCount = 0;
%mainTag = %i;
} else if(%tag $= ("/" @ $journalMainTags[%i]))
{
echo("end main tag found" SPC %tag);
//when end tag is found set
%mainValueCount++;
}
}
echo("looking for a main");
case "sub":
echo("looking for a sub");
echo(%line);
%tag = %this.returnStringBefore(%this.getTagName(%line), "=");
echo("looking for:" SPC %tag);
for(%i=0;%i<$subTagCount[%mainTag];%i++)
{
if(%tag $= $journalSubTags.contents[%mainTag].contents[%i])
{
echo("found" SPC $journalSubTags.contents[%mainTag].contents[%i]);
echo("loading from main:" SPC %mainValueCount SPC "to sub:" SPC %subValueCount);
$subValueArray.contents[%mainTag].contents[%mainValueCount].contents[%i] = %this.returnStringAfter(%line, "=");
%subValueCount++;
}
}
}
echo($journalArrayCount);//for debug
}
} else
{
echo("file scan failed"); //for debug
}
%file.close();
%file.delete();
}
#15
Thanks, im about to crash so ill look through it tommorow.
I started work on the gui for it, or a least a gui so i can start testing some functions out.
I have never done any gui editing before. So far its a mix of using the editor and scripting and its easy to get a handle of.
03/01/2005 (8:09 pm)
@King BobThanks, im about to crash so ill look through it tommorow.
I started work on the gui for it, or a least a gui so i can start testing some functions out.
I have never done any gui editing before. So far its a mix of using the editor and scripting and its easy to get a handle of.
#16
03/01/2005 (8:50 pm)
I love the gui system in Torque... yeah often you use both the editor and scripts... though I found myself using scripts 90% of the time lol...
Torque Owner Philip Mansfield
Default Studio Name
Automating it might be a bit tricky with the myriad of options available, but it should be possible to select an image, and then fill in a simple form with the mode, image size and the other bits of info.
As it goes it along it writes out the datablocks to a file, and you can then cut and paste them into your own script files.
Any coders fancy a project? ;)