How to call function from another function

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Post Reply
Message
Author
User avatar
brodhaq
Posts: 152
Joined: Wed Jun 29, 2016 4:13 pm

How to call function from another function

#1 Post by brodhaq »

Hello
I am facing issue while working on L3 Trilogy ESI-2000.

I have subscribtion to xpl altitude dataref, which calls the new_altitude function whenever the xplane altitude changes.
new_altitude function draws altimeter and QNH display

Now I have my change QNH change function which is called by a button. This function changes the QNH value, but I need to force it to call new_altitude function as well, in order to re-draw the altimeter with the new QNH. When x-plane is paused, altitude does not change, so new_altitude function is not being called again and again, so when in pause I change QNH, the altimeter is not re-drawn until I unpause.

Is there something like "call = new_altitude()" or so?

Best regards,
Pavel
Pavel Brodský
Prague, Czech Republic

User avatar
Ralph
Posts: 7926
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: How to call function from another function

#2 Post by Ralph »

You might be able to do just new_altitude()
But I'm not sure if that works because there's no variable... In 3.x you can use request_callback(name of your callback)
If I remember correctly though, it's not yet documented on the wiki...

User avatar
brodhaq
Posts: 152
Joined: Wed Jun 29, 2016 4:13 pm

Re: How to call function from another function

#3 Post by brodhaq »

I tried new_altitude() as the first thing, but no success.

Would you recommend me switching to v3 beta now, and develop on that, or should I stick with v2? I need quite stable platform, no time to fight with bugs. How much usable v3 is, for daily serious development?

Pavel
Pavel Brodský
Prague, Czech Republic

User avatar
Ralph
Posts: 7926
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: How to call function from another function

#4 Post by Ralph »

Hard to say. It's getting better (almost) every day, but there's bugs here and there. The only way to do it in 2.1.3 is to make everything global, place your txt_set, img_rotate, etc in for example:

Code: Select all

function gui_update()
Your stuff
end
And then call that gui_update function at various places, like in the callback from the sim and your custom function.

User avatar
brodhaq
Posts: 152
Joined: Wed Jun 29, 2016 4:13 pm

Re: How to call function from another function

#5 Post by brodhaq »

Reply to myself:
Another function can be called by starting a timer with 0 delay which has callback of the another function.
Hint: dont forget to stop that timer somewhere :-)

Pavel
Pavel Brodský
Prague, Czech Republic

User avatar
brodhaq
Posts: 152
Joined: Wed Jun 29, 2016 4:13 pm

Re: How to call function from another function

#6 Post by brodhaq »

Ralph wrote: Wed Oct 11, 2017 3:37 pm You might be able to do just new_altitude()
But I'm not sure if that works because there's no variable... In 3.x you can use request_callback(name of your callback)
If I remember correctly though, it's not yet documented on the wiki...
Hello,
just reporting from V3 that request_callback(function_name) works perfectly and is extremly useful tool! Please document this on wiki for others, this is very important function (at least for me, as I am now doing all the menu logic in my EFIS). Example of usage is that I am using one function to control QNH setting while other function to draw altimeter. So I have added request_callback(new_altitude) at the end of my QNH setting function, which forces the altimeter to re-draw when QNH is changed. Thus altimeter reacts on QNH even with sim paused (which was not the case previously, because when sim is paused, altitude dataref does not change, so the subscribtion does not callback the altimeter function).

Pavel
Pavel Brodský
Prague, Czech Republic

User avatar
Ralph
Posts: 7926
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: How to call function from another function

#7 Post by Ralph »

I think Corjan wasn't sure if he really wanted this function, so that's why it's not on the wiki. I'm not sure what his opinion is right now.

User avatar
Sling
Posts: 5239
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: How to call function from another function

#8 Post by Sling »

Why do you need a special function for a callback? You can just do function_name(). I use this all the time. You can pass arguments this way as well.

Post Reply