Outerra forum

Anteworld - Outerra Game => Modding: Importer, Tools & Utilities => JavaScript development => Topic started by: SteelRat on June 29, 2015, 10:09:37 am

Title: Properties
Post by: SteelRat on June 29, 2015, 10:09:37 am
Hi cameni!

Object.getOwnPropertyNames(this)

Code: [Select]
...
$ctx   // What is it?
Title: Re: Properties
Post by: cameni on June 29, 2015, 11:22:22 am
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.
Title: Re: Properties
Post by: SteelRat on June 29, 2015, 12:17:39 pm
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!

Code: [Select]
this.ctx = $ctx(this);

Correctly?
Title: Re: Properties
Post by: necro on July 02, 2015, 07:46:31 am
no, this might be enough:


Code: [Select]
var $ctx;

You can access the methods easily by
Code: [Select]
$ctx.method()
Title: Re: Properties
Post by: cameni on July 02, 2015, 09:14:29 am
$ctx is defined as a method on interface objects, so:

Code: [Select]
var obj = // create object somehow ...
obj.$ctx().something = 1; //sets global variable "something" in the context of the obj's script

Title: Re: Properties
Post by: SteelRat on July 02, 2015, 09:58:32 am
$ctx is defined as a method on interface objects, so:

Code: [Select]
var obj = // create object somehow ...
obj.$ctx().something = 1; //sets global variable "something" in the context of the obj's script

Thanks!
Title: Re: Properties
Post by: SteelRat on October 02, 2015, 02:40:18 pm
Hi cameni!

Code: [Select]
var Vec3 = function (x, y, z) {
    this.x = +x;
    this.y = +y;
    this.z = +z;
};

Vec3.prototype = {
    constructor: Vec3
};

Why is that?
Code: [Select]
this.x = +x;
And not so
Code: [Select]
this.x = x;
Title: Re: Properties
Post by: cameni on October 02, 2015, 03:13:48 pm
It's a weird JS optimization trick.
See http://www.sitepoint.com/understanding-asm-js/ and http://asmjs.org/spec/latest/#parameter-type-annotations
Title: Re: Properties
Post by: SteelRat on October 02, 2015, 03:57:16 pm
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!
Title: Re: Properties
Post by: SteelRat on February 06, 2016, 12:46:50 pm
$ctx is defined as a method on interface objects, so:

Code: [Select]
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.

Code: [Select]
// 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;
}
}

Code: [Select]
// 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;
}
}
}
Title: Re: Properties
Post by: cameni on February 07, 2016, 02:19:18 am
There was a bug in this version that may have a connection to this one, we'll have to test it.
Title: Re: Properties
Post by: SteelRat on February 07, 2016, 09:23:12 am
There was a bug in this version that may have a connection to this one, we'll have to test it.

Ok. Thank!