Jump to content
The simFlight Network Forums

Combine Lua Vals in Macros?


Recommended Posts

Hello Mr Dowson,

Is it possible to combine Lua Vals in Macros?

With "normal" macros I can combine it in this way:

1=Battery

1.1=...

1.2=...

With the Lua Vals I tried the same:

1=Battery

1.1=L:LeftBatSwitch=TOG

1.2=L:RightBatSwitch=TOG

ut that does not work....

Any Ideas?

thank you, Guenter

Link to comment
Share on other sites

H

Is it possible to combine Lua Vals in Macros?

Looking further down your message I see you mean "L:vars" not "Lua" values -- Lua is a separate language used to provide plug-in code for FSUIPC (and many other games and simulators for that matter). "L:vars" are the local gauge variables with names prefixed by L: in FS to denote them as Local (I think).

With the Lua Vals I tried the same:

1=Battery

1.1=L:LeftBatSwitch=TOG

1.2=L:RightBatSwitch=TOG

ut that does not work....

It does not work because "Battery" is the name of the macro, and "L:LeftBatSwitch" etc are also names of macros. The L:var macros use the L:var identifier as the name, whereas in button, keypress and mouse macros you choose the name.

If you want more than one macro action from a button or keypress you would need to either edit the INI file Buttons assignments to assign the different actions to the same keypress/button, or write a Lua plug in to action the multiple macro operations and then assign your button or keypress to the Lua action which then appears in the drop-down.

Regards

Pete

Link to comment
Share on other sites

thanks for answering (that was realllly fast)

I solved it via the *.ini editing

Here's an other question concerning to the Lua Programming.

I've got the commands for the A2A B377 e.g. IntercoolerFlap1 which regulates the IntercoolerFlaps (as the name says)

Now I can assign them to a button (with repeat) in a macro with

2=L:IntercoolerFlap1=INC

3=L:IntercoolerFlap1=DEC

The range of the flaps is 1 to 100.

Works perfectly....

Now my question:

Is it possible in a way to get them to one of my Saitek throttles? So that I can regulate the flaps with a throttle.

I've managed it of course by assigning two ranges via the axis assigement (ranges for action): in the upper half of the throttle range the IC-Flaps rise up, in the lower 50% they go down.

But is it possible to get the values 1 to 100 out of the throttles to regulate the IC-Flaps?

I don't think so, but I better ask, maybe you know a solution...

thank you,

guenter

Link to comment
Share on other sites

But is it possible to get the values 1 to 100 out of the throttles to regulate the IC-Flaps?

You can write a little Lua plug-in which receives your throttle value as a parameter, scales it to fit your range 1-100, and writes the L:var value with the result. When the Lua plug-in is saved in the Modules folder, assign the lever axis to it in the normal axis assignment tab in FSUIPC.

Alternatively you could simply try assigning direct to your L:var macro in the axis assignment TAB, scaling the value by using the simple arithmetic multiplier and divider facility. See the Advanced User's document, the section at the end of the Axis Assignments section entitled "Additional parameters to scale input axis values". You haven't got the power of the Lua language to help scale exactly there, but you might get close to what you want.

Regards

Pete

Link to comment
Share on other sites

  • 3 weeks later...

Hello, its me again... ;-)

I bring up this old thread because I'm still stuck on this "problem"

(I mean the initial post theme with combining LuaVars in Macros, not the last question here)

As above I'd like to get two commands together:

C66587, 8028 ; this plays a sound file in the PMDG J41 (don't ask why Rotor-Brake plays a sound file; PMDG does everything with the rotorbrake parameters)

L:LeftBatSwitch=TOG ; this toggles the Battery switch ON and OFF

As you stated above I can't combine these two commands into a Macro, e.g.

1=Batt

1.1=C66587, 8028

1.2=L:LeftBatSwitch=TOG

I'l see myself that it wouldn't work

But if I create a LUA file for the Battery switch and for all the switches coming after this, I get tons of separate LUA files for each switch in this plane.

Do you see my problem? A macro is much more handy as you write several commands in one file, named with numbers.

Do you think something like that would be possible also with LUA commands in the future?

Or do you have a solution that I just have one LUA file for different switch-commands?

Next question is, that I already now how to handle the LuaVrs in a Lua file, but I have no clue if it is possible and how to handle the comand for the rotor_brake (e.g. C66587, 8028) in a Lua File?

What ould you do to combine the Lua Var and the C66587 command for one button?

Except the possibility to assign it direct in the FSUIPC4.ini...

Hope you understood me...

And yes, I was flying yesterday without programming :wink: :lol:

Link to comment
Share on other sites

As you stated above I can't combine these two commands into a Macro, e.g.

1=Batt

1.1=C66587, 8028

1.2=L:LeftBatSwitch=TOG

Why not just have a macro for the L:var setting and make two assignments to the same button or switch? Multiple assignments to buttons is the usual method, the one that preceded Macros and Lua files for many years.

Do you see my problem? A macro is much more handy as you write several commands in one file, named with numbers.

Do you think something like that would be possible also with LUA commands in the future?

Lua commands can already be combined like that, because Lua files are referenced by number via the Lua Files reference list built up in the INI file. You are mixing up "L:vars", the local gauge variable, with Lua -- two completely different subjects.

The problem with L:vars is that you most certainly need the name, and building up an index for every possible L:var which might occur on any user system is a forbidding prospect. Some add-on airliners have hundreds. Worse, they may use similar or the same names for different functions, so you need an index per plane. Ugh!

Or do you have a solution that I just have one LUA file for different switch-commands?

As described in the FSUIPC Lua documentation, Lua programs are started with the value of "ipcPARAM" pre-set to the parameter value you enter into the Parameter field for the calling Key or Button press assignment, and you can use that parameter for whatever you like -- maybe an FS control number, or maybe just an index to switch to different parts in your Lua program.

Next question is, that I already now how to handle the LuaVrs in a Lua file, but I have no clue if it is possible and how to handle the comand for the rotor_brake (e.g. C66587, 8028) in a Lua File?

FS controls are sent to FS by the "ipc.control(...)" command. Please scan down the list of facilities in the Lua Library documentation.

Regards

Pete

Link to comment
Share on other sites

UUUhhh heavy stuff in english language ;-)

i've understood the first part, ok.

For the second there're stil questions

As described in the FSUIPC Lua documentation, Lua programs are started with the value of "ipcPARAM" pre-set to the parameter value you enter into the Parameter field for the calling Key or Button press assignment, and you can use that parameter for whatever you like -- maybe an FS control number, or maybe just an index to switch to different parts in your Lua program.

I need an example for this, please.

Now I have understood that a LUA file with different commands could look like this:

Inside a file which is called example.lua

ipcPARAM=1

ipc.writeLvar("L:pmdg_hide_yoke", 0)

ipc.writeLvar("L:pmdg_hide_yoke", 0)

ipc.writeLvar("L:pmdg_hide_yoke", 0)

ipcPARAM=2

ipc.writeLvar("L:pmdg_hide_yoke", 1)

ipc.writeLvar("L:pmdg_hide_yoke", 2)

ipc.writeLvar("L:pmdg_hide_yoke", 3)

(its just examples, don't look at the commands as they all they same...)

As I understand it I can now choose via the FSUIPC menu for button 1 "lua example" with parameter 1

and for button 2 "lua example" with parameter 2.

Is that correct?

Is the code correct or how do I have to handle the ipcPARAM???

heavy stuff, heavy stuff :wink:

I'm very interested in this programming stuff, so forgive me my daily questions...

Link to comment
Share on other sites

As described in the FSUIPC Lua documentation, Lua programs are started with the value of "ipcPARAM" pre-set to the parameter value you enter into the Parameter field for the calling Key or Button press assignment, and you can use that parameter for whatever you like -- maybe an FS control number, or maybe just an index to switch to different parts in your Lua program.

I need an example for this, please.

Okay. Why not what you wanted, above? You wanted to do this:

1=Batt

1.1=C66587, 8028

1.2=L:LeftBatSwitch=TOG

So, write a Lua program with only these lines:

ipc.control(66587, ipcPARAM)
lbat = ipc.readLvar("L:LeftBatSwitch")
ipc.writeLvar("L:LeftBatSwitch", 1 - lbat)

Then assign a button to this Lua program, entering 8028 in the Parameter field. The 8028 is the value then in ipcPARAM. You can have as many buttons calling this one Lua program as you like, each with a different parameter.

Now I have understood that a LUA file with different commands could look like this:

Inside a file which is called example.lua

ipcPARAM=1

ipc.writeLvar("L:pmdg_hide_yoke", 0)

ipc.writeLvar("L:pmdg_hide_yoke", 0)

ipc.writeLvar("L:pmdg_hide_yoke", 0)

ipcPARAM=2

ipc.writeLvar("L:pmdg_hide_yoke", 1)

ipc.writeLvar("L:pmdg_hide_yoke", 2)

ipc.writeLvar("L:pmdg_hide_yoke", 3)

(its just examples, don't look at the commands as they all they same...)

As I understand it I can now choose via the FSUIPC menu for button 1 "lua example" with parameter 1

and for button 2 "lua example" with parameter 2.

No, no ,no. A line like "ipcPARAM = 1" sets the value 1 to the variable ipcPARAM. So it does no good for you at all. You need to test the value already in ipcPARAM, thus:

if ipcPARAM == 1 then 
   ipc.writeLvar("L:pmdg_hide_yoke", 0)
   ipc.writeLvar("L:pmdg_hide_yoke", 0)
   ipc.writeLvar("L:pmdg_hide_yoke", 0)
elseif  ipcPARAM == 2 then
   ipc.writeLvar("L:pmdg_hide_yoke", 1)
   ipc.writeLvar("L:pmdg_hide_yoke", 2)
   ipc.writeLvar("L:pmdg_hide_yoke", 3)
end

I'm very interested in this programming stuff, so forgive me my daily questions...

Take a look at the Lua website. There's lots of help there. I cannot teach folks Lua, there are better sources! If you are really interested I'd recommend the book "Programming in Lua".

Regards

Pete

Link to comment
Share on other sites

Thanks again, Pete!

Maybe it looks very simple to you, but the following code took me 2 hours to create.

But now I can TOGGLE the two battery switches of the J41

Great :lol:


-- LEFT Battery switch TOGGLE
if ipcPARAM == 1 then   


	lbat = ipc.readLvar("L:LeftBatSwitch")

	if lbat == 1 then
   	ipc.writeLvar("L:LeftBatSwitch", 0)
	ipc.control(66587, 8028)

	elseif lbat == 0 then
   	ipc.writeLvar("L:LeftBatSwitch", 1)
	end


-- RIGHT Battery switch TOGGLE
elseif ipcPARAM == 2 then
	rbat = ipc.readLvar("L:RightBatSwitch")

	if rbat == 1 then
   	ipc.writeLvar("L:RightBatSwitch", 0)
	ipc.control(66587, 8028)

	elseif rbat == 0 then
   	ipc.writeLvar("L:RightBatSwitch", 1)
	end
end

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.