Outerra forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Outerra Tech Demo download. Help with graphics driver issues

Pages: [1] 2 3 ... 5

Author Topic: Methods  (Read 45837 times)

SteelRat

  • Sr. Member
  • ****
  • Posts: 380
  • newbie
Methods
« on: May 12, 2015, 02:57:32 pm »

Hi Cameni!

Code: [Select]
/*
file: hero.js
*/

"use strict";

$include("scripts/config.js");
$include("scripts/functions.js");

function initialize(reload)
{
this.set_character_model("outerra/mercenary/mercenary");

addWeapon(this, "AK_74M");
}

...

Code: [Select]
/*
file: functions.js
*/

function addWeapon(unit, weapon) {

var cfgWpn = cfgWeapons[weapon];

if (cfgWpn.scope) {
var cfgWpnBase = cfgWeapons[cfgWpn.base];

unit.set_weapon_model(cfgWpnBase.pack); // model is created
var wpn = unit.get_geomob(1);

for (var meshIdx in cfgWpnBase.meshes) {
if (cfgWpn.meshes.indexOf(cfgWpnBase.meshes[meshIdx]) < 0) {
// operations on arrays are correct
try {
wpn.set_mesh_visible(cfgWpnBase.meshes[meshIdx], false); // Error
} catch(e) {
unit.log_err("PTM: set_mesh_visible: " + e);
}
}
}
}
}

Code: [Select]
ERROR: PTM: set_mesh_visible: TypeError: Cannot call method 'set_mesh_visible' of null
ERROR: PTM: set_mesh_visible: TypeError: Cannot call method 'set_mesh_visible' of null
ERROR: PTM: set_mesh_visible: TypeError: Cannot call method 'set_mesh_visible' of null
...

What am I doing wrong?

And yet, it's correctly?
Code: [Select]
var wpn = unit.set_weapon_model(cfgWpnBase.pack);
Logged

PytonPago

  • Hero Member
  • *****
  • Posts: 2284
  • It´s way too complex, dont let me try to explain !
Re: Methods
« Reply #1 on: May 12, 2015, 03:13:29 pm »

Now when i look at the functions.js ... if ya want to hide a mesh, you have to define its id´s -- (  this.illumfp002_id = this.geom.get_mesh_id('002'); ) ... not sure, but id say you just try to hide them based on the meshes names itself, but it probably needs the "_id" (all the meshes ID´s defined) part on the end and then --- ( this.geom.set_mesh_visible_id(this.illumfp002_id, false); ) ...
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: Methods
« Reply #2 on: May 12, 2015, 03:22:44 pm »

Now when i look at the functions.js ... if ya want to hide a mesh, you have to define its id´s -- (  this.illumfp002_id = this.geom.get_mesh_id('002'); ) ... not sure, but id say you just try to hide them based on the meshes names itself, but it probably needs the "_id" (all the meshes ID´s defined) part on the end and then --- ( this.geom.set_mesh_visible_id(this.illumfp002_id, false); ) ...

Тут проблема другого характера, в созданном объекте "wpn" отсутствует метод "set_mesh_visible()".
Logged

SteelRat

  • Sr. Member
  • ****
  • Posts: 380
  • newbie
Re: Methods
« Reply #3 on: May 13, 2015, 04:36:48 pm »

The problem is solved.
And the result of me not impressed (
The result has killed my idea!
Logged

PytonPago

  • Hero Member
  • *****
  • Posts: 2284
  • It´s way too complex, dont let me try to explain !
Re: Methods
« Reply #4 on: May 13, 2015, 05:04:53 pm »

The problem is solved.
And the result of me not impressed (
The result has killed my idea!

 ... why ? ( could you share the files ? )
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: Methods
« Reply #5 on: May 13, 2015, 05:31:48 pm »

The problem is solved.
And the result of me not impressed (
The result has killed my idea!

 ... why ? ( could you share the files ? )

One more thing that should be checked, then share.
Logged

SteelRat

  • Sr. Member
  • ****
  • Posts: 380
  • newbie
Re: Methods
« Reply #6 on: June 28, 2015, 10:37:11 am »

Hi cameni!

Code: [Select]
var $sketch = this.$query_interface("ot::js::sketch.get");

this.grp = $sketch.create_group();

// These two methods I understand
this.img = $sketch.load_image("ui/basic.imgset/airspeed");
this.img2 = $sketch.load_image2("ui/airspeed.dds");

$sketch.make_group_active(this.grp);
$sketch.attach_to_element(this.geom.get_inst_id(), true);
$sketch.set_xray_mode(true);

this.canvas = $sketch.create_canvas(this.grp, {x:-1,y:1,z:1});

// I do not understand the meaning of having two methods of implementing the same result
$sketch.draw_image(this.img, {x:0,y:0}, {x:60,y:60}, 0xffffffff);
$sketch.draw_image2(this.img2, {x:0,y:0}, {x:60,y:60}, 0xffffffff);
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: Methods
« Reply #7 on: June 28, 2015, 01:42:16 pm »

// I do not understand the meaning of having two methods of implementing the same result
$sketch.draw_image(this.img, {x:0,y:0}, {x:60,y:60}, 0xffffffff);
$sketch.draw_image2(this.img2, {x:0,y:0}, {x:60,y:60}, 0xffffffff);

Me neither :D

For some reason Angrypig mixed two interface versions into one. Expect it to change soon.
« Last Edit: June 29, 2015, 10:53:18 am by cameni »
Logged

SteelRat

  • Sr. Member
  • ****
  • Posts: 380
  • newbie
Re: Methods
« Reply #8 on: June 29, 2015, 07:03:55 am »

I understood  :)
thanks
Logged

SteelRat

  • Sr. Member
  • ****
  • Posts: 380
  • newbie
Re: Methods
« Reply #9 on: July 01, 2015, 12:43:12 pm »

Hi cameni!

Code: [Select]
function update_frame(dt, engine, brake, steering)
{
...

var speed = Math.round(this.speed()*3.6);
var txt = "" + "Speed: " + speed;
this.sketch.make_group_active(this.grp);
this.sketch.draw_text({x:0,y:0}, 0xffffffff, txt);
}

The result on the screen
Speed: (white squares instead of numbers)

Tried so, the result is the same.
Code: [Select]
var speed = this.speed().toString();
How to?

And the associated question of how to format text?
Logged

angrypig

  • Sr. Member
  • ****
  • Posts: 454
Re: Methods
« Reply #10 on: July 02, 2015, 02:30:11 am »

Hi,

the sketch API is not finished yet we are constantly adding new features and modding existing functions. Once we will have it ready we will release documentation for it. Probably in next update...
Logged

SteelRat

  • Sr. Member
  • ****
  • Posts: 380
  • newbie
Re: Methods
« Reply #11 on: July 02, 2015, 10:19:31 am »

Hi,

the sketch API is not finished yet we are constantly adding new features and modding existing functions. Once we will have it ready we will release documentation for it. Probably in next update...

I can not understand where the catch.
If I passed to this argument

Code: [Select]
var txt = "" + "Speed 2: " + (1 + 2 + 3 + 4 + 5.6789);

That data is displayed correctly.
Logged

SteelRat

  • Sr. Member
  • ****
  • Posts: 380
  • newbie
Re: Methods
« Reply #12 on: July 02, 2015, 01:38:05 pm »

 :facepalm: :)

The correct version

Code: [Select]
function update_frame(dt, engine, brake, steering)
{
...

if (this.canvas != undefined)
this.sketch.delete_canvas(this.canvas);

this.canvas = this.sketch.create_canvas(this.grp, {x:0,y:2,z:0});

var speed = Math.round(this.speed()*3.6);
var txt = "";
txt += "Speed: " + speed + "\n";
this.sketch.draw_text({x:0,y:0}, 0xffffffff, txt);
}

Dear developers, do not forget about the method
Code: [Select]
this.sketch.clear_canvas(this.canvas);
Logged

SteelRat

  • Sr. Member
  • ****
  • Posts: 380
  • newbie
Re: Methods
« Reply #13 on: July 11, 2015, 02:21:55 pm »

Hi cameni!

Code: [Select]
// Ground vehicle

function init_chassis(){
...

this.add_weapon(); // arguments?
}
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: Methods
« Reply #14 on: July 12, 2015, 01:13:32 am »

It's a placeholder function, does nothing yet.
Logged
Pages: [1] 2 3 ... 5