Jump to content
The simFlight Network Forums

Lua variable concatenation


Recommended Posts

Hi.

The control will not send when I use concatenated variable in ipc.control. 

cdukey = L_CDU_5 works perfectly but cdukey = "L_CDU_" .. n does not despite ipc.display showing L_CDU_5.

function SET(n)
Click_L = 0x20000000 -- Left mouse click
L_CDU_5 = 69632+358 -- Left CDU 5 Key Command

cdukey = "L_CDU_" .. n

ipc.control(cdukey, Click_L)
ipc.display(cdukey)

end

SET(5)

What am I doing wrong?

Link to comment
Share on other sites

ipc.control takes the control number (n) as a parameter, as an integer. You are passing a string, Even though the sting holds the name of a local variable which holds a number, it is the string that is passed to the function, not the variable value. This should work:
    

ipc.control(L_CDU_5 , Click_L)
Link to comment
Share on other sites

20 minutes ago, Keight said:

yes as I wrote this works but I am trying to set the "5" part of the  "L_CDU_5" by variable n.

But you cannot do this, as cdukey is a string - just because that holds the variable name, it is not that variable.
You could try with:

ipc.control(_G[cdukey], Click_L)

see https://stackoverflow.com/questions/43776809/how-to-use-string-as-variable-name-in-lua, or google further...

John

 

  • Thanks 1
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.