Jump to content
The simFlight Network Forums

How to force an ipc.macro to do it's full Job


Recommended Posts

Hello,

In the attached Files, i try to run a Lua Script that runs another Script insisde via the ipc.macro Command.

When running the Main Script, it starts the SubScript. But it seems, that the SubScript would be leaved before it has done it's full Job and a little later it will be called again by the Main Script. So, my Question is, if it is possible, to force the SubScript to do it's full Job without leaving and starting again. And if it is possible, what do i have to do?

Short Description of the desired WorkFlow for the PMDG B777F (newest Version for P3Dv4)

B777F is set to Electrical Power up for using the CDUs. 

FlightLog.lua read the Reg of the Aircraft, here D-ALFA, turns on the CDU FS Actions Menu and then turn on the CDU Fuel Page. This will work without any Problems. Then it calls the Macro Lua:PMDGFuelInput. In that LuaFile, a File has to be read and then the Input of the Values into the CDU begins. There seems to be the Problem, that the whole Workflow of the Scripts will leave the SubScript before all is done. Further it seems, that it will be called again, and again, and again.

Hope, i could express the Problem the right Way. Any Help will be highly appreciated. Thanks in Advance.

 

Joachim 

FlightLog.lua

PMDGFuelInput.lua

PMDGInitialFuelQty.txt

Link to comment
Share on other sites

4 hours ago, Airbuspilot said:

When running the Main Script, it starts the SubScript. But it seems, that the SubScript would be leaved before it has done it's full Job and a little later it will be called again by the Main Script. So, my Question is, if it is possible, to force the SubScript to do it's full Job without leaving and starting again. And if it is possible, what do i have to do?

Assuming your "subscript" is being started by an ipc.runlua command, then it starts it its own thread and is completely independent or how it started. there's no "parent-child" relationship going on. Starting a plug-in in this way it identical to starting it directly, via an assignment or an entry in a macro or [Auto] section in the FSUIPC INI file.

So your "subscript" is terminating itself for some reason.

I'm sorry, but I really am not going to study your Lua code and debug it for you myself. I suggest you use either the debug/trace facilities provided to determine what is happening, or at least add some logging to work it out.

Pete

 

Link to comment
Share on other sites

I didn't asked you, to study and debug my Files. But maybe an other User will have the Time, to look in there and have a Hint for me.

10 hours ago, Pete Dowson said:

I'm sorry, but I really am not going to study your Lua code and debug it for you myself

BTW: Such Comments aren't really helpful.

I used  the Logging Features of FSUIPC but they don't give me a Trace of the Problem. You can be sure, that i only post for Help in this Forum, if i have absolutely no other Option. However, thanks for your Answer.

Joachim 

Link to comment
Share on other sites

42 minutes ago, Airbuspilot said:

I used  the Logging Features of FSUIPC but they don't give me a Trace of the Problem.

The logging you need is the Debug/Trace one, in the Logging Tab, on the left. That gives you line by line trace, by line number, and also variable values when they change.

43 minutes ago, Airbuspilot said:

BTW: Such Comments aren't really helpful.

But you seemed to have posted full sources with no pointers as to what is done where or what you think is really going wrong. If it is your code you should understand what it is doing. Therefore you must have an idea where in all that code things are not going the way you expect.

By posting as you did with only a vague description of a problem which i don't even understand it definitely seemed as if you expected me to analyse your work, which is why i said what i did. I am not out to hurt or insult you as you seem to think!

You didn't even say how either of those Lua plug-ins are started (and there doesn't appear to be a "runlua" in either of them). One of them (FlightLog) loops forever or until its flag 0 is set, and the other simply does a series of things then exits.

46 minutes ago, Airbuspilot said:

You can be sure, that i only post for Help in this Forum, if i have absolutely no other Option.

Well, it is nice to be treated as a "last resort" I must say! :-(

I tried to help by pointing out that there are lots of facilities to help you work out what is going on. When you've done that and you think it is a problem in the Lua interpreter or FSUIPC's implementation then by all means show me why and I'll attend to it. But you need to narrow things down a lot first! 

As well as the built-in trace mechanisms I often simply insert "ipc.log" lines to log important information in different places, or just to indicate the code has reached this point. I make these conditional on a variable like "debug", declared at the start, being set to true or false, so I can leave them in and simply turn them on or off as needed. There are therefore some very good ways of determining the sequence and results.

Pete

 

Link to comment
Share on other sites

4 hours ago, Pete Dowson said:

Well, it is nice to be treated as a "last resort" I must say! :-(

Sorry, but you got me completely wrong at this Point. I meant, that i tried Hours for Hours to solve the Problem by my self before posting for Help in the Forum.

5 hours ago, Pete Dowson said:

I tried to help by pointing out that there are lots of facilities to help you work out what is going on. When you've done that and you think it is a problem in the Lua interpreter or FSUIPC's implementation then by all means show me why and I'll attend to it. But you need to narrow things down a lot first! 

I am sure, that it is not a Problem of Lua or FSUIPC. It is a Problem with my Coding maybe due to a lack of Knowledge. But again, i didn't ask you directly to study and debug my Code. Sure, i am glad if you could help me. But if you had no Time or don't like to help this Way, it is okay. So, i hope any other User could take some Time and will try to help.

 

5 hours ago, Pete Dowson said:

But you seemed to have posted full sources with no pointers as to what is done where or what you think is really going wrong.

Seems, i didn't clearly expressed the Problem in the initial Post? I thought, i did. 

5 hours ago, Pete Dowson said:

You didn't even say how either of those Lua plug-ins are started (and there doesn't appear to be a "runlua" in either of them)

In the initial Post, i described, that i start the "SubScript" with the ipc.macro Command. Meanwhile i tried it with runlua - in fact with the same Results. Will try to find my self, where the Fault in my Script is.

Joachim

Link to comment
Share on other sites

1 hour ago, Airbuspilot said:

Sure, i am glad if you could help me. But if you had no Time or don't like to help this Way, it is okay. So, i hope any other User could take some Time and will try to help.

I think, as I said, you need to provide more than just the code. what is going on, and where? Where is it going wrong? That's the point. The code as presented is just that, very obscure sequences of lines which mean nothing to me and I suspect also nothing to other readers. You need to do a bit more work is assisting those you hope to assist you.

1 hour ago, Airbuspilot said:

In the initial Post, i described, that i start the "SubScript" with the ipc.macro Command.

Yes, and that is in the loop which never ends. So it will be repeated over and over if the conditions apply. And each time it is restarted, the previous one, if still running, will be terminated and started again.

The one you are starting will end when it has done the little it has to do. There's nothing to stop it.

So, what is stopping your loop starting it over and over?

Pete

 

 

Link to comment
Share on other sites

21 hours ago, Pete Dowson said:

So, what is stopping your loop starting it over and over?

In Fact, this Part of the Script is an "One Time only" Job. So, i deleted the looping Code and it will be doing, what i want it to do.

Maybe you could provide a little Help with the following Problem. When starting P3Dv4, loading the Aircraft and starting a Scenario, FSUIPC5.log is logging. Starting my Script with the JoystickButton, FlightLog.log is logging. That's really great to figure out some of the Problems. If i found and corrected a Part of the Code, i will try it again. I learned with the Command "LuaKillAll" all the Luas will be stopped from running. But starting the corrected Script again, it will not work right, because the Variables are not reset even if i reset them in the Code manually. So, i have to cancel and restart the Sim every Time, after a Correction of my Script. Also the Re-Simconnect will not solve this Problem. It would be very, very helpful, if you could provide a Way that makes the Restart of the Sim unnecessary. Thanks in Avance.

Joachim 

Link to comment
Share on other sites

1 hour ago, Airbuspilot said:

If i found and corrected a Part of the Code, i will try it again. I learned with the Command "LuaKillAll" all the Luas will be stopped from running. But starting the corrected Script again, it will not work right, because the Variables are not reset even if i reset them in the Code manually

What variables are you talking about, and why is it you expect them to be "reset"?

If you mean values which are from Prepar3D values, naturally they won't be "reset" just because you restart Lua plug-ins.

If you mean variables local to you plug-ins, those will be "nil" (same as undefined) until you set them with a value.

If you mean the Global variable facilities in Lua, those, as must surely be clear from their name, are Global. They are for communication between separate plug-ins which may not even be running as the same time -- they are also used for plug-ins which run sequentially, perhaps to retain status details of external hardware.  If you are using those and you want them to start with specific values, then you have to set those values. But note that they don't "belong" to your plug-ins. Any plug-in using the same names will access the same variables.

Pete

 

Link to comment
Share on other sites

16 hours ago, Pete Dowson said:

If you mean the Global variable facilities in Lua, those, as must surely be clear from their name, are Global. They are for communication between separate plug-ins which may not even be running as the same time

Yes, i mean those global Variables, that are controlling the Workflow of my Scripts. Meanwhile i solved it by my self. There was a Value that i had set the wrong Way.

Please allow me some little last Questions. Maybe you could have a Look at the attached, real small Script. Those issued "ipc.sleep" Commands are pausing the Workflow? I mean. that i.E. after the runlua on Line 12, there is a Pause in the Workflow, before the Condition on Line 14 is checked for controlling the further Workflow? I am assuming, that a Value of 1000 represents 1 Second. Is this assuming right or could it vary depending on the CPU Speed i.E.?

Joachim 

FlightLog.lua

Link to comment
Share on other sites

15 minutes ago, Airbuspilot said:

Maybe you could have a Look at the attached, real small Script. Those issued "ipc.sleep" Commands are pausing the Workflow? I mean. that i.E. after the runlua on Line 12, there is a Pause in the Workflow, before the Condition on Line 14 is checked for controlling the further Workflow? I am assuming, that a Value of 1000 represents 1 Second. Is this assuming right or could it vary depending on the CPU Speed i.E.?

No need to look at your program to answer your question. The ipc.sleep command is actually documented, thus:

 

"ipc.sleep(msecs) Suspends execution of the plug-in for the given number of
milliseconds, allowing other threads to operate with less hindrance."


So 1000 is 1000 milliseconds = 1 second. You really need to use the FSUIPC Lua Library documentation as a reference for such questions.

The function actually uses the Windows function Sleep. It guarantees that much delay -- but that's a minimum, as other loading on the same PC may delay it a little before the thread regains control. There's no guarantee of any time except it won't be less than what you specify. If you want to check how long it was just use the ipc.elapsedtime  before and after to measure it.

Pete

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • 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.