Iceking007 Posted March 3, 2022 Report Share Posted March 3, 2022 Hello, I have been learning Lua and it's been going fairly well. I have run into an odd problem I'm hoping someone could shed some light on. Please note I am by no means an expert... and there certainly is a ton I don't fully understand, however I'm trying to learn and solve a piece at a time. So simply put I have a multi array table, say TableA{} which has a bunch of strings in it; I'm using this for commands I plan to send back to fsuipc. Anyways the table might look like this: TableA { {"C#####", "C#####"}, {"C#####", "C#####"} } if I run io.write(TableA[1][1]) I get a I expect C##### (tested as ...C###11 or C###21 respective to verify) However if say I change some code to: v = io.read() k = io.read() io.write(TableA[v][k]) I get "attempt to index a nil value". Even if I print the values before the table call I can see the variables are storing the inputs; however the table isn't using the values. To clarify: v = 1 k = 2 works but not if I'm using io.read() I appreciate your time. Link to comment Share on other sites More sharing options...
Iceking007 Posted March 3, 2022 Author Report Share Posted March 3, 2022 Nevermind, I've literally just stumbled upon a solution (isn't that how it works...?!) Here's what worked: TableA{ {"stuff here"} } function readTableA() for v = v, v do for k = k, k do io.write(TableA[v][k]) end end end Not sure why I need all that with variables rather than set integers being able to read the table directly; but hay, if it works, it works. I was going to see about deleting this, but perhaps someone might find it useful?! Storage space is fairly cheap. I have more questions but I'll post those as they bother me more. Thank you. Link to comment Share on other sites More sharing options...
John Dowson Posted March 3, 2022 Report Share Posted March 3, 2022 Your code doesn't make much sense. To define the table you should use: TableA = { ... } Why are you using the io library? For logging, use ipc.log. Your readTableA function also makes no sense - I am surprised that doesn't give an error as the for loop syntax is not correct... Try an on-line lua tutorial to understand the basics, and take a look at some of the example lua scripts provided. Link to comment Share on other sites More sharing options...
Iceking007 Posted March 4, 2022 Author Report Share Posted March 4, 2022 It wasn't a very good explanation... that table in specific is in fact a multi dimensional table: TableA = { {array 1:1, array 1:2, array 1:3}, {array 2:1, array 2:2, array 2:3} } I was only using the io library for testing purposes. This way I can run my code instantly in the terminal and see how it's working. Otherwise I'd have to save it upload to my NAS, download to my flight simulator (after starting it up of course) run fs, and then attempt the code. If it didn't work (as I build it in individual pieces at a time) I wouldn't know where the failure is, this way I get an idea. I have done a few tutorials and looked at many of the example files. Thank you for your feedback. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now