Outerra forum

Anteworld - Outerra Game => Modding: Importer, Tools & Utilities => JavaScript development => Topic started by: SteelRat on April 01, 2015, 08:49:26 am

Title: Variables
Post by: SteelRat on April 01, 2015, 08:49:26 am
Hi cameni!

The script is invoked from the console
Code: [Select]
/*
Spawn logic object
*/

var obj = "ptm/Logic/Logic";
var initCode = 'this.log_inf("Object logic created");';

Object.prototype.ptm = {initCode: initCode}

$con.exec("var $world = $eview.$query_interface('ot::js::world.get')");
$con.exec("var logic = $world.create_instance(obj, #(pos 10), #rot, false)");

// Here everything is fine
// logic.ptm.initCode == 'this.log_inf("Object logic created");'
print(logic.ptm.initCode);

next
Code: [Select]
/*
    package: ptm/Logic/Logic
    script: logic.js
*/

var init = false;

function init_chassis(param) {

}

function init_vehicle() {

}

function update_frame() {
if (!init) {
if (this.ptm) { // here always this.ptm == undefined
eval(this.ptm.initCode);
init = true;
this.log_inf("Logic initialized");
}
}
}

Where is my mistake?
I have two links to the same object, but the new property is available only where I have added a new property to the prototype object.
I have thought about this, but I'm not sure.

Question
How do I pass a variable from one context to another context
Title: Re: Variables
Post by: cameni on April 01, 2015, 09:28:47 am
How do I pass a variable from one context to another context

You can't. What do you want to achieve?
Title: Re: Variables
Post by: SteelRat on April 01, 2015, 10:19:56 am
How do I pass a variable from one context to another context

You can't. What do you want to achieve?

My idea was to have one object "Logic", after its establishment, give it the necessary data to solve any of the current task.

By analogy:
spawnCode ([params], code)   //this logic
createTrigger ([params], condition code, activate code)   //this trigger
Title: Re: Variables
Post by: cameni on April 01, 2015, 12:27:26 pm
It's not possible (and it would be dangerous) to access foreign contexts and variables from vehicle scripts. It will be possible to access vehicles from game script in the future, but there will be a mechanism for it, so that the script can get only the objects it's allowed to see, and perform only some tasks. Basically, a coordinated AI for some tasks.
Title: Re: Variables
Post by: SteelRat on April 01, 2015, 01:52:49 pm
It's not possible (and it would be dangerous) to access foreign contexts and variables from vehicle scripts. It will be possible to access vehicles from game script in the future, but there will be a mechanism for it, so that the script can get only the objects it's allowed to see, and perform only some tasks. Basically, a coordinated AI for some tasks.

PytonPago translate please!
Я и предполагал такое развитие событий, просто я знакомлюсь с миром по ближе).
Title: Re: Variables
Post by: PytonPago on April 01, 2015, 02:25:09 pm
PytonPago translate please!
Я и предполагал такое развитие событий, просто я знакомлюсь с миром по ближе).

"I thought it might be so, i just getting into this stuff a little more."
Title: Re: Variables
Post by: SteelRat on April 01, 2015, 02:34:29 pm
Thank you.
Title: Re: Variables
Post by: PytonPago on April 01, 2015, 03:48:08 pm
Thank you.

No need to thank the Pyton translator. Just use it like the google one ... whyteout those rude slang words.  =D
Title: Re: Variables
Post by: SteelRat on June 29, 2015, 08:21:01 am
Hi developers!

It would be great to have such

Code: [Select]
// global variables in user name space
var $Uns = this.$query_interface("ot::js::userNameSpace.get");

$Uns.setVariable( "varName", value);

var varName = $Uns.getVariable( "varName");
var varName = $Uns.getVariable( "varName", value); // Option. If the variable is not defined, it returns the specified value

$Uns.deleteVariable( "varName");