Outerra forum
Anteworld - Outerra Game => Modding: Importer, Tools & Utilities => JavaScript development => Topic started by: SteelRat on June 29, 2015, 10:09:37 am
-
Hi cameni!
Object.getOwnPropertyNames(this)
...
$ctx // What is it?
-
A function that returns the context where the object was created. In theory should allow you to access global properties of the script where the object was created, though it may not be always clear where that was.
-
A function that returns the context where the object was created. In theory should allow you to access global properties of the script where the object was created, though it may not be always clear where that was.
Interesting!
this.ctx = $ctx(this);
Correctly?
-
no, this might be enough:
var $ctx;
You can access the methods easily by
$ctx.method()
-
$ctx is defined as a method on interface objects, so:
var obj = // create object somehow ...
obj.$ctx().something = 1; //sets global variable "something" in the context of the obj's script
-
$ctx is defined as a method on interface objects, so:
var obj = // create object somehow ...
obj.$ctx().something = 1; //sets global variable "something" in the context of the obj's script
Thanks!
-
Hi cameni!
var Vec3 = function (x, y, z) {
this.x = +x;
this.y = +y;
this.z = +z;
};
Vec3.prototype = {
constructor: Vec3
};
Why is that?
this.x = +x;
And not so
this.x = x;
-
It's a weird JS optimization trick.
See http://www.sitepoint.com/understanding-asm-js/ and http://asmjs.org/spec/latest/#parameter-type-annotations
-
It's a weird JS optimization trick.
See http://www.sitepoint.com/understanding-asm-js/ and http://asmjs.org/spec/latest/#parameter-type-annotations
I understood.
This means that the value of the "X" is of type double.
Thank!
-
$ctx is defined as a method on interface objects, so:
var obj = // create object somehow ...
obj.$ctx().something = 1; //sets global variable "something" in the context of the obj's script
Hi cameni!
Does not work.
// Truck_trailer.js
function update_frame(dt, engine, brake, steering, parking) {
...
if (this.init === undefined) {
var pos = this.geom.get_pos();
var rot = this.geom.get_rot();
var pos = relative_pos(pos, rot, 10, 180, 50);
this.trailer = $world.create_instance("SteelRat/Trailer/Trailer", pos, rot, false);
this.trailer.$ctx().truckMover = "TestVal";
this.log_inf("---- PTM: Truck mover: Init: OK");
this.init = true;
}
}
// Trailer.js
function update_frame(dt, engine, brake, steering, parking) {
...
if (this.init === undefined) {
if (this.$ctx().truckMover) { /* The subject test I have tried a lot of options, the effect -> nothing */
this.log_inf("---- PTM: Trailer: Init: OK");
this.init = true;
}
}
}
-
There was a bug in this version that may have a connection to this one, we'll have to test it.
-
There was a bug in this version that may have a connection to this one, we'll have to test it.
Ok. Thank!