Jump to content
The simFlight Network Forums

Recommended Posts

Hey guys, I need some help with my lua script which reads a FSUIPC offset. Its not working as intended and I'm not sure why

Essential I need a message to be displayed when I switch the Landing Lights ON. But I only want this to happen when I am airborne, not on the ground. To check this I read the FSUIPC offset 0366 to see if the plane is airborne. However I must have coded the ipc.readSW(offset) incorrectly, because the wrong message is being displayed even when I am on the ground.

Here is the code:

function runMessage(event, param)

	local gnd = ipc.readSW(0366)
	
	if (gnd == 1) then
		ipc.display("you are on the ground and the offset was read correctly", 1, 0 )
		return
	end

	if (gnd == 0) then
		ipc.display("Landing Lights ON: .. message here", 1, 0 )		
		return
	end
end

event.control(66059, "runMessage") -- lights on

 

Thanks

Link to comment
Share on other sites

 

You aren't confusing the 'delay' and 'color' parameters are you? You entry has color set to 1 and delay set to 0.

ipc.display may not like a delay value of '0'. Try changing that to'1' and see if it works.

 

Also, there is no need for paran's around the gnd == 1 or gnd == 0 entries in the 'if' statement.

What is the purposes of the 'return' statement?  There is nothing to return.

I would write that function like this:

function runMessage(event)

    local gnd = ipc.readSW(0366)  
    if gnd == 1 then
        ipc.display("you are on the ground and the offset was read correctly", 1, 1 )       
    elseif gnd == 0 then
        ipc.display("Landing Lights ON: .. message here", 1, 1 )        

    end
end

Another thing that may be an issue is the use of the ... message here". If that is meant to be some previously defined message then it should read:

ipc.display("Landing Lights ON "..message, 1, 1)

This would display whatever the 'message' was defined as. If that wasn't your intent then I would not use the double periods just to insure that they aren't being misinterpreted.

 Paul.

 

  • Upvote 1
Link to comment
Share on other sites

7 hours ago, Gypsy Baron said:

I would write that function like this:

function runMessage(event)

    local gnd = ipc.readSW(0366)  
    if gnd == 1 then
        ipc.display("you are on the ground and the offset was read correctly", 1, 1 )       
    elseif gnd == 0 then
        ipc.display("Landing Lights ON: .. message here", 1, 1 )        

    end
end

Thanks for helping Paul.  Just a couple of clarifications:

 

First the offset for the ipc.readSW is wrong. it is NOT 366 (decimal, but 0x366 (i.e hexadecimal. ALL offsets are documented in hex. If you want to use decimal then it would be 870.

Your code, Paul, is otherwise good but it would be a little simpler with the "else if gnd == 0" as a simple "else". Though since the standard convention for boolean variables is that any non-zero is 'true', whilst 0 is 'false', so the test should be for 0 first, then just "else" for all other cases. That's the 'safe' way.

7 hours ago, Gypsy Baron said:

ipc.display may not like a delay value of '0'. Try changing that to'1' and see if it works.

Sorry it isn't specific in the docs, but a delay of 0 is the same as omitting it -- it means no delay is applied, the message stays on display till replaced or cleared by a null string.

7 hours ago, Lifenbaucher said:

However I must have coded the ipc.readSW(offset) incorrectly

Yes, you used the wrong offset. See above.

Pete

 

  • Upvote 1
Link to comment
Share on other sites

Thanks guys you've certainly helped. I've got it all working now

@Baron - I put the purposely put the 'delay' parameter at zero so it wouldn't disappear. But i needed the text to be white, hence the 'colour' param = 1

This is my cleared up code, in case anyone needs an example

function runMessage(event, param)

	local gnd = ipc.readSW(0x366)
	
	if (gnd == 0) then
		ipc.display("Landing Lights Toggled:\n message here xxxxxxxxxxxxxxx...", 1, 0 )
		return
	else
		return
	end
	
end

event.control(66059, "runMessage") -- lights on

 

Link to comment
Share on other sites

Hey, I was hoping to get some further help with lua. Since ive discovered this functionality I have found myself setting up scripts for all sorts of useful things...

I wanted to create script whereby, when the simulator pauses (particularly when PMDG auto pauses at TOD), the P3D window minimizes to taskbar. This way the GPU can power down to 0% usage, saving heat and electricity. This is what I have written so far:

function minimize(event, param)

	ipc.display("Pause was toggled", 1, 15 )
	ext.state("prepar3d.exe", EXT_MIN)	
	
end

event.control(65794, "minimize") --pause on

I have a feeling that I'm not use the ext.state() function correctly. Could someone clarify I'm doing it the right way, please?

Thanks

Link to comment
Share on other sites

4 hours ago, Lifenbaucher said:

I wanted to create script whereby, when the simulator pauses (particularly when PMDG auto pauses at TOD), the P3D window minimizes to taskbar.

I'm not sure it works on the process in which it is running, but even if it does I don't think it will if P3D is running in full screen mode. Are you using it in Windowed mode so that Max/Min operate?

Pete

 

Link to comment
Share on other sites

On 4/18/2017 at 4:45 PM, Pete Dowson said:

I'm not sure it works on the process in which it is running, but even if it does I don't think it will if P3D is running in full screen mode. Are you using it in Windowed mode so that Max/Min operate?

Pete

 

Yeah I run it on windowed mode all the time

Have I coded the script correctly though?

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.