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

Hello!
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>
<binding>
<command>nasal</command>
<script> var act = getprop("/devices/status/yoke/actradio"); if (act == 1) {
<command>property-swap</command>
<property>/instrumentation/comm/frequencies/selected-mhz</property>
<property>/instrumentation/comm/frequencies/standby-mhz</property>;
}elsif (act == 2){
<command>property-swap</command>
<property>/instrumentation/comm[1]/frequencies/selected-mhz</property>
<property>/instrumentation/comm[1]/frequencies/standby-mhz</property>;
}elsif (act == 3){

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

</script>
</binding>
</button>

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!
Ivan
Last edited by I-VANM on Mon Jun 01, 2020 7:54 pm, edited 1 time in total.
I-VANM
 
Posts: 5
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.

See: http://wiki.flightgear.org/Bindings#property-swap
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,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11771
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:

<condition><equals>
<property>/devices/status/yoke/actradio</property>
<value>1</value>
</equals></condition>

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!
Ivan
I-VANM
 
Posts: 5
Joined: Mon Jun 01, 2020 9:45 am


Return to Nasal

Who is online

Users browsing this forum: No registered users and 1 guest