Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hi Pete,

Wondering if you could take a quick look at this lua test script. It works but I am little worried because I cannot test a final version, for another sim in which i dont have and...
In the final version there will be only 5 or 6 "x" arrays, but there will be around 15 - 20 filled indexes in each. ( haven't got that far yet )
What I am trying to do is monitor the same offset (a few of them) but direct the function call to somewhere else, cancel the other function calls, all based on a selector knob.
Am I treading on thin ice here?

Thanks in advance,
Roman

function s(offset, value)
	ipc.display("it worked for function 1 (s), the val = " .. tostring(ipc.readUB(0x4211)) .. ", index = " .. tostring(ipc.readUB(0x4210)), 2)
end

function t(offset, value)
	ipc.display("it worked for function 2 (t), the val = ".. tostring(ipc.readUB(0x4211)) .. ", index = " .. tostring(ipc.readUB(0x4210)), 2)
end

-- function a(flag), an old test
function a(offset, value)

	cmds = {
	function() event.offset(0x4211, "UB", "s") end,  
	function() event.cancel("s") end,
	function() event.offset(0x4211, "UB", "t") end,  
	function() event.cancel("t") end
	}
	
	if value == 0 then
		x = {1, 0, 0, 1} -- s is on, t is off
	elseif value == 1 then
		x = {0, 1, 1, 0} -- s is off, t is on
	elseif value == 2 then
		x = {0, 1, 0, 1} -- both off	
	elseif value == 3 then
		x = {1, 0, 0, 1} -- s is on, t is off		
	elseif value == 4 then
		x = {0, 1, 0, 1} -- both off
	elseif value == 5 then
		x = {0, 1, 1, 0} -- s is off, t is on
	elseif value == 6 then
		x = {1, 0, 0, 1} -- s is on, t is off
	else -- 7
		x = {0, 1, 0, 1} -- both off
	end
	
	for i = 1, #x do
		if x[i] == 1 then
			cmds[i]()
		end
	end	
	
end

function b(flag)
	ipc.writeUB(0x4211, (ipc.readUB(0x4211) + 1))
end

function c(flag)
	ipc.writeUB(0x4211, 0)
end

-- event.flag(1, "a") -- toggle, turn listener on/off (an old test - successful) 
event.offset(0x4210, "UB", "a") -- controlled by Offset Byte Cyclic Increment, offset = 4210, param = 1/7
event.flag(2, "b") -- increase val offset
event.flag(3, "c") -- clear val offset

 

Posted
1 hour ago, spokes2112 said:

Wondering if you could take a quick look at this lua test script. It works but I am little worried because I cannot test a final version, for another sim in which i dont have and...
In the final version there will be only 5 or 6 "x" arrays, but there will be around 15 - 20 filled indexes in each. ( haven't got that far yet )
What I am trying to do is monitor the same offset (a few of them) but direct the function call to somewhere else, cancel the other function calls, all based on a selector knob.

It looks like you are mastering more esoteric stuff in Lua than I've ever done. Arrays of functions eh? I didn't know that was possible. But if it works on one sim how's another sim going to change it? The Lua interpreter is the same.

As an aside, If i needed to do what you'd describe I'd have just had the one master function, always called for the offset, which in turn calls a whatever function is currently selected, like with a C/C++ switch statement..

Pete

 

 

Posted

Pete,

Thanks so much for taking a peek at it. I guess what I will do is make 2 versions, the one above & another using the "switch" style, of which I have already started but it is just a huge mess! The one above is so much more elegant. If that one has inherent bugs I will have a fallback.
On last question if I may -
I have 2 listeners with different offsets, pointing to the same function :
event.offset(0x0001, "UB", "GoHere") 
event.offset(0x0002, "UB", "GoHere")  
Will the following cancel both?
event.cancel("GoHere")
I am assuming it does, hope so.

Thanks again and..
To you & John - Merry Christmas 🎄
P.S. 

6 hours ago, Pete Dowson said:

Arrays of functions eh? I didn't know that was possible.

FSUIPC Lua Library, pg 23, the title page of the events library, 3rd paragraph - 
"The function name provided as a string in the Lua event function calls can now be functions in tables."
This gave me a clue, then it was off to that interweb thingy and search for examples in arrays.
I believe a table is an array, it is how it is accessed which is different. Similar to JS.. (could be way off on this)
  

Posted
11 hours ago, spokes2112 said:

I have 2 listeners with different offsets, pointing to the same function :
event.offset(0x0001, "UB", "GoHere") 
event.offset(0x0002, "UB", "GoHere")  
Will the following cancel both?
event.cancel("GoHere")
I am assuming it does, hope so.

Ah, that I'm not sure about. You'd need to test. It's possible that it searches for one then, when found, does it and ends. If so you'd need two cancels. Or two separate functions with one calling the other.

11 hours ago, spokes2112 said:

To you & John - Merry Christmas 🎄

Thank you! You too, and thanks for all the contributions and help you offer other users on this Forum!

Pete

 

  • Like 1
Posted
10 hours ago, Pete Dowson said:

It's possible that it searches for one then, when found, does it and ends.

Thanks for the help! That was it.

Roman

function b(flag)
	ipc.display("TEST", 1)
end

function c(flag)
	event.cancel("b") -- if the only one active, worked up to flag 1
	event.cancel("b") -- if added then it worked thru flag 2
	event.cancel("b") -- added the 3rd, worked on all
end


event.flag(1, "b") -- test
event.flag(2, "b") -- test
event.flag(3, "b") -- test
event.flag(4, "c") -- turn off

 

Posted
14 minutes ago, spokes2112 said:

Thanks for the help! That was it.

Okay, so it only cancels the first.

Perhaps it should carry on and look for other matches. Never thought of cases like yours where there'd be multiple events for the same function.

But I'll leave it to John to decide whether to change that. I assume there's no good use for doing it specifically one at a time?  Mind you, I'm not even sure what order they'd be seen in -- probably first registered to last.

Pete

 

Posted
15 hours ago, Pete Dowson said:

Perhaps it should carry on and look for other matches. Never thought of cases like yours where there'd be multiple events for the same function.

As there is no way to specify which event to cancel, I think it should really continue and cancel all registered events for that function.
I'll update this at some point, most probably for the next release (FSUIPC6 & 7 only though).

John

  • 2 weeks later...
Posted
On 12/23/2020 at 11:52 AM, John Dowson said:

I think it should really continue and cancel all registered events for that function.
I'll update this at some point, most probably for the next release (FSUIPC6 & 7 only though).

This has now been implemented in FSUIPC6/7 and will be included in the next release of those products.

John

  • Like 1

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.