Anteworld - Outerra Game > JavaScript development

Properties

<< < (2/3) > >>

SteelRat:

--- Quote from: cameni on July 02, 2015, 09:14:29 am ---$ctx is defined as a method on interface objects, so:


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

--- End code ---

--- End quote ---

Thanks!

SteelRat:
Hi cameni!


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

Vec3.prototype = {
    constructor: Vec3
};

--- End code ---

Why is that?

--- Code: ---this.x = +x;
--- End code ---

And not so

--- Code: ---this.x = x;
--- End code ---

cameni:
It's a weird JS optimization trick.
See http://www.sitepoint.com/understanding-asm-js/ and http://asmjs.org/spec/latest/#parameter-type-annotations

SteelRat:

--- Quote from: 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

--- End quote ---

I understood.
This means that the value of the "X" is of type double.

Thank!

SteelRat:

--- Quote from: cameni on July 02, 2015, 09:14:29 am ---$ctx is defined as a method on interface objects, so:


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

--- End code ---

--- End quote ---

Hi cameni!

Does not work.


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

--- End code ---


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

--- End code ---

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version