This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
kornstar83's profile picture

A couple of questions from a newcomer

Started by kornstar83, 06 March 2015 - 01:54 AM
kornstar83 #1
Posted 06 March 2015 - 02:54 AM
Hello everyone, I am a newcomer to minecraft, computercraft(obviously), and programming in lua. I have been reading through several tutorials lately trying to learn as much as I possibly can and thanks to all of the very helpful people here I have learned a lot in the last few days and that has enabled me to create some simple and very ordered programs, for example:

turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
etc.

I have also started using more functions and loops to get my turtles to do what I want them to do, and so far everything seems to be going well. I'm now working on adding some more advanced features to the coding I am writing such as gravel/sand proofing and mob proofing, I have been successful in the gravel proofing thanks to the tutorials and am well on my way to accomplishing the mob proofing. I will stop myself here before I ramble on too much, but I felt that an introduction might encourage more users to respond to this post.

I will now begin by providing more info on the versions that I am using. when using CC I run Minecraft version 1.7.10 along with Minecraft Forge version 10.13.2.1291 and ComputerCraft version 1.73

As I stated above I have been spending hours reading through tutorials and forum posts to learn as much as possible, and while doing so I found reference to what seems to be pre-defined variables (like 'i' seems to be predefined to mean inventory), and I have also seen reference to things such as a PIL that I'm not sure what they are or how I can use them to help me. I have also spent a few hours searching this forum and also running searches on google to try to figure out the answer to my question but most of the results that I get are either too advanced for me to understand or have nothing to do with what I am looking for.

Now for my question: is there a topic on this forum or else where that I can go to find out more about pre-defined variables such as 'i' (I apologize if I'm not using the proper terminology) and where/how do I find this PIL (from what I understand it seems to be a reference to lua language and how to use it) and other reference material to help me learn.

I'm not necessarily asking anyone to explain these things to me, a simple link to (or even just a "go to this thread") is all that I need, I can do the rest myself. I had been trying to avoid posting this question here but after searching and reading as much as I have my eyes (and head) are starting to hurt a little.

I apologize once again if this question has already been asked and answered or covered somewhere in a tutorial that I may have missed but I can't handle anymore searching at the moment. Any and all help with this is greatly appreciated.

Finally I would like to thank all of the developers, administrators, and moderators of CC and this forum, you are all awesome.

Thanking you in advance,
kornstar83
Evil_Bengt #2
Posted 06 March 2015 - 07:32 AM
Lua has a free online version of their manual or whatever so go and check it out :D/> It sure helped me alot! :D/>

http://www.lua.org/manual/5.3/
Bomb Bloke #3
Posted 06 March 2015 - 07:50 AM
Truth be told, "i" isn't a "predefined variable". Back in the day, FORTRAN coders used to often use it as the counter variable in their loops because it was the first valid integral variable name available to them (other variable names, eg "a", "b" etc were reserved for other data types), and the habit has sort of persisted and become a tradition whenever creating "for" loops in any language.

For example, if someone wants to count their way through the inventory slots available to a turtle, they'll probably use "i"… and if someone wants to count their way through tomorrow's grocery shopping list, odds are they'll use "i" for that, too!

You don't need to use it, though. Go with whatever variable names you feel make your script easy to read.

PIL (Programming in Lua) is a book which happens to be linked up the top of the manual Bengt referred you to.

Personally I think that reading your way down this tutorial directory - at least as far as the scope tutorial, for starters - is an excellent way to learn.
MKlegoman357 #4
Posted 06 March 2015 - 11:42 AM
You can find the docs and function reference of Lua 5.1 (CC uses this version of Lua) here. On the CC Wiki you can find all the CC related APIs and functions.
KingofGamesYami #5
Posted 06 March 2015 - 12:44 PM
One thing nobody has mentioned is CC uses LuaJ 2.0. This means there are some flaws, notably the broken string functions. Also, CC doesn't include the debug library for security reasons. The io library is basically a rewrite of the fs library, so it is missing some functionality.

Something else you may want at some point is an emulator. Several have been written, my favorite is a web based one called Mimic. It'll let you test your code without launching Minecraft.

In addition to an emulator, you may be interested to know CC's lua files. They can help if you get stuck on a project, and know CC makes use of something you don't understand - you can read the source code to figure out what it's doing.

Never be afraid to ask questions in Ask A Pro: we love to help. However, it would be nice if you could read the stickys before posting. They can sometimes solve your problem, and if not, will give you instructions on how to post appropriately.

Welcome to the forums!
kornstar83 #6
Posted 07 March 2015 - 03:15 AM
Thank you all for the information, my eyes (and head) are well rested today so I will get to reading through as much of that info as I can.

Never be afraid to ask questions in Ask A Pro: we love to help. However, it would be nice if you could read the stickys before posting. They can sometimes solve your problem, and if not, will give you instructions on how to post appropriately.

I wasn't afraid to ask the question, I was simply being stubborn and wanted to try to figure it out on my own. I would like to say that I did read the sticky about posting questions before I posted mine, and I thought that I had conformed to the rules within it, I sincerely apologise if my question broke any of those rules.

Also thank you for the welcome :)/>

Thanks again to you all for your help, it is greatly appreciated.
kornstar83
Lyqyd #7
Posted 07 March 2015 - 03:17 AM
Your question was just fine, so I'm not sure where he was coming from with that comment.
kornstar83 #8
Posted 07 March 2015 - 03:31 AM
after re-reading the sticky I realized that I chose a poor title for this topic as it didn't give any clues as to what would be found in the question. I will be more careful from now on when posting.
KingofGamesYami #9
Posted 07 March 2015 - 04:31 AM
Your question was just fine, so I'm not sure where he was coming from with that comment.

I was just giving random advice. It's nice to see someone who actually writes about their problem on the forums :)/>.