So I made a quick map out of 64x Cube 1/4h bricks. But it was too big, and took to long to travel across. So I wanted to resize it.
Instead of doing it by hand I made a quick script:
function resizemap(%mapfile) //"saves/aatemp.bls"
{
if(isFile(%mapfile)) //first we check if the file exists, if it doesn't, report that.
{
%fr = new FileObject(){}; //create a new file object, this is what manipulates the file
%fr.openforread(%mapfile); //use the file object to open the map file for reading
%fw = new FileObject(){}; //create a new file object, this one will write a new file
%fw.openforwrite("saves/resizedmap.bls"); //open for write will overwrite a file if it already exists
while(!%fr.isEOF()) //while we're not at the end of the file, continue
{
%line = %fr.readline(); //read a line from the file and store it in a variable
if(getWord(%line,0) $= "64x") //check word 0 of the stored line, this is actually the first word
{
%line = "32x" SPC getWords(%line,1,2) SPC getWord(%line,3)*0.5 SPC getWord(%line,4)*0.5 SPC getWord(%line,5)*0.5 SPC getWords(%line,6,14); //replace 64x with 32x, fill in the next two words("cube and 1/4h"), rescale the next 3 words, fill in the rest of the words. for this file there were 15 words on the line we were changing
}
%fw.writeline(%line); //write the stored line, if it didn't start with 64x, the line is unedited
} //if we're not at the end of the file, we'll loop back to the beginning of the while loop
%fr.close(); //close and clean up the file objects we were using
%fr.delete();
%fw.close();
%fw.delete();
echo("File written"); //report we're finished
}
else //no map file
{
echo("Map file not found."); //report no map file
}
}
discoverfile("base/resizemap.cs");
exec("base/resizemap.cs");
resizemap("saves/aatemp.bls");
It reads a line and checks if the first word on the line is 64x.
If it is, it changes 64x to 32x and scales down the position data by 1/2.
Then it writes the line to a new file.
If the first word is not 64x, it just passes it on to be written to the new file.
I hope this was clear enough for a newbie to figure it out.
This webpage has more information on file objects, and you can find links at the top for string manipulation. (getWord, getWords, etc.)
http://docs.garagegames.com/tge/official/content/documentation/Reference/Console%20Functions/TorqueScript_Console_Functions_7.html