Game Development Community

Scripting

by Marcelo Sim · in Technical Issues · 09/26/2007 (12:02 pm) · 7 replies

Hi people,

I'm using the starter.fps starter kit and inside of it, i put a new file with this code:


datablock ItemData(ObjTeste)
{
shapeFile = "~/data/shapes/items/healthPatch.dts";
mass = 1;
friction = 1;
};

function InsereObjTeste()
{
%shape = new Item() {
datablock = ObjTeste;
rotation = "0 0 1 0";
};

// Insere na missao do torque
MissionCleanup.add(%shape);

%shape.setTransform("-90 -2 20 0 0 1 0");
echo("Inserindo elemento " @ %shape);

return (%shape);
}

function MoveObjeto(%shape, %dist)
{
%xfm = %shape.getTransform();
%lx = getword(%xmf, 0);
%ly = getword(%xmf, 1);
%lz = getword(%xfm, 2);
%lx += %dist;

%shape.setTransform(%lx SPC %ly SPC %lz SPC "0 0 1 0");
}

function ExecutaMovimento()
{
%ms = InsereObjTeste();
MoveObjeto(%ms, 15);
}


So, I start the starter.fps game and, in console, I compile the code using:

exec("starter.fps/teste.cs");

It compiles and load without any problem but when I try to use:

$ff = InsereObjTeste();

I receive an error saying that this function does not exists.

Does someone could help me?

Thanks a lot.

Ricardo

About the author

Recent Threads


#1
09/26/2007 (12:59 pm)
You could try using
%pos = getWords( %shape.getTransform(), 0, 2 );
%offset = %dist SPC "0 0"
%pos = VectorAdd( %pos, %offset );
%shape.setTransform( %pos SPC "0 1 0 0" );

It would be more readable. Don't know if that helps.
#2
09/26/2007 (1:26 pm)
If you put your new script file under server/scripts.
Then add a line:

exec("./MyScript.cs");
to server/scripts/game.cs;

This will solve it.

The problem is that it is failing to locate the shape file and so the datablock is not being create, this in turn affects the creation of your test object with that data block.

Alternatively you can just change the datablock to such:
datablock ItemData(ObjTeste) {
   shapeFile = "starter.fps/data/shapes/items/healthPatch.dts";
   mass = 1;
   friction = 1;
};
The only difference is the absolute reference to the dts.

Also you need to be in a mission for there to be a MissionCleanup object to add your object to.

Gabe
#3
09/27/2007 (6:14 am)
Hi Gabriel,

I tried both solution but neither of them had worked.

When I put my function in server/scripts and tried do execute the command $ff = InsereObjTeste(); in the console, I received a message saying that ObjTeste is not a GameBase datablock class.

Do you know what this means?

Thanks a lot for you help.

Ricardo
#4
09/27/2007 (6:53 am)
I was getting that same error while I was testing your initial scripts. This error was due to it failing to create the datablock due to an invalid shape file (couldn't find the referenced shape).

When you execute the script directly you should be seeing some error messages?

Gabriel
#5
09/27/2007 (7:56 am)
Hi Gabriel,

When I compile and execute this script in console, it compiles and loads without problem. The problem occours when I try to call the function $ff = InsereObjTeste();

It says that this function does not exists!

Thanks.

Ricardo
#6
09/27/2007 (8:51 am)
Could you please list the commands you enter into the console plus the results, and this will help to identify the problem.

Gabriel
#7
09/27/2007 (9:20 am)
Datablocks are intended to all be loaded prior to a mission starting. You cannot create new datablocks post mission start up (by exec'ing this code at the console, for example) without a host of other steps.

As Gabriel suggests, exec the file that contains your datablock prior to starting your mission, and it will instantiate correctly (assuming nothing else is wrong).