Jump to content
The simFlight Network Forums
jmcken

Some questions regarding writing variables:

Recommended Posts

Hello:

 

My name´s John McKen, I live in Asheville, NC, USA. I´ve been a C# & C++ programmer for serveral years, and used FSUIPC succesfully in a cuple proyects too.

 

However now I´m facing something that is driving me crazy, I am creating a programm that detects where you´re flying and the timezone and then it should introduce the hour(time) into FSX/P3D via FSUIPC. But I could not find any variable to do that.

 

Kind Regards!

And congratulations to Pete for this awesome "programm".

Share this post


Link to post
Share on other sites

However now I´m facing something that is driving me crazy, I am creating a programm that detects where you´re flying and the timezone and then it should introduce the hour(time) into FSX/P3D via FSUIPC. But I could not find any variable to do that.

 

Why are you doing this? Do you not want FS to take care of the time zones for you?

 

All the date and time values are in the Offsets list from 0238 to 0248 inclusive. How could you miss them? And how could such a thing drive you crazy?

 

Pete

Share this post


Link to post
Share on other sites

Basically FS doesn't work good at all regarding timezones. So basically what I am trying to do is something like FS Real Time. Thanks for the offsets it seems I didn't see them despite being used the search function (I'm getting old :p)

Thank you very much Pete!

Share this post


Link to post
Share on other sites

May I ask you Pete, if there is a way to store variables such as speed, altitude, longitude, latitude.... And then introduce them into FS in case of crash. Just something like AutoSave?

 

Regards!

Share this post


Link to post
Share on other sites

May I ask you Pete, if there is a way to store variables such as speed, altitude, longitude, latitude.... And then introduce them into FS in case of crash. Just something like AutoSave?

 

Yes, of course, by program. Read the values, save them, write them back when needed.

 

If you look in the Lua examples provided in the FSUIPC Documents folder, you'll find an example of using Lua plug-ins to link two PCs running FS and making one slave of the other, mimicking its flight.  See "SlaveServer", "MasterClient". You'd need to do something basically similar but storing the values instead of sending them over a Network link.

 

Of course, if you want to do your own autosave just save a flight and load it when needed. You can do that with FSUIPC or direct with SimConnect.

 

BTW since none of your questions are really specifically related to the use of Paul Henty's .NET DLL you should really be posting in the Support Forum itself, not in this subforum. Please do so further further support questions.

 

Pete

Share this post


Link to post
Share on other sites

Hello again, guys:

 

This time my question has to do with C# Programming. I finally managed to make the timezones´ function work. However I am having trouble with the AutoSave, this is what I´ve done. But unfortunately it´s not working. May Paul can help me:

 

First I declare the offsets that I´m going to store & update, then I create variables with to store the value of the first ones. And then inside the setLastValues() method I store the value of them.(This method is called each time the user presses a button/the timer_tick passes through it)

// We declare the offsets:
        Offset<long> Latitude = new Offset<long>("update",0x0560);
        Offset<long> Longitude = new Offset<long>("update", 0x0568);
        Offset<long> Altitude111 = new Offset<long>("update", 0x0570);
        Offset<int> Airspeed = new Offset<int>("update", 0x02BC);
        Offset<int> Heading = new Offset<int>("update", 0x0580);

        long lastlatitude;
        long lastlongitude;
        long lastaltitude;
        int lastairspeed;
        int lastheading;

        private void setLastValues()
        {
            this.lastlatitude = this.Latitude.Value;
            this.lastlongitude = this.Longitude.Value;
            this.lastaltitude = this.Altitude111.Value;
            this.lastairspeed = this.Airspeed.Value;
            this.lastheading = this.Heading.Value;
        }

2. This is the code on the button "Save Flight"

private void pictureBox3_Click(object sender, EventArgs e)
        {
            if (pictureBox5.Enabled == false && asave.Enabled != true)
            {
                asave.Start();
                asave.Enabled = true;
                asave.Interval = 600000;
                
                
                asave_Tick(null, null);

                asave.Tick += new EventHandler(chour_Tick);
                setLastValues();
            }
            else
            {
                MessageBox.Show("You have to connect to FS first!!/You can click just once");

            }
        }

Code on the Timer_Tick:

private void asave_Tick(object sender, EventArgs e)
        {
                        
            setLastValues();
                        
        }

And finally, code in the "Load Flight" button:

private void pictureBox4_Click(object sender, EventArgs e)
        {
            
            this.Latitude.Value = lastlatitude;
            this.Longitude.Value = lastlongitude;
            this.Airspeed.Value = lastairspeed;
            this.Altitude111.Value = lastaltitude;
            this.Heading.Value = lastheading;
            FSUIPCConnection.Process("update");                               
       }

But for some reason it is not working, it does load the wrong latitude, longitude, speed and everything gets loaded wrong.

 

I can´t realize on what I´m doing wrong.

 

Thank you very much!!

 

 

Regards!!

Edited by jmcken

Share this post


Link to post
Share on other sites

I can't see anywhere in the code that you call process() before setting the values. Process() needs to be called to get the current values from FSX.

 

Unless you have a more suitable place I would put this in setLastValues().

private void setLastValues()
{
   FSUIPCConnection.Process("update");
   this.lastlatitude = this.Latitude.Value;
   this.lastlongitude = this.Longitude.Value;
   this.lastaltitude = this.Altitude111.Value;
   this.lastairspeed = this.Airspeed.Value;
   this.lastheading = this.Heading.Value;
}

See if that helps.

 

Paul

Share this post


Link to post
Share on other sites

Thank you very much Paul! But still no Luck... I´m still facing the same issue... When I click the "Load Flight" button the latitude & lon is setted up to 0.

 

Kind regards!

Share this post


Link to post
Share on other sites

Strange. I can't see anything obviously wrong with the code.

 

Use the debugger (set breakpoints) to see where the values are wrong.

 

Check the values being saved in setLastValues(). In pictureBox4_Click() check the values of the this.lastlatitude etc.

 

Also use the FSUIPC logging to log FSUIPC Writes. Then see exactly what value is being written to FSX. (If you log to the console and run FSX in window mode you can see this in realtime).

 

Paul

Share this post


Link to post
Share on other sites

Okay using the console, I could find that the lastxxxxvalue is "0" in all cases(Latitude, Longitude, Heading, Speed....) I don´t know where the issue might be...

 

PS:

 

This is how I inserted the Process() in the method:

private void setLastValues()
        {
            FSUIPCConnection.Process();
            this.lastlatitude = this.Latitude.Value;
            this.lastlongitude = this.Longitude.Value;
            this.lastaltitude = this.Altitude111.Value;
            this.lastairspeed = this.Airspeed.Value;
            this.lastheading = this.Heading.Value;
        }

But I also kept the other Process() in the "Load Button" "click-event"

FSUIPCConnection.Process("update");

Edit: Ok, I think I found the mistake. Presumably the method setLastValues() is not being called at least when you hit the button "Save Flight"(pictureBox3)... Do you know why might be that happening?

Share this post


Link to post
Share on other sites

The problem is you're calling Process() without the group name, so it's not updating (reading) the "update" group which has all your relevant offsets. I did give you the correct code with the group name included (post #7).

private void setLastValues()
{
   FSUIPCConnection.Process("update");
   this.lastlatitude = this.Latitude.Value;
   this.lastlongitude = this.Longitude.Value;
   this.lastaltitude = this.Altitude111.Value;
   this.lastairspeed = this.Airspeed.Value;
   this.lastheading = this.Heading.Value;
}

Paul

Share this post


Link to post
Share on other sites

Presumably the method setLastValues() is not being called at least when you hit the button "Save Flight"(pictureBox3)... Do you know why might be that happening?

 

 

 

No, looks fine to me. Have you tried putting a breakpoint in pictureBox3_click() and stepping though to see if it's called?

 

Two reasons I can think of that the line is not getting called:

 

1. The click of the pictureBox3 is not actually bound to pictureBox3_click(). Check in the form designer - properties of pictureBox3.

 

2. There is an exception being thrown in an earlier line. You would normally see this, unless you're catching the exception somewhere and not reporting it.

 

Paul

Share this post


Link to post
Share on other sites

No, looks fine to me. Have you tried putting a breakpoint in pictureBox3_click() and stepping though to see if it's called?

 

Two reasons I can think of that the line is not getting called:

 

1. The click of the pictureBox3 is not actually bound to pictureBox3_click(). Check in the form designer - properties of pictureBox3.

 

2. There is an exception being thrown in an earlier line. You would normally see this, unless you're catching the exception somewhere and not reporting it.

 

Paul

 

 

Paul you made my day!!!

 

I could fix it.... problem was  this one.

asave_Tick(null, null);
 
                asave.Tick += new EventHandler(chour_Tick);

I copied this piece of code from other tick that I had to control the timezone part and I forgot to change the chour_Tick to asave_Tick.... Working now!

 

Thank you very very much"!!!

Share this post


Link to post
Share on other sites

They're great tools those scripts

 

By the way Pete, is it possible to make them work in UDP ?, to set one (of course) MasterClient with many SlaveServers reading from it ?

 

I don't know, but I don't see any reason why the Lua libraries should stop you doing whatever you liked on the Network. Maybe the Lua reference data on their website will help?

 

Pete

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.