Jump to content
The simFlight Network Forums

Some help with LUA needed


Recommended Posts

Hello all,
I hope someone with extensive LUA knowledge here, is prepared to take a look at my Lua. It is used to play announcements in the various stages of flight.

 I found it somewhere on the net, so I did not write it myself and frankly I'm not very smart with LUA programming. The strange thing is that before I updated my FSUIPC version to 4.945a it used to work without problems but now it does not anymore.

The Lua is started with the Sim (prepar3d) via ipcready.
Sadly I have not updated FSUIPC for a long time and can't trace which version I used before, otherwise I might be able to go back to that version....

I also have the log attached, but it shows no errors though. By looking at the log, the LUA seems to run, but it doesn't.

Only when I stop the LUA through some FSUIPC programmed buttons and then restart it, it runs (for a while)....

 

Anyway, here it is. I hope someone can look it over and maybe find something incorrect.

Thanks in advance,

Jaap

-- Welcome Announcement, will start sound if door closed. Note: Door must be open first!--

wcflag=0
doortime=0
function welcome(offset,value)
    ground=ipc.readUW("0366")	--only on ground
	if (ipc.readUW("0366") == 1) then
	 repeat	  -- wait for door open, if open break
	  ipc.readUB("3367")
	  ipc.sleep(1000)
	 until (ipc.readUB("3367") > 0 )
		 while (ipc.readUB("3367") > 0) do -- wait for door closed
	            ipc.readUB("3367")
				ipc.sleep(1000)
		 end
		    if (value > 0) and (wcflag == 0) then
			 sound.play("E:\\Prepar3D\\sound\\CD_Welcome.wav") --Welcome Message
			 ipc.sleep(60000)
			 sound.play("E:\\Prepar3D\\sound\\CD_SafetyMessage.wav") --Safety Message
			 wcflag=1 --don`t repeat sound
			end

	else
	wcflag=1
	end
end

-- Climb Announcements

cflag=0
function climbp(offset,value)
vspeed=ipc.readSW("0842") * -3.28084
groundalt=ipc.readUD("0020") * 3.28084 /256
alt=ipc.readUD("0574") * 3.28084
altogr=alt - groundalt
   	if (ipc.readUB("0609") == 0) and (cflag == 0) and (tbflag == 0) then 	-- Piston Engine?
	 if
	 (alt > 5000) and (vspeed > 300) and (altogr > 2000) then 	-- no sightseeing
         sound.play("E:\\Prepar3D\\sound\\paxsign.wav")
	 ipc.sleep(3000)
	 sound.play("E:\\Prepar3D\\sound\\CD_CapClimb.wav")	-- climb announcement
	 cflag=1
	 end
	end
end

ctflag=0
function climbt(offset,value)
vspeed=ipc.readSW("0842") * -3.28084
groundalt=ipc.readUD("0020") * 3.28084 /256
alt=ipc.readUD("0574") * 3.28084
altogr=alt - groundalt
  	if (ipc.readUB("0609") == 5) and (ctflag == 0) and (tbflag == 0) then	-- Turbo Engine?
	 if
	 (alt > 11000) and (vspeed > 900) then
         sound.play("E:\\Prepar3D\\sound\\paxsign.wav")
	 ipc.sleep(3000)
	 sound.play("E:\\Prepar3D\\sound\\CD_CapClimb.wav")
	 ctflag=1
	 end
	end
end

cjflag=0
function climbj(offset,value)
vspeed=ipc.readSW("0842") * -3.28084
groundalt=ipc.readUD("0020") * 3.28084 /256
alt=ipc.readUD("0574") * 3.28084
altogr=alt - groundalt
   	if (ipc.readUB("0609") == 1) and (cjflag == 0) and (tbflag == 0) then	-- Jet?
	 if
	 (alt > 10000) and (vspeed > 1200) then
         sound.play("E:\\Prepar3D\\sound\\paxsign.wav")
	 ipc.sleep(3000)
	 sound.play("E:\\Prepar3D\\sound\\CD_CapClimb.wav")	-- climb announcement
	 cjflag=1
	 end
	end
end


--Descent announcements

dpflag=0
function descentp(offset,value)
vspeed=ipc.readSW("0842") * 3.28084
groundalt=ipc.readUD("0020") * 3.28084 /256
alt=ipc.readUD("0574") * 3.28084
altogr=alt - groundalt
  	if (ipc.readUB("0609") == 0) and (dpflag == 0) and (tbflag == 0) then 	-- Piston Engine?
	 if
	 (alt < 6000) and (vspeed > 300) and (altogr > 2000) then 
         sound.play("E:\\Prepar3D\\sound\\paxsign.wav")
	 ipc.sleep(3000)
	 sound.play("E:\\Prepar3D\\sound\\CD_CapDescent.wav")	-- descent announcement
	 dpflag=1
	 end
	end
end

dtflag=0
function descentt(offset,value)
vspeed=ipc.readSW("0842") * 3.28084
groundalt=ipc.readUD("0020") * 3.28084 /256
alt=ipc.readUD("0574") * 3.28084
altogr=alt - groundalt
  	if (ipc.readUB("0609") == 5) and (dtflag == 0) and (tbflag == 0) then	-- Turbo Engine?
	 if
	 (alt < 13000) and (vspeed > 900) then
         sound.play("E:\\Prepar3D\\sound\\paxsign.wav")
	 ipc.sleep(3000)
	 sound.play("E:\\Prepar3D\\sound\\CD_CapDescent.wav")	-- descent announcement
	 dtflag=1
	 end
	end
end

djflag=0
function descentj(offset,value)
vspeed=ipc.readSW("0842") * 3.28084
groundalt=ipc.readUD("0020") * 3.28084 /256
alt=ipc.readUD("0574") * 3.28084
altogr=alt - groundalt
  	if (ipc.readUB("0609") == 1) and (djflag == 0) and (tbflag == 0) then	-- Jet Engine?
	 if
	 (alt < 18000) and (vspeed > 1200) then
         sound.play("E:\\Prepar3D\\sound\\paxsign.wav")
	 ipc.sleep(3000)
	 sound.play("E:\\Prepar3D\\sound\\CD_CapDescent.wav")	-- descent announcement
	 djflag=1
	 end
	end
end

-- Final announcement

fplflag=0
function finalp(offset,value)
vspeed=ipc.readSW("0842") * 3.28084
groundalt=ipc.readUD("0020") * 3.28084 /256
alt=ipc.readUD("0574") * 3.28084
altogr=alt - groundalt
  	if (ipc.readUB("0609") == 0) and (fpflag == 0) then	-- Piston Engine?
	 if
	 (altogr < 2000) and (vspeed > 300) and (dpflag == 1) and (tbflag == 0) then	-- coming from descent
	 sound.play("E:\\Prepar3D\\sound\\paxsign.wav")
	 ipc.sleep(3000)
	 sound.play("E:\\Prepar3D\\sound\\CD_BeforeLanding.wav")	-- final announcement
	 dpflag=1
	 end
	end
end

ftflag=0
function finalt(offset,value)
vspeed=ipc.readSW("0842") * 3.28084
groundalt=ipc.readUD("0020") * 3.28084 /256
alt=ipc.readUD("0574") * 3.28084
altogr=alt - groundalt
  	if (ipc.readUB("0609") == 5) and (ftflag == 0) then  -- Turbo Engine?
	 if
	 (altogr < 4000) and (fpflag == 1) and (vspeed > 800)	and (tbflag == 0) then	--coming from descent
	 sound.play("E:\\Prepar3D\\sound\\paxsign.wav")
	 ipc.sleep(3000)
	 sound.play("E:\\Prepar3D\\sound\\CD_BeforeLanding.wav")	-- final announcement
	 ftflag=1
	 end
	end
end

fjflag=0
function finalj(offset,value)
vspeed=ipc.readSW("0842") * 3.28084
groundalt=ipc.readUD("0020") * 3.28084 /256
alt=ipc.readUD("0574") * 3.28084
altogr=alt - groundalt
  	if (ipc.readUB("0609") == 1) and (fjflag == 0) then	-- Jet Engine?
	 if
	 (altogr < 4000 ) and (vspeed > 1000) and (djflag == 1) and (tbflag == 0) then	 --coming from descent
	 sound.play("E:\\Prepar3D\\sound\\paxsign.wav")
	 ipc.sleep(3000)
	 sound.play("E:\\Prepar3D\\sound\\CD_BeforeLanding.wav")	-- descent announcement
	 fjflag=1
	 end
	end
end
--LUA calls for events FSUIPC

event.offset(0x0366,"UW","welcome")

event.offset(0x0842,"SW","climbp")
event.offset(0x0842,"SW","climbt")
event.offset(0x0842,"SW","climbj")
event.offset(0x0842,"SW","descentp")
event.offset(0x0842,"SW","descentt")
event.offset(0x0842,"SW","descentj")
event.offset(0x0842,"SW","finalp")
event.offset(0x0842,"SW","finalt")
event.offset(0x0842,"SW","finalj")
--global variables
--end script--

~

 

 

Log.txt

Link to comment
Share on other sites

Jaap, At first glance it appears that something is amiss near the end of the first function. You will notice that the color of the statements

change in that area and from then on all text is green.

 

In my lua plugins in edit mode, comments are green and offsets and parameters are green. The rest of the text in the

statements is black, or in the case of "qoute enclosed text", red.

 

Although, when I copy and paste your script and open it in edit mode on my system, the colors of

the variious elements appear to be correct. I'll have to scan the scropt in more detail to see if I can

spot any errors but it is late here on the US west coast so I won't be able to do anything tonight.

 

 Paul

 

EDIT: Just did a quick scan and the only thing I see that MIGHT be an issue is where there

         are division operations such as:  3.28084 /256

 

          In all my scripts there are no spaces between the numerator, the / and the denominator.

          It just may be that the Lua parser/engine or whatever may have changed from an earlier

          version in FSUIPC4 and that the space is now causing trouble.

 

          I ran the debugger here on my system and it didn't toss out any errors so I'm at a loss

          for recommendations.

 

          Also, you say that if you start the script manually that it does run "for awhile". That would tend

         to say that the script itself may be fine but some external influence is causing the issues. Maybe

          a lack of resources after a period of time.

Link to comment
Share on other sites

Hello Paul,

Thanks for looking at my LUA. I was puzzled about the colors in code window too, but had no Idea what it was for. So you can see by the colors when there is something faulty? You say you use a "Lua editor"? I write them in notepad, and that has no colors... What editor do you use? Maybe it can make my life a bit easier.

Indeed if I run the script manually, it starts, but only the two first messages play, and sometimes, out of the blue, a descent or final message plays?! I run the FSUIPC console window next to my flightsim, and no errors appear but it sort of "hangs" in lines 8,9 and 10.

I have fiddled around with the file and came up with a new one, and that seems to run fine so far, but only when I start it manually....

I did change the division operations from 3.28084 /256 to ​3.28084/256 without space.

Maybe you or someone else can check this file, and see if I did something wrong or too complicated.....

-- Welcome Announcement, will start when door is closed. Door must be open first!--

wcflag=0
function welcome(offset,value)
    Battery=ipc.readUD("281C")	
	if (ipc.readUD("281C") == 1) then
	 repeat	  
	  ipc.readUB("3367")
	  ipc.sleep(6000)
	 until (ipc.readUB("3367") > 0 )
		 while (ipc.readUB("3367") > 0) do 
	            ipc.readUB("3367")
				ipc.sleep(6000)
		 end
		    if (value > 0) and (wcflag == 0) then
                         ipc.sleep(3000)
                         sound.play("E:\\Prepar3D\\sound\\CA_paxsign.wav")
	                 ipc.sleep(3000)
			 sound.play("E:\\Prepar3D\\sound\\CA_Welcome.wav") --Welcome Message
			 ipc.sleep(60000)
                         sound.play("E:\\Prepar3D\\sound\\CA_paxsign.wav")
	                 ipc.sleep(3000)
			 sound.play("E:\\Prepar3D\\sound\\CA_SafetyMessage.wav") --Safety Message
			 wcflag=1 --don`t repeat sound
			end
	else
	wcflag=1
	end
end

-- Climb Announcements

climbflag=0
function climb(offset,value)
vspeed=ipc.readSW("0842") * -3.28084
groundalt=ipc.readUD("0020") * 3.28084/256
alt=ipc.readUD("0574") * 3.28084
   	if (ipc.readUB("0609") == 1) and (climbflag == 0) then		
	 if
	 (alt > 8000) and (vspeed > 1500) then
         sound.play("E:\\Prepar3D\\sound\\CA_paxsign.wav")
	 ipc.sleep(3000)
	 sound.play("E:\\Prepar3D\\sound\\CA_CapClimb.wav")	-- climb announcement
	 climbflag=1
	 end
        end
end


--Descent announcements

descendflag=0
function descent(offset,value)
vspeed=ipc.readSW("0842") * 3.28084
groundalt=ipc.readUD("0020") * 3.28084/256
alt=ipc.readUD("0574") * 3.28084
  	if (ipc.readUB("0609") == 1) and (descendflag == 0) then	
	 if  
         (alt < 15000) and (vspeed > 1200) then
         sound.play("E:\\Prepar3D\\sound\\CA_paxsign.wav")
	 ipc.sleep(3000)
	 sound.play("E:\\Prepar3D\\sound\\CA_CapDescent.wav")	-- descent announcement
	 descendflag=1
	 end
	end
end

-- Final announcement

finalflag=0
function final(offset,value)
vspeed=ipc.readSW("0842") * 3.28084
groundalt=ipc.readUD("0020") * 3.28084/256
alt=ipc.readUD("0574") * 3.28084
  	if (ipc.readUB("0609") == 1) and (finalflag == 0) then	
	 if  
         (alt < 6000 ) and (vspeed > 1000) and (descendflag == 1) then
	 sound.play("E:\\Prepar3D\\sound\\CA_paxsign.wav")
	 ipc.sleep(3000)
	 sound.play("E:\\Prepar3D\\sound\\CA_BeforeLanding.wav")	-- descent announcement
	 finalflag=1
	 end
	end
end

-- After Landing Announcement

landingflag=0
function landing(offset,value)
    flaps=ipc.readUD("0BDC")
   Landed=ipc.readUW("0366") 
  	if (ipc.readUW("0366") == 1) and (landingflag == 0) and (finalflag == 1 ) then	
	 if  
         (flaps == 16383) then
	 sound.play("E:\\Prepar3D\\sound\\CA_paxsign.wav")
	 ipc.sleep(3000)
	 sound.play("E:\\Prepar3D\\sound\\CA_AfterLanding.wav")	-- After Landing announcement
	 landingflag=1
	 end
	end
end

--LUA calls for events FSUIPC

event.offset(0x281C,"UD","welcome")
event.offset(0x0842,"SW","climb")
event.offset(0x0842,"SW","descent")
event.offset(0x0842,"SW","final")
event.offset(0x0BDC,"UD","landing")

--global variables
--end script--






 

I'm also trying to add a seatbelt announcement that should play when the seatbelt sign has been turned off, but I can't seem to find the right offset for that. I also use Project Magenta RJ Glass cockpit, and that shows when the signs are on or off. Maybe someone can help me with that too?

 

Thanks in advance,

Jaap

Link to comment
Share on other sites

Japp, I downloaded the Lua package and installed that. It includes the editor it seems.

 

This is a separate download completely independant of FSUIPC4.

 

http://www.lua.org/download.html

 

I simply downloaded the Lua package, did the install and that was it. When I right-click on a lua script

the pop-up menu lists among other things "Edit script..."

 

That is the editor that I use. It will also check syntax and pick up some errors.

 

As for the seatbelt indication, have you tried this offset:

 

341C  1  No smoking alert switch (1 = on, 0= off
341D  1  Seat belts alert switch (1 = on, 0 = off)

 

I notice that you use the form  ipc.readxx("number")

I assume that "number" is the offset, however I always use the form

ipc.readxx(0xoffset),  no quotes but the offset preceded by 0x indicating a hex value.

Apparently the form you use in acceptable as some of the script works, it is just that

I have never seen the statements written that way.

 

   Paul

Link to comment
Share on other sites

Hi Paul,

Thanks! Have the editor now, that's a little bit easier to work with.

I already tried those two offsets you suggest, but it seems Project Magenta handles it in a different way, so they did nothing.

However  I found an Offset in the Project Magenta part of the offset lists:

Offset    Size    Use

04FE       2       PFD

Various (Read Only)

Bit 0 Windshear

1 Below G/S

2 Caution

3 Warning

4 Stab Out Of Trim (Boeing only and TrimMax/TrimMin have to be set)

6 Eight Mode ND Active

7 Seatbelt Sign

8 No Smoking Sign

9 Weather Radar (Captain)

10 EGPWS/Terrain (Captain)

11 TCAS Active (Captain)

13 TCAS WARNING

14 TCAS ALERT

 

 and I tried this in between what I already had:

-- Seatbelt announcementseatbeltflag=0function seatbelt(offset,value)seatbelt=ipc.readSW("04FE")landing=ipc.readUW("0366")   	if (ipc.readSW ("04FE") == 128) and (landing == 0) then			 sound.play("E:\\Prepar3D\\sound\\CA_paxsign.wav")	 ipc.sleep(3000)	 sound.play("E:\\Prepar3D\\sound\\CA_seatbelts off.wav")		 seatbeltflag=1	 end        end--LUA calls for events FSUIPCevent.offset(0x281C,"UD","welcome")event.offset(0x0842,"SW","climb")event.offset(0x0842,"SW","descent")event.offset(0x0842,"SW","final")event.offset(0x0BDC,"UD","landing")event.offset(0x04FE,"SW","seatbelt")--global variables--end script--

But all I get is an Error: Attempt to calll a number value....

I must admit that all that bit and byte Word and DWord stuff puzzles me very much, so I probably did something horribly wrong, but I just don't see it.

Ideas?

 

Thanks,

Jaap

Link to comment
Share on other sites

I believe that 

event.offset(0x04FE,"SW","seatbelt")

should be

event.offset(0x04FE,"UW","seatbelt")

 

On the bit, byte, etc front.

A byte is 8 bits  made up of 1's and 0's such as '10101010'

A WORD is 2 bytes or 16 bits

A DWORD or Double Word is 2 words or 32 bits

A SIGNED word has the sign in bit 15, the 'left most bit'  (bits are numbered 0 to 15 in a word, right to left) thus the

range of values represented is -32768  (1000 0000 0000 0000) to +32767 (0111 1111 1111 1111)

 

If you are running Win7, open the calculator and under the 'View' tab select 'Programmer' to easily convert

from decimal to hex, octal or binary.

 

Also note that your statement above, if (ipc.readSW ("04FE") == 128) and (landing == 0) then   

will not evaluate properly. Also, you should be using 'ipc.readUW' as 04FE is an UNSIGNED WORD.

 

When you read the value in 04FE, you need to isolate bit 7, the seatbelt bit, and then test its state.

Doing a logical AND operation with the contents of 04FE and 128 (80 hex) will give you only bit 7 having the posibility of being "1", or

the value or that AND operation being 128. Perhaps something like the  lines below:

 

seatbeltflag=0
function seatbelt(offset,value)
seatbelt=ipc.readSW("04FE")  --you have read the word containing the seatbelt bit into a variable here
landing=ipc.readUW("0366")

 

SeatBeltBit = logic.And(seatbelt, 128)    -- 'Logical And' the variable with decimal 128, which should return a "128" or "0"

if (SeatBeltBit == 128) and (landing == 0) then

 

It may be possible to rewrite those last two lines as:

 

if (logic.And(seatbelt, 128) == 128) and (landing == 0) then

 

I've never had need to use the bitwise and logical operators Lua functions (logicAnd(x,y) etc)

so I'm just using my best guess here :)

 

Have a look at the "Logic Library", page 11 of the Lua Library PDF in the FSUIPC4 Documents folder.

 

   Paul

Link to comment
Share on other sites

Paul,

Yes, you are absolutely right about the SW that should have been an UW! Not that I figured it out myself but shortly after my last post I came across a LUA somewhere that used the same offset and that said UW, so I already changed that.

If I understand your explanation right a Signed Word is capable of using negative numbers and an Unsigned Word is not?

I have some LUA documents opened here, but there's so much to absorb.......

 

To make testing easier i have narrowed my lua down to this, as the rest works ok:

-- Seatbelt announcement

function seatbelt(offset,value)
seatbelt=ipc.readUW("0x04FE")  
landing=ipc.readUW("0x0366")
if (logic.And(seatbelt, 128) == 128) and (landing == 0) then	
	 sound.play("E:\\Prepar3D\\sound\\CA_seatbelts off.wav")	
	 end       
end

event.offset(0x04FE,"UW","seatbelt")

--global variables
--end script--

And I have tried a number of variations, but still get the same error. I am baffled, cause usually I can get things working by asking for advice and looking around how others have solved things, but I can't put my finger on this one. It's probably something stupid we're overlooking....

 

@Jorge: In now have LUAEdit and that does the same thing. Also trying the debug function seems buggy. It finds errors in perfectly working lua's even the ones from the FSUIPC bundle. But in any case I don't have to count the lines anymore!

 

Thanks for helping!

Jaap

Link to comment
Share on other sites

Jaap, remove the quotes from the offset field when using HEX notation.0xFFFF.  Quotes go

around the offset stated as a string.  "FFFF"

 

seatbelt=ipc.readUW("0x04FE")  <----- remove the quotes or make this  (04FE)
landing
=ipc.readUW("0x0366")   <----- ditto

 

 Paul

Link to comment
Share on other sites

I removed the Quotes and also tried the other form of notation Paul, but none of it was succesfull.

I have been trying and trying for almost two days now and can't get it to work. Tried a lot off combinations and conditions, but it will not work.

It should be so simple:

All I want is a message being played when the seatbelt switch is set to off. That's all. How hard can it be? Am I so stupid that I can't figure it out?

I know there would be easier ways to do it, but to operate the seatbeltsign in Project Magenta's RJ Glass displays, I already assigned that switch via FSUIPC Buttons&Switches. Otherwise I could assign a small lua, that just plays a message, to that switch.....

 

I have tried to keep it as simple as I could think off:

-- Seatbelt announcement

function seatbelt(offset,value)
seatbelt=ipc.readUW(0x04FE)  
if (logic.And(seatbelt, 128) == 0) then	
	 sound.play("E:\\Prepar3D\\sound\\CA_seatbelts off.wav")	
	 end       
end

event.offset(0x04FE,"UW","seatbelt")

I tried 0x080 instead of 128, and ~=128 or ==0 or ~=0 etc. But the closest I got was when the seatbelt switch was already off when I started the script, and the message was played! So I tried moving things around a bit, but it didn't get better.

My holidays are now over and I'm quite fed up with it. The rest of my script is working OK, only not when started from within ipc.ready.lua.

 

Thanks for helping Paul.

 

Maybe when Pete is back he can solve it for me.

I'm done for now!

Regards,

Jaap

 

Any other suggestions: Welcome!

Link to comment
Share on other sites

All I want is a message being played when the seatbelt switch is set to off. That's all. How hard can it be? Am I so stupid that I can't figure it out?

 

Did you try Lus trace/logging to see why it didn't work -- just a checkbox in the FSUIPC logging tab? Did you  monitor the offset 04FE to see if was indeed changing? Did you even simply check the FSUIPC log to see if an error was reported?

 

I have tried to keep it as simple as I could think off:

 

 

Since the value is provided alwady, as a parameter, slightly simpler would be:

 
-- Seatbelt announcement
function seatbelt(offset,seatbelt)
   if logic.And(seatbelt, 128) == 0 then    
     sound.play("E:\\Prepar3D\\sound\\CA_seatbelts off.wav")    
   end
end

event.offset(0x04FE,"UW","seatbelt")

Pete

 

Link to comment
Share on other sites

Hello Pete,

 

Thanks for jumping in....

 

Did you try Lus trace/logging to see why it didn't work -- just a checkbox in the FSUIPC logging tab? Did you  monitor the offset 04FE to see if was indeed changing? Did you even simply check the FSUIPC log to see if an error was reported?

Yes I did, I even had the Console log opened so that I could see what was going on. On some occasions I had a Lua Error: Attempt to calll a number value , which made it kind of clear what I did wrong, but on other occasions the LUA just ended without doing anything I expected, and without any errors.

 

So I tried the solution you gave me and of course that works flawlessly, (GRRR)

Then I looked back to the things I tried before an came across this one:

-- Seatbelt announcement
function seatbelt(offset,seatbelt)
   Landed=ipc.readUW("0366")
   if Logic.And(seatbelt, 128) == 0 and (ipc.readUW("0366") == 0) then
     ipc.sleep(3000)    
     sound.play("E:\\Prepar3D\\sound\\CA_seatbelts off.wav")    
   end
end

Apart from a little addition, this looks almost the same, but I bet that you'll spot the fault in the wink of an eye.... I took me a while, but then I spotted it too: ​​

Logic.And instead of logic.And. Oh my....... (bad words come to mind..)!.

 

So that is solved now.

Which brings me to my next question, the actual reason I started this topic: Why does the completed LUA not run correctly when started from within ipc.ready.lua? Are there limitations to the amount of LUA's that can be started from there, and can they interfere with each other when the same functions or offsets are used? And why did it run before updating from FSUIPC 4.939n (I'm not quite sure about that version) to 4.945a?

 

When all LUA's are started automatically the LUA in question runs also but does this:

 

   185673 LUA.1: E:\Prepar3D\Modules\Lear45.lua:10
   185673 LUA.1: E:\Prepar3D\Modules\Lear45.lua:11
   185673 LUA.1: E:\Prepar3D\Modules\Lear45.lua:12
   185673 LUA.1: E:\Prepar3D\Modules\Lear45.lua:13
   191679 LUA.1: E:\Prepar3D\Modules\Lear45.lua:11
   191679 LUA.1: E:\Prepar3D\Modules\Lear45.lua:12
   191679 LUA.1: E:\Prepar3D\Modules\Lear45.lua:13
   197685 LUA.1: E:\Prepar3D\Modules\Lear45.lua:11
   197685 LUA.1: E:\Prepar3D\Modules\Lear45.lua:12
   197685 LUA.1: E:\Prepar3D\Modules\Lear45.lua:13
   200820 LUA.2: Offset Change event: calling "Doors" in "E:\Prepar3D\Modules\GoFlightleds.lua"
   200820 LUA.2: E:\Prepar3D\Modules\GoFlightleds.lua:44
   200820 LUA.2: Local: val = 0
   200820 LUA.2: E:\Prepar3D\Modules\GoFlightleds.lua:47
   200836 LUA.2: E:\Prepar3D\Modules\GoFlightleds.lua:49
   200836 LUA.2: Waiting for an event in "E:\Prepar3D\Modules\GoFlightleds.lua"
   203691 LUA.1: E:\Prepar3D\Modules\Lear45.lua:11
   203691 LUA.1: E:\Prepar3D\Modules\Lear45.lua:15
   203691 LUA.1: E:\Prepar3D\Modules\Lear45.lua:29
   203691 LUA.1: Waiting for an event in "E:\Prepar3D\Modules\Lear45.lua"

 

In steps 11, 12 and 13 it's waiting for the door to be closed. Then when it is, it steps from 11 to 15 to 29 which is the end of the first part, but no sounds are played. (the LUA in use is the one from Post #3).

 

 When I remove the Lear45.lua from ipc.ready.lua and assign this LUA via FSUIPC buttons&switches to a switch, it runs perfectly together with the two LUA's that were started from within ipc.ready.lua (GFPower.lua and GoFlightleds.lua).

I find that very strange. Maybe you can tell what is going wrong?

 

In any case, thanks for helping and your patience.

And sorry for the lenghty topic...

 

Regards,

Jaap

Link to comment
Share on other sites

Which brings me to my next question, the actual reason I started this topic: Why does the completed LUA not run correctly when started from within ipc.ready.lua? Are there limitations to the amount of LUA's that can be started from there, and can they interfere with each other when the same functions or offsets are used?

 

No.

 

 

In steps 11, 12 and 13 it's waiting for the door to be closed. Then when it is, it steps from 11 to 15 to 29 which is the end of the first part, but no sounds are played. (the LUA in use is the one from Post #3).

 

The log is all very well, but being a small extract I can't see what Lua threads 1 and 2 are, and certsainly you've shown me no Lua file with a "Doors" function, so how can I possibly comment?

 

 

 When I remove the Lear45.lua from ipc.ready.lua and assign this LUA via FSUIPC buttons&switches to a switch, it runs perfectly together with the two LUA's that were started from within ipc.ready.lua (GFPower.lua and GoFlightleds.lua).

I find that very strange. Maybe you can tell what is going wrong?

 
Again, I do not have enough information.
 
Pete
Link to comment
Share on other sites

Ok, I understand.

In that case, here is the complete log and all the lua's I use:

 I stopped the simulator when I saw that the Lear45.lua did not play the soundfiles.

Thanks for helping,

Jaap

 

Thanks for the files, but what am I looking for?

 

What is the precise question? Relate it to the files. I assume you've gone through the Lua trace and determined where you think something has gone wrong? You can't possibly expect me to look through over 30000 lines of logging not knowing what I'm supposed to be looking for? In other words, what sounds are you expecting at what stage in the log?

 

Does the Lear45 one work when loaded in ipcReady by itself? If not, why not do a trace with only that running? Maybe it would be easier to deal with a trace a bit less than 30000 lines?

 

BTW, rather than use "ipc.macro" to run a Lua plug-in from a Lua plug-in you would be better using the dedicated function for this, "ipc.runlua". Also I note that the ipcReady file does not correspond to the one you actually used for the Trace because one of the plug-ins is commented out.

 

Also, in the Lear one you have these events:

 

event.offset(0x281C,"UD","welcome")
event.offset(0x0842,"SW","climb")
event.offset(0x0842,"SW","descent")
event.offset(0x0842,"SW","final")
event.offset(0x0BDC,"UD","landing")
event.offset(0x04FE,"UW","seatbelt")
 
Why three separate events all for changes in 0842? Don't you think that's a wee bit inefficient?  Looking at the functions all called every time a little change occurs in 0842 they all pretty much do many similar things.
 
It's also inefficient to do this:
 
vspeed=ipc.readSW("0842")
 
in the first line of the function in which the value of the offset you are reading, again, is supplied as  the parameter value. Why read it again?
 
Why do you have ipc.sleep(3000) BEFORE each sound.play?
 
Finally, it would help immensely if you Monitor the offsets you are using for events in Lear45 -- ie 281C, 0842, 0BDC and 04FE. Use the Monitor facilty in the Logging tab ad select "normal log". Then changes in those will be shown within the trace.

 

Pete

Link to comment
Share on other sites

I have just found this line in your Log:

 

   103382 LUA.1: E:\Prepar3D\Modules\Lear45.lua:108
 
That is the line in the Lear45.lua file playing a sound:
 
     sound.play("E:\\Prepar3D\\sound\\CA_seatbelts off.wav")    
 

Is that what you are not hearing? If so, then additionally to what I said just above, could you add these lines to the [General] section in your FSUIPC4.INI:

 

Debug=Please

LogExtras=x20

 

then run the sim and do the test -- the log should then contain details of the Sound calls made, and maybe why they failed.

 

Also, try moving your 3 second sleep lines to AFTER the sound requests. I think they are useless beforehand, but may allow the sound action to start when given time after.

 

Pete

Link to comment
Share on other sites

Hello Pete,

I needed to wait on the weekend before I could startup the sim and do some testing again...

 

Thanks for the files, but what am I looking for?

 

What is the precise question? Relate it to the files. I assume you've gone through the Lua trace and determined where you think something has gone wrong? You can't possibly expect me to look through over 30000 lines of logging not knowing what I'm supposed to be looking for? In other words, what sounds are you expecting at what stage in the log?

I am trying to determine why my lua does not work when started from within ipc.ready.lua, but does work when started from a via FSUIPC assigned button.

When the lua is started from ipc.ready it does some checking but finally jumps right to line 29, which is the end of the first function. After that nothing happens when opening and closing the doors. When I start the lua by hand (ipc.ready disabled), it works perfectly and starts playing the sounds beginning at line 14 as soon as the door is closed.

I check the logfiles after every try, and during testing I always have the console log opened, so I can see what is going on.

 

 

Does the Lear45 one work when loaded in ipcReady by itself? If not, why not do a trace with only that running? Maybe it would be easier to deal with a trace a bit less than 30000 lines?

Lear45.lua is now the only used one. It does not run, and I did the trace but all it tells my untrained eye, is that somehow it skips the lines where it should check when the doors are opened or closed, starting at line 7. It just jumps to line 29.

 

 

BTW, rather than use "ipc.macro" to run a Lua plug-in from a Lua plug-in you would be better using the dedicated function for this, "ipc.runlua". Also I note that the ipcReady file does not correspond to the one you actually used for the Trace because one of the plug-ins is commented out.

Ok, I have changed my ipc.ready.lua as you suggested (attached as .txt). It is correct that the Lear45.lua was commented out. I did that to test how the lua would run when started by hand. I should have changed that back before posting.

 

 

Also, in the Lear one you have these events:

 

event.offset(0x281C,"UD","welcome")
event.offset(0x0842,"SW","climb")
event.offset(0x0842,"SW","descent")
event.offset(0x0842,"SW","final")
event.offset(0x0BDC,"UD","landing")
event.offset(0x04FE,"UW","seatbelt")
 
Why three separate events all for changes in 0842? Don't you think that's a wee bit inefficient?  Looking at the functions all called every time a little change occurs in 0842 they all pretty much do many similar things.
 
It's also inefficient to do this:
 
vspeed=ipc.readSW("0842")
 
in the first line of the function in which the value of the offset you are reading, again, is supplied as  the parameter value. Why read it again?

I understand what you're saying, it does look inefficient, but I just don't see how to improve that. I've been at it almost all weekend, and tried various combinations but I only made things worse or not working at all. I did simplify the Lear45.lua as much as I could (attached as .txt), and it runs fine when started by hand. But if you could help me simplify it even more I would be much obliged.

 

 

Why do you have ipc.sleep(3000) BEFORE each sound.play?
 
Finally, it would help immensely if you Monitor the offsets you are using for events in Lear45 -- ie 281C, 0842, 0BDC and 04FE. Use the Monitor facilty in the Logging tab ad select "normal log". Then changes in those will be shown within the trace.

The first ipc.sleep in line 15 is done because of another sound (door closing) being generated by the sim would not be drowned by the pax sign sound in line 16. The other ipc.sleep commands are done for more or less the same reasons: not to drown other sounds.

 

I have done the monitoring of offsets 0366 ( ground), 0BDC (flapsetting), 3367(doors) and 04FE(seatbeltsign from ProjectMagenta)

Logfiles attached as .txt

 

 

I have just found this line in your Log:

 

   103382 LUA.1: E:\Prepar3D\Modules\Lear45.lua:108
 
That is the line in the Lear45.lua file playing a sound:
 
     sound.play("E:\\Prepar3D\\sound\\CA_seatbelts off.wav")    
 

Is that what you are not hearing? If so, then additionally to what I said just above, could you add these lines to the [General] section in your FSUIPC4.INI:

 

Debug=Please

LogExtras=x20

 

then run the sim and do the test -- the log should then contain details of the Sound calls made, and maybe why they failed.

This line is no longer relevant, because the whole lua has been changed. The seatbelt.wav was playing however, but it only works when my other PC's running PM RJ, PM MCP and PM CDU are connected with WideFS.


I added the above lines to my FSUIPC General section in the .ini.

 

The log files are attached and their names should be self explanatory.

 I hope you have enough information to see what I am overlooking.

 

Thanks for your patience and best regards,

Jaap

FSUIPC4log with LUA Autostart.txt

FSUIPC4log with LUA Manual start.txt

ipcready.txt

Lear45.txt

FSUIPC4log with LUA Autostart.txt

FSUIPC4log with LUA Manual start.txt

ipcready.txt

Lear45.txt

Link to comment
Share on other sites

When the lua is started from ipc.ready it does some checking but finally jumps right to line 29, which is the end of the first function.

 

As the Lua is first executed, it executes all of the lines, in turn, jumping over functions altogether (because they have to be explicitly called). The functions will be called from the event, and the event will occur not before the complete first execution, right to the end.

 

Checking your latest logs, the difference is immediately obvious. (Much easier to see without all the other plug-ins intervening).

 

When running from ipcReady, which is early, it seems the "onground" flag has not yet been set, so your routine "welcome" jumps around a lot of code and sets "finalflag=1". Then, next time, when the "onground" flag is set, finalflag is NOT zero, so again the code is skipped.

 

In other words your logic is not right. You only want to set finalflag IN the main code, after you've processed the change to "on ground",  You don't want to set it to 1 on the "else" condition. 

 

Not sure about wcflag. Not checked through enough to see what that's for.

 

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.