Author Topic: Define Functions for a ScriptObject in Multiple TorqueScript Files  (Read 961 times)

I am trying to define the functions for a ScriptObject in multiple files. Take, for instance, the following three files.

Quote from: server.cs
new ScriptObject(MyObject);
exec("./log.cs");
exec("./example.cs");
Quote from: log.cs
function MyObject::log(%m) {
    echo("Logged Message:" SPC %m);
}
Quote from: example.cs
function MyObject::exampleFunction() {
    %this.log("The example function was called.");
}

If I run MyObject.exampleFunction(); in the console, I get the error: Add-Ons/Script_MyScriptName/example.cs (0): Unable to find object: '' attempting to call function 'log'

Is this just impossible? Should I just use a different ScriptObject in each TorqueScript file?

I just realized my problem. I am new to ScriptObjects, and I did not realize that the first parameter for any function in a ScriptObject is the ScriptObject itself. This all works if I add %this before all of the parameters.

Code: [Select]
==>new scriptobject(asdf);
==>function asdf::fdsa(%a){echo("zoop" SPC %a);}
==>asdf.fdsa();
zoop asdf

You are missing something

Probably the %this argument in the example.cs

Edit: yea you got it.  At any rate, you still need to declare %this before you use it.

As I mentioned above, I am quite new to ScriptObjects. Do you know if it's possible to export a variable stored in a ScriptObject using the export function? I know how to do this with normal global variables, but it is not able to find an array when I say for instance:
Code: [Select]
export("MyObject.points*", "Config/server/MyMod/points.cs", false);

not really, but you can do obj.save("path"); to export all the data

not really, but you can do obj.save("path"); to export all the data
Ah, very useful. Thanks!