Board index FlightGear Development Canvas

Need advice on how to place a canvas on a submodel  Topic is solved

Canvas is FlightGear's new fully scriptable 2D drawing system that will allow you to easily create new instruments, HUDs and even GUI dialogs and custom GUI widgets, without having to write C++ code and without having to rebuild FlightGear.

Re: Need advice on how to place a canvas on a submodel

Postby TheEagle » Wed Jan 19, 2022 12:50 am

Why does this always happen to me … :oops: :cry: :x :( :evil:

The source of the problem was much simpler - after adding the texture to the COMFreqDisplay in Blender, I forgot to re-export to the AC file !
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3413
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: Need advice on how to place a canvas on a submodel

Postby TheEagle » Wed Jan 19, 2022 1:11 am

Finally I can read the frequency on my display ! :) But whenever I change the frequency, I get this error:
Code: Select all
  198.48 [ALRT]:nasal      Nasal runtime error: undefined symbol: me
  198.48 [ALRT]:nasal        at /home/user/fgfs-addons/Aircraft/c210-family/Nasal/radios.nas, line 110
  198.48 [ALRT]:nasal        called from: /home/user/fgdata/Nasal/globals.nas, line 131


This the code I'm using:
Code: Select all
var ComNavFreqDisplay = {
   new: func(deviceNode) {
      var obj = {
         parents: [ComNavFreqDisplay],
         _canvas: canvas.new({"size": [256, 96], "view": [256, 96]}),
         poweredNode: deviceNode.getNode("power-btn"),
         selectedMhzNode: deviceNode.getNode("frequencies/selected-mhz"),
      };
      
      return obj;
   },
   init: func() {
      me.display = me._canvas.createGroup();
      
      me.display.text = me.display.createChild("text")
                  .setTranslation(128, 48)
                  .setAlignment("right-center")
                  .setFont("DSEG/DSEG7/Classic-MINI/DSEG7ClassicMini-Regular.ttf")
                  .setFontSize(80)
                  .setColor(1, 0.7, 0.7);
      
      setlistener(me.poweredNode, me.update);
      setlistener(me.selectedMhzNode, me.update);
      
      me._canvas.addPlacement({"node": "COMFreqDisplay"});
      me.update();
   },
   update: func() {
######################################
#                         Line causing the error                         #
######################################
      if (me.poweredNode.getBoolValue()) {
         me.display.text.show();
      } else {
         me.display.text.hide();
      }
      
      me.display.text.setText(me.selectedMhzNode.getDoubleValue());
   },
};

Whyever is me not defined when the method is called by a listener ? :?
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3413
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: Need advice on how to place a canvas on a submodel

Postby TheEagle » Wed Jan 19, 2022 12:05 pm

Found out by reading Object Oriented Programming in Nasal on the wiki … all working now. I do have one last question though.

I have one AC file containing the NAVFreqDisplay and COMFreqDisplay. Then I have an XML file for the no.1 COM/NAV radio with all the animations, which refers to the /instrumentation/comm and nav properties through a params section. For the no.2 radio I have an XML file which includes the no.1 radio file through a <model> tag and just passes a different set of properties for the knobs etc. to the no.1 XML file to use. This worked fine until now but now the no.1 Canvas displays are of course also added to the no.2 radio, while I of course need separate canvases ! :mrgreen: :roll: Now, do I have to make two AC files which differ just in the name of the displays (COM1FreqDisplay, COM2FreqDisplay, ...), or is there any way to tell the canvas which of the two COM/NAV radios it should be placed on when the displays have the same name (and the same texture, of course). Would the canvas recognize a named <model> as parent ? Then I could just give the two radios different names in the panel XML file.
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3413
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: Need advice on how to place a canvas on a submodel

Postby TheEagle » Wed Jan 19, 2022 12:18 pm

the named <model> isn't recognized as a valid parent. :(
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3413
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: Need advice on how to place a canvas on a submodel

Postby Maerchenprinz » Wed Jan 19, 2022 12:23 pm

Hi!

It could be that
Code: Select all
deviceNode.getNode("power-btn")
returns something like 'nil'.
Does it work when you call the method by the "power-btn" listener? If so, then that's because "power-btn" changes from 'nil' to 'something' and the getNode("power-btn") becomes something useful.
Just check the property-tree for the initial value of "power-btn" (there you can, by Ctrl+click or something (sorry, forgotten!), also display the type of property and number of listeners).
Hope that wasn't a complete rubbish theory... :roll:

Ciao,

Adrian

EDIT: This post was written while the solution was found by TheEagle...
User avatar
Maerchenprinz
 
Posts: 306
Joined: Thu Mar 15, 2007 6:24 pm
Location: Bochum, it's better, much better than you think!
Callsign: Adrian

Re: Need advice on how to place a canvas on a submodel

Postby TheEagle » Wed Jan 19, 2022 12:28 pm

Maerchenprinz wrote in Wed Jan 19, 2022 12:23 pm:EDIT: This post was written while the solution was found by TheEagle...

:mrgreen: But thanks for trying to help !
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3413
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: Need advice on how to place a canvas on a submodel

Postby wkitty42 » Wed Jan 19, 2022 4:36 pm

TheEagle wrote in Wed Jan 19, 2022 12:05 pm:Found out by reading Object Oriented Programming in Nasal on the wiki … all working now.

what was the fix???

Image
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9148
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 20.04

Re: Need advice on how to place a canvas on a submodel

Postby TheEagle » Wed Jan 19, 2022 4:44 pm

Umm, good question, I forgot ! :x

:mrgreen: Just kidding. I simply didn't know that for a listener (or timer) you need to write
Code: Select all
setlistener("/prop", func me.update());

instead of
Code: Select all
setlistener("/prop", me.update);

!
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3413
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: Need advice on how to place a canvas on a submodel

Postby wkitty42 » Wed Jan 19, 2022 4:57 pm

ahhh... maybe the guy in the comic above and denvercoder9 will finally find their answer, now? ;) :lol:
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9148
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 20.04

Previous

Return to Canvas

Who is online

Users browsing this forum: No registered users and 4 guests