webots icon indicating copy to clipboard operation
webots copied to clipboard

Can't reference fields from PROTO javascript functions if not referenced directly

Open brettle opened this issue 1 year ago • 0 comments

As a test case, consider:

#VRML_SIM R2023b utf8
# template language: javascript

PROTO ExampleProto [
    field SFFloat field1 1
    field SFFloat field2 5
]
{
  Solid {
%<
function sum(fieldsObj) {
  return fieldsObj.field1.value + fieldsObj.field2.value;
}
>%
       radarCrossSection %<= sum(fields) >%
  }
}

When I insert that proto, I get:

ERROR: '.../ExampleProto.proto': error: Template engine error: failed to execute JavaScript template: Cannot read property 'value' of undefined.

I suspect I'm running up against this:

https://github.com/cyberbotics/webots/blob/69681a9c200ff1e156c90868ef2eb3d293319ca8/src/webots/vrml/WbProtoModel.cpp#L277-L295

brettle avatar Jun 28 '24 16:06 brettle