Blockland Forums > Modification Help

Define Functions for a ScriptObject in Multiple TorqueScript Files

Pages: (1/2) > >>

TheRealMint:

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");

--- End quote ---

--- Quote from: log.cs ---function MyObject::log(%m) {
    echo("Logged Message:" SPC %m);
}

--- End quote ---

--- Quote from: example.cs ---function MyObject::exampleFunction() {
    %this.log("The example function was called.");
}

--- End quote ---

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?

TheRealMint:

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.

Nexus:


--- Code: ---==>new scriptobject(asdf);
==>function asdf::fdsa(%a){echo("zoop" SPC %a);}
==>asdf.fdsa();
zoop asdf
--- End code ---

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.

TheRealMint:

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: ---export("MyObject.points*", "Config/server/MyMod/points.cs", false);
--- End code ---


Nexus:

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

Pages: (1/2) > >>

Go to full version