Board index FlightGear Development Nasal

[Solved] Swapping properties under Nasal  Topic is solved

Nasal is the scripting language of FlightGear.

[Solved] Swapping properties under Nasal

Postby I-VANM » Mon Jun 01, 2020 12:19 pm

First time posting here, so sorry for the wrong subrforum...
Because of the lack of physical buttons, I've programmed a four-button set to control the whole radio stack: "select active radio", "stby freq up", "stby freq down", "swap freq".
I've created a integer property called "/devices/status/yoke/actradio. My first button manages the property correctly. The two other buttons (using if/elsif and getprop/setprop) are able to increase/decrease the frequencies as I want. The Swap button doesn't work. Here is my coding attempt:

<button n="1">
<name>Black button</name>
<desc>swap active and stby freq of active radio</desc>
<script> var act = getprop("/devices/status/yoke/actradio"); if (act == 1) {
}elsif (act == 2){
}elsif (act == 3){

<!--and so on for comm, nav and ADF-->


This doesn't work (I suppose) because of the non-Nasal coding (<command>, <property>... ) into the Nasal <script>, but I can't find a Nasal function to manage the frequencies swapping. I'm dreaming of something like "swapprop"...
How can a simple copypase guy like me get this result?
Thank you!
Last edited by I-VANM on Mon Jun 01, 2020 7:54 pm, edited 1 time in total.
Posts: 7
Joined: Mon Jun 01, 2020 9:45 am

Re: Swapping properties under Nasal  

Postby Hooray » Mon Jun 01, 2020 1:14 pm

you can use both, Nasal or fgcommands (bindings) - and you can even invoke fgcommands from Nasal.
That being said, you need to use different properties for this to work (look for the index number).
Also, you will need separate bindings for each command (IIRC).

If you simply want to a no-code solution, just see $FG_ROOT/README.commands and use a conventional binding.

Don't use Nasal if you don't understand the XML part of it.

Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Posts: 12158
Joined: Tue Mar 25, 2008 8:40 am

Re: Swapping properties under Nasal

Postby I-VANM » Mon Jun 01, 2020 7:53 pm

Thank you, Hooray!
I've found <conditions> in README.commands, so I can avoid Nasal as follows:


instead of the whole Nasal thing with var, getprop, if var=1, elsif and so on.
Copypasted 4 times, small adjustments... works 100%.

Thank you again, proud to be part of this community of generous helpers!
Posts: 7
Joined: Mon Jun 01, 2020 9:45 am

Return to Nasal

Who is online

Users browsing this forum: Google [Bot] and 1 guest