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: Variables  (Read 12090 times)

SteelRat

  • Sr. Member
  • ****
  • Posts: 380
  • newbie
Variables
« 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
Logged

cameni

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

SteelRat

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

cameni

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

SteelRat

  • Sr. Member
  • ****
  • Posts: 380
  • newbie
Re: Variables
« Reply #4 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!
Я и предполагал такое развитие событий, просто я знакомлюсь с миром по ближе).
Logged

PytonPago

  • Hero Member
  • *****
  • Posts: 2284
  • It´s way too complex, dont let me try to explain !
Re: Variables
« Reply #5 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."
Logged
We are still undeveloped as long as we don´t realize, that all our science is still descriptive, and than beyond that description lies a whole new world we just haven´t even started to fully understand.

SteelRat

  • Sr. Member
  • ****
  • Posts: 380
  • newbie
Re: Variables
« Reply #6 on: April 01, 2015, 02:34:29 pm »

Thank you.
Logged

PytonPago

  • Hero Member
  • *****
  • Posts: 2284
  • It´s way too complex, dont let me try to explain !
Re: Variables
« Reply #7 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
Logged
We are still undeveloped as long as we don´t realize, that all our science is still descriptive, and than beyond that description lies a whole new world we just haven´t even started to fully understand.

SteelRat

  • Sr. Member
  • ****
  • Posts: 380
  • newbie
Re: Variables
« Reply #8 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");
Logged