Author Topic: My custom brick making script  (Read 879 times)

I am getting syntax errors from my script im trying to make i possibly gonna release, any way to fix it
Code: [Select]
//datablock fxDTSBrickData (brick8x24fData)
//{
// brickFile = "./8x24f.blb";
// category = "Plates";
// subCategory = "8x";
// uiName = "8x24f";
// iconName = " ";
//};

package CBricks
{
function NewBrick(%a, %b, %c)
{
new FileObject("CustoBrick"@%a@"x"@%b@"x"@%c@"Brick");
if(!isFile(%Bricks = "add-ons/Script_CustomBricks/"@%a@"x"@%b@"x"@%c@"-Brick.blb"))
{


("CustoBrick"@%a@"x"@%b@"x"@%c@"Brick").openForWrite(%bricks);
("CustoBrick"@%a@"x"@%b@"x"@%c@"Brick").writeLine(%a@" "@%b@" "@%c);
("CustoBrick"@%a@"x"@%b@"x"@%c@"Brick").writeLine("BRICK");
("CustoBrick"@%a@"x"@%b@"x"@%c@"Brick").close();
}
new FileObject("CustodataBrick"@%a@"x"@%b@"x"@%c@"Brick");
if(!isFile(%DataBricks = "add-ons/Script_CustomBricks/"@%a@"x"@%b@"x"@%c@"-Brick.cs"))
{
("CustoDataBrick"@%a@"x"@%b@"x"@%c@"Brick").openForWrite(%DataBricks);
("CustoDataBrick"@%a@"x"@%b@"x"@%c@"Brick").openForWrite("datablock fxDTSBrickData ("\"brick"@%a@"x"@%b@"x"@%c@"CustomBrickModData\")");
("CustoDataBrick"@%a@"x"@%b@"x"@%c@"Brick").openForWrite("{");
("CustoDataBrick"@%a@"x"@%b@"x"@%c@"Brick").openForWrite(" brickFile = \"./"@%a@"x"@%b@"x"@%c@"-Brick.blb;\"");
("CustoDataBrick"@%a@"x"@%b@"x"@%c@"Brick").openForWrite(" category = \"CustoBricks;\"");
("CustoDataBrick"@%a@"x"@%b@"x"@%c@"Brick").openForWrite(" subCategory = \"Bricks\";");
("CustoDataBrick"@%a@"x"@%b@"x"@%c@"Brick").openForWrite(" uiName = \""@%a@"x"@%b@"x"@%c@"\";");
("CustoDataBrick"@%a@"x"@%b@"x"@%c@"Brick").openForWrite(" iconName = \"\";");
("CustoDataBrick"@%a@"x"@%b@"x"@%c@"Brick").openForWrite("};");
}
updateAddOnList();
}
};
activatePackage("CBricks");
echo("---Say DeactivatePackage(CBricks); in console to deactivate!---");
Modify: i just noticed i for got to add some )'s gonna try it with that added
updated code
And suprisingly, the ()'s worked but it wont write the .cs file D=, any thing i did wrong?
Updated script
« Last Edit: October 13, 2009, 12:52:11 PM by Pah1023 »

You cannot use @ stuff outside of these: (  )
You can only use (  and  ) for math, if, loops, and functions.

You cannot use @ stuff outside of these: (  )
You can only use (  and  ) for math, if, loops, and functions.
So would i just do CustoBrick%ax%bx%cBrick
?

Trying to imitate something I did but in a crappy way?
Sorry, thought this was physical brick creation. This is for creating a new type of brick.

Trying to imitate something I did but in a crappy way?
Sorry, thought this was physical brick creation. This is for creating a new type of brick.
What you mean?
This mod is like that old V8 one with the gui but with out it, i will try to make a GUI in the later ver..


You can't use variables in the name of an object:
Code: [Select]
CustoBrick@%a@x@%b@x@%c@Brick.openForWrite()
You can't declare variables in a functions arguments:
Code: [Select]
(!isFile(%Bricks = "add-ons/Script_CustomBricks/"@%a@"x"@%b@"x"@%c@"-Brick.blb"))
You're using variables that you haven't declared, you're using openForWrite instead of writeLine - there are so many mistakes in this code that it is fruitless trying to help.

You need to read and reread a Torque Game Engine scripting guide/tutorial, you need to look up how to use FileObjects and what their functions and arguments are before you use them.

Code: [Select]
new FileObject("CustoBrick"@%a@"x"@%b@"x"@%c@"Brick");
should be:

Code: [Select]
%file = new FileObject();
so that you can then use:

  • %file.openForWrite();
  • %file.writeLine();
  • %file.close();
  • %file.delete();

Instead of using:

Code: [Select]
if(!isFile(%Bricks = "add-ons/Script_CustomBricks/"@%a@"x"@%b@"x"@%c@"-Brick.blb"))
{
    //fileobject code here
}

you can do the inverse - checking if the brick file already exists, in which case sending an error to the user and returning early:

Code: [Select]
%Bricks = "Add-Ons/Script_CustomBricks/" @ %a @ "x" @ %b" @ %x @ "%c @ "-Brick.blb";
if(isFile(%Bricks))
{
   error("ERROR: NewBrick() - " @ %Bricks @ " already exists!");
   return;
}

//fileobject code here

And code like this:

Code: [Select]
CustoDataBrick@%a@x@%b@x@%c@Brick.openForWrite(" brickFile = ./"@%a@"x"@%b@"x"@%c@"-Brick.blb;");
will not work (and not just because it's supposed to writeLine :cookieMonster:) as that produces the following output:

brickFile = ./1x1x1-Brick.blb;

and as you should already be aware, strings need to be encased in speech marks (").
To include speech marks without breaking the statement, you need to include a \ infront of them, e.g:

Code: [Select]
echo("\"The dog sat on the log\"");
would output:

"The dog sat on the log" in the console.

So study up, read through some code relevant to what you're trying to do and use it as a reference! If you need further help or want an example of working code, ask away.

You can't declare variables in a functions arguments:
Yes you can. :cookieMonster:

if(isObject(("TeamEdit_Inv" @ %j).itemID[$Minigame::TDMTeamSE_name[%id,%j]]))
It's always worked fine for me.

Wait... Shouldn't i add something like exec("add-ons/script_CustomBricks/*.cs");
?

Code: [Select]
("CustoDataBrick"@%a@"x"@%b@"x"@%c@"Brick").openForWrite(" category = \"CustoBricks;\"");
That will get the line category = "CustoBricks;" which doesn't end the line with a semicolon and causes errors.

That was what wrong with the script, thanks i will see if it works.