Board index FlightGear Support Flying

Pop up messages in scenarios

Controlling your aircraft, using the autopilot etc.

Pop up messages in scenarios

Postby RobAndrew » Sat Dec 22, 2018 5:37 pm

I'm currently trying to make a scenario where, as soon as I select it, i have a pre-made message appear at the top of my screen for a couple of seconds. How can I do this?

Thanks
RobAndrew
 
Posts: 83
Joined: Thu Jul 12, 2018 4:59 pm
Version: 2017.3.1
OS: Mac OSX 10.11.6

Re: Pop up messages in scenarios

Postby legoboyvdlp » Sat Dec 22, 2018 5:56 pm

For reference, I juggested using <nasal> tags with a CDATA section and screen.msg inside them, but it didn't seem to work - an alternative solution will be necessary.
User avatar
legoboyvdlp
 
Posts: 6020
Joined: Sat Jul 26, 2014 1:28 am
Callsign: YV-LEGO
Version: 2018.3.1
OS: Windows 10 HP

Re: Pop up messages in scenarios

Postby Hooray » Sat Dec 22, 2018 5:59 pm

It depends on where you want to invoke that code.
Speaking in general, you need to an event, a "trigger" (say a property that changes) and an event handler (say property listener). And finally, you need an output method - e.g. print(), printlog() or any of the screen output routines, or even a Canvas dialog.

Apart from that there is also a dedicated "tutorial" system handling these things for you, search the wiki for "Tutorials".
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: 11263
Joined: Tue Mar 25, 2008 8:40 am

Re: Pop up messages in scenarios

Postby RobAndrew » Sat Dec 22, 2018 7:42 pm

Thanks for the replies,

I will say I don't have a clue how to use or make nasal commands. I'm only familiar with xml's. However there is always space to learn and would like to, I just don't really know where to start. However I will take a look at the tutorials wiki

EDIT: I've created a nasal file and copied the text from "Howto: Create a new Nasal Module" and saved it under Data/Nasal. I would just like to know how to tie this in to the scenario and make it show when I check the box. Try and link it in to the scenario xml file?
RobAndrew
 
Posts: 83
Joined: Thu Jul 12, 2018 4:59 pm
Version: 2017.3.1
OS: Mac OSX 10.11.6

Re: Pop up messages in scenarios

Postby Hooray » Sat Dec 22, 2018 8:16 pm

Open the corresponding dialog file (XML) and look for the property/properties associated with your scenario, that is the property that you can then use to trigger your Nasal code.

Speaking in general, you will not want to put custom Nasal code into $FG_ROOT/Nasal, but rather use $FG_HOME/Nasal instead. But that's really just cosmetics, for learning purposes - it doesn't matter at all.

But depending on what exactly you have in mind, there are probably better ways to structure your modification.

PS: If you prefer XML over Nasal, the tutorial system is probably what you want to look at. Besides, it's an excellent starting point to familiarize yourself with Nasal coding.
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: 11263
Joined: Tue Mar 25, 2008 8:40 am

Re: Pop up messages in scenarios

Postby RobAndrew » Sat Dec 22, 2018 11:23 pm

Hooray wrote in Sat Dec 22, 2018 8:16 pm:look for the property/properties associated with your scenario, that is the property that you can then use to trigger your Nasal code.


So far I have this in an .nas file under Data/nasal:

# test.nas (save in $FG_ROOT/Nasal)
var mycode = func() {
var message = "My test module got loaded!";
print(message); # prints the message to the black console/terminal window
gui.popupTip(message, 5); # shows the message inside the main FlightGear window as a popup/tooltip for a duration of 5 seconds
}; # end of the mycode function

# sets up a signal handler that listens to the specified property
# once it changes, it triggers the mycode callback function specified above
setlistener("/sim/signals/nasal-dir-initialized", mycode);

Now I understand that property associated with my scenario is "var message" or "var mycode" I think? as that is what will print "My test module got loaded!" I just am not sure how to trigger this? I'm guessing through the scenario XML? I know I previously stated that I am familiar with XML's, but i'm still no expert and am still getting the hang of those as well! Could you describe to me some trigger logic at all? As this is all I have in the file so far.

This all probably sounds quite silly and frustrating coming from me, asking to have it spelled out! But this is where I am with my coding at the moment unfortunately! Thank you for the support so far
RobAndrew
 
Posts: 83
Joined: Thu Jul 12, 2018 4:59 pm
Version: 2017.3.1
OS: Mac OSX 10.11.6

Re: Pop up messages in scenarios

Postby Hooray » Sun Dec 23, 2018 12:07 am

Yeah, it would seem like a good idea to first of all learn more about "listeners" and how setlistener() works:

http://wiki.flightgear.org/Listeners

http://wiki.flightgear.org/Using_listen ... with_Nasal

http://wiki.flightgear.org/Nasal_librar ... ener.28.29

Next, you should try to use the built-in property browser to trigger your code: http://wiki.flightgear.org/Property_Browser


For starters, I would suggest to ignore what you have written so far, and simply use the built-in Nasal code: http://wiki.flightgear.org/Nasal_Console

Only copying the following snippet of code into the console:

Code: Select all

var myCode = func() {
var message = "Hello World");
gui.popupTip( message );
};

setlistener("/RobAndrew/trigger", myCode);



You can use the property browser to navigate to /RobAndrew/trigger and change the property to trigger your code.

Once you have that working, I would suggest to start playing with this, based on working through the links I posted above.
And once you got the hang of how this works, you can open the XML dialog to look up the property that you want to use to set up your own scenario listener.
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: 11263
Joined: Tue Mar 25, 2008 8:40 am

Re: Pop up messages in scenarios

Postby RobAndrew » Sun Dec 23, 2018 3:56 pm

Okay, So.......

I've managed to do as you say and put the example code in to the Nasal Console, then bring up the property browser and find the trigger for this, then show it by pressing "Set" without typing any form of trigger in. My only issue now is knowing which location to make a trigger in? or a set listener? I've tried reading the articles but I can't really get my head around them and don't really understand them that well. Although I will carry on reading them and try and make some sense out of them.
Could you (or anyone else) possibly help me with the next step of this? I've found the gui/dialog xml's and even one for "scenario" which may be part of the solution? Although in this there was no references to each individual Scenario, just the layout of the Dialog and some nasal scripting at the bottom.
I'm really sorry, you may end up having to explain nuclear physics to a monkey here. Hopefully not, but i think this is going to take me some time!
Thanks
RobAndrew
 
Posts: 83
Joined: Thu Jul 12, 2018 4:59 pm
Version: 2017.3.1
OS: Mac OSX 10.11.6

Re: Pop up messages in scenarios

Postby wlbragg » Sun Dec 23, 2018 5:09 pm

Hi RobAndrew,

When you say "scenario", exactly what are you talking about? A "Tutorial" that you select from the in simulator menu or something else?

If it is a tutorial, a method for feeding a screen response already exists. It would help us to know exactly what your trying to do. That really is the only way we can give you specific advice.

If it is a menu choice your adding to the GUI and building something from there, then there would be a different method to handle that.
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
User avatar
wlbragg
 
Posts: 4278
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Debain/nVGT640

Re: Pop up messages in scenarios

Postby Hooray » Sun Dec 23, 2018 8:49 pm

Just briefly, I think you are making this more complicated than it is.

Honestly, just ignore everything you don't understand yet.

Just treat the whole property browser like a conventional browser, e.g. a file system explorer.
All the nodes there represent "paths", so you have key/value pairs.
The equivalent of a "file" being a value, e.g. a number or a string

Thus, once you navigate to such a location in the tree (file system), you can change its value.
The "file" in the example is called "trigger" - to change its value, just enter anything into the text box near the "SET" button.

Once you click that button, any listeners (=event handlers) registered for that location will be fired.

So, if you previously entered the corresponding event handler code into the console and "executed" that code, you should end up seeing a message on the screen whenever you change the value of the "trigger" property under /RobAndrew

Quite frankly, you don't need an enormous computing background here, you can accomplish so much more just by tinkering around with this, trying new things out.

And don't worry about "breaking" stuff, you can usually just exit/restart FlightGear and you should end up with a fresh session, so it is not straightforward to literally make persistent changes in between sessions.

Thus, my recommendation would definitely be to play with the property browser, and the Nasal console - in the meantime, you can look at the wiki links previously mentioned here, and maybe open $FG_ROOT/Docs to take a look at some of the README files.

The point being, we could obviously give you the "solution" directly, but that won't help you as much as spending a little time tinkering with the simulator and its property browser/nasal console.

You can find a number of people on the forum who picked up basic Nasal coding skills by working through a few tutorials and by playing with FlightGear along the way, including even retired folks who never heard about XML until then ;-)
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: 11263
Joined: Tue Mar 25, 2008 8:40 am

Re: Pop up messages in scenarios

Postby RobAndrew » Tue Dec 25, 2018 12:11 pm

wlbragg wrote in Sun Dec 23, 2018 5:09 pm:When you say "scenario", exactly what are you talking about? A "Tutorial" that you select from the in simulator menu or something else?


What I had in mind is this:

I would like to set up a scenario for Practising navigation/intercepting. Ideally, as soon as I check the scenario box, I would like to have a message pop up (Air traffic control) giving vectors and speeds of the target. Which I can then use to work out an intercept course.

I probably am making this more complicated than it is to be fair. It's all just quite new to me. However I will continue to experiment!
RobAndrew
 
Posts: 83
Joined: Thu Jul 12, 2018 4:59 pm
Version: 2017.3.1
OS: Mac OSX 10.11.6

Re: Pop up messages in scenarios

Postby Hooray » Tue Dec 25, 2018 9:24 pm

RobAndrew wrote in Tue Dec 25, 2018 12:11 pm:I would like to set up a scenario for Practising navigation/intercepting. Ideally, as soon as I check the scenario box, I would like to have a message pop up (Air traffic control) giving vectors and speeds of the target. Which I can then use to work out an intercept course.

I probably am making this more complicated than it is to be fair. It's all just quite new to me. However I will continue to experiment!


Okay, thanks for clarifying.
Indeed, this is possible to do, and it is not very difficult at all.
Based on your questions and your background, I would suggest that you stop using Nasal scripting for now, and instead look at the aforementioned "Tutorial" system, which is mostly XML-based, but which can still be agumented via scripts.

Apart from that, there are several existing features that have more or less overlapping functionality.
Such as for example, the tanker.nas "scenario" (air-to-air refueling, with vectors/altitude computed dynamically)
But there are also dedicated GCA/PART add-ons, which basically simulate a ground-controlled-approach by computing the required heading/altitude changes to a configurable airport/runway (add-ons created by rleibner).

Note that these add-ons don't just use screen messages, but can also be set up to use a text-to-speech engine.
All of these are GPL'ed, so that it would be possible to look at the code in question and extend/modified them as needed, or even create new add-ons for related purposes (think a virtual flight instructor, or ATC trainer etc).


http://wiki.flightgear.org/PAR_instrument
Image

Based on what I've seen here, I think it would be a good idea to ignore scripting for now, and start by tinkering with the property browser, maybe in conjunction with reading up on XML and properties in FlightGear (wiki and $FG_ROOT/Docs), and maybe playing a bit with existing features related to what you have in mind. You will certainly find that the Tutorial system can be easily used to set up a scenario like the one you have in mind.

That being said, if you are specifically interested in "dogfighting" (since you mentioned intercepting a target), there is also a dedicated FlightGear "mod" for just that, called "Bombable":

http://wiki.flightgear.org/Bombable
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: 11263
Joined: Tue Mar 25, 2008 8:40 am

Re: Pop up messages in scenarios

Postby RobAndrew » Fri Dec 28, 2018 10:44 pm

Okay, Thanks for the response,

I'm certainly more familiar with XML than nasal, so it's a good thing to hear that I can do this via this median. I have downloaded bombable and have been using it for a while now, very interesting stuff! (The only downside is that you can't program AI aircraft to shoot Missiles...oh well!)
I'll certainly take a look at making this into a tutorial. in reality the concept can't be achieved until the next update anyway, due to my request to the dev list about using lats/lons in route manager for referencing bearings and distances. But i'll certainly look in to it a bit more.

Thanks again, hopefully I can get this done without sounding to stupid! :'D
RobAndrew
 
Posts: 83
Joined: Thu Jul 12, 2018 4:59 pm
Version: 2017.3.1
OS: Mac OSX 10.11.6

Re: Pop up messages in scenarios

Postby Hooray » Sat Dec 29, 2018 7:43 pm

Please don't worry about "sounding too stupid" - keep in mind that most of the more seasoned user around here are indeed "10-year overnight successes" - just look at people's posting history or their registration date. Many of us have been using FlightGear for years if not even a whole decade (at least).

As a matter of fact, the feature request you mentioned above brings back fond memories actually, because the route manager's waypoint parsing routines were the first module for which I posted patches here, which ended up being added by James - over 10 years ago.

Note that Nasal has support for this sort of stuff via a dedicated module called "geo.nas".
XML-wise, you would want to use at so called "Property Rules" (wiki) probably.


PS: Technically, I consider it definitely possible to make an AI object "fire" other AI objects, and I believe we talked about this on the forum several times. Under the hood, these would be treated as separate AI instances, with the 2nd instanced being based on the position/orientation and velocities vector from the originating aircraft. I am not sure if/how this is implemented in bombable specifically, but from a Nasal standpoint it's completely do-able I'd say.
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: 11263
Joined: Tue Mar 25, 2008 8:40 am

Re: Pop up messages in scenarios

Postby RobAndrew » Sun Dec 30, 2018 12:12 am

Hooray wrote in Sat Dec 29, 2018 7:43 pm:PS: Technically, I consider it definitely possible to make an AI object "fire" other AI objects, and I believe we talked about this on the forum several times. Under the hood, these would be treated as separate AI instances, with the 2nd instanced being based on the position/orientation and velocities vector from the originating aircraft. I am not sure if/how this is implemented in bombable specifically, but from a Nasal standpoint it's completely do-able I'd say.


Yes, I'll rephrase what I said earlier and say that your right-it IS possible. Hell, most things are. But from what I hear it would take a lot of work and also a lot of memory for something like this to function. For me, running a 2009 Macbook with a hefty 8GB (I know, Huge :wink: ) RAM, I'm not sure such systems could take it

Hooray wrote in Sat Dec 29, 2018 7:43 pm:As a matter of fact, the feature request you mentioned above brings back fond memories actually, because the route manager's waypoint parsing routines were the first module for which I posted patches here, which ended up being added by James - over 10 years ago.


...Wow, must've been on the scene for a while then huh!

So I'm going to try and make this a tutorial. I've looked through the wiki and it seems quite straightforward (And When I say "Straightforward" I mean More understandable to me!) However, to make such a file for this, Where do I save said file? I may have over looked it, but I can't see anywhere in the article where to save the document.

Thanks again everyone!
RobAndrew
 
Posts: 83
Joined: Thu Jul 12, 2018 4:59 pm
Version: 2017.3.1
OS: Mac OSX 10.11.6

Next

Return to Flying

Who is online

Users browsing this forum: No registered users and 4 guests