Outerra forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Download Outerra Tech Demo. Unofficial Outerra Discord server, MicroProse Discord server for OWS.

Author Topic: Properties  (Read 17018 times)

SteelRat

  • Sr. Member
  • ****
  • Posts: 380
  • newbie
Properties
« on: June 29, 2015, 10:09:37 am »

Hi cameni!

Object.getOwnPropertyNames(this)

Code: [Select]
...
$ctx   // What is it?
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: Properties
« Reply #1 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.
Logged

SteelRat

  • Sr. Member
  • ****
  • Posts: 380
  • newbie
Re: Properties
« Reply #2 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?
Logged

necro

  • Sr. Member
  • ****
  • Posts: 451
    • google+ Blog
Re: Properties
« Reply #3 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()
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: Properties
« Reply #4 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

Logged

SteelRat

  • Sr. Member
  • ****
  • Posts: 380
  • newbie
Re: Properties
« Reply #5 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!
Logged

SteelRat

  • Sr. Member
  • ****
  • Posts: 380
  • newbie
Re: Properties
« Reply #6 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;
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: Properties
« Reply #7 on: October 02, 2015, 03:13:48 pm »

Logged

SteelRat

  • Sr. Member
  • ****
  • Posts: 380
  • newbie
Re: Properties
« Reply #8 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!
Logged

SteelRat

  • Sr. Member
  • ****
  • Posts: 380
  • newbie
Re: Properties
« Reply #9 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;
}
}
}
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: Properties
« Reply #10 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.
Logged

SteelRat

  • Sr. Member
  • ****
  • Posts: 380
  • newbie
Re: Properties
« Reply #11 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!
Logged