Jump to content

XMedders

Retired Staff
  • Posts

    61
  • Joined

  • Last visited

  • Days Won

    1

XMedders last won the day on December 22 2015

XMedders had the most liked content!

1 Follower

About XMedders

  • Birthday April 24

Contact Methods

  • Website URL
    http://fishermedders.com/

Profile Information

  • Gender
    Male
  • Location:
    My Computer
  • Interests
    Computers, Coding, Minecraft, Tekkit, Java, Bukkit, Spigot, Guitars, Haxing

Recent Profile Visitors

47,014 profile views

XMedders's Achievements

Carpenter

Carpenter (5/26)

31

Reputation

  1. Thanks, I enjoy the art of coding, and I believe it is an essential skill for all people in this day in age.
  2. Wise words from this man everybody! Editing right now
  3. Turtles! How cute! [and deadly] Turtles! Lovable, programmable... reptiles! No, no, no. Not those kind of turtles! These turtles http://computercraft.info/wp-content/uploads/2012/07/piggy.png Prerequisite: If you're reading this, and you're not on the CraftersLand Server, you totally should check it out. Url is craftersland.net Since most of you will be playing on CraftersLand, you or your town Mayor/Assistant must allow them in your town. To do this, you must enter the following command: /town perm town set ccturtles true However, if you only want them in one chunk, which is probably the smarter choice, if you aren't doing turtles in every chunk of your town, the next command is better. /town perm plot set ccturtles true This will only allow them in one chunk of your town (the one you're standing in) Turtles are the blocky robots that come with ComputerCraft! The Wiki for turtles on computercraft.info says: Seeing as CraftOS and TurtleOS are very similar, I believe that the only main difference is that the TurtleOS startup shell is reskinned to say 'TurtleOS', and that the apis folder has one more api, this being the Turtle Api! The turtle Api is an Api for Turtles Only that have many code-world interfaces, such as digging, placing, turning, moving, etc. There are some functions that don't require a tool to dig, but it would be nice to have a compatible tool. What I mean by this is that if you're using turtle.dig() to dig stone, you'll need a shovel turtle, and not a pickaxe one. So, this means that you must be specific with the type of job you want your turtle to do. Premade Programs There are some programs that come with the turtles. Feel free to play around with these! I have some creative descriptions to spark your imagination and creativity glands. craft - this one requires a crafty turtle dance - get on down with your bad self excavate - holes, holes, digging the holes. go - shoo, shoo, foul turtle. refuel - get some coal in your system tunnel - dig a tunnel for your mining laziness. turn - you look around slowly, not sure what to think of your surroundings These are the only ones that I know of, but please tell me if I'm missing any x) Using the turtle Api in your programs So, I'm going to teach you how the turtle Api works. It works like any other Api, in that it has functions, and return variables . This being said, you can check out the Turtle Api page if you'd like and play around with it yourself, or you can follow the tutorial. If you're a beginner, I'd advise you stick to the tutorial for now . First, We'll find a convenient location, such as the spot from my last tutorial . (img) Next, we need to determine what we want our program to do. The program I have chosen to write is a simple square pattern. The Moves will be like this: forward x3, left, forward x3, left, forward x3, left, forward x3, left By using this pattern, the turtle will go in the square, and end up in the exact same spot as before, aswell as facing the same direction. An easy way to do this is by using for loops. These are easily manipulable to make them do whatever you want. for i = 1,5 do print(i) end --will return --1-5 on each newline. We will use this condition loop to create a function so that we don't have to enter turtle.forward() 12 times. function go(num) for i = 1,num do turtle.forward() end end Then, we will put the function together with the code to run it. Lets run it once. function go(num) for i = 1,num do turtle.forward() end end go(3) turtle.turnLeft() go(3) turtle.turnLeft() go(3) turtle.turnLeft() go(3) turtle.turnLeft() --We are facing the original direction. Optional: for extra fun add a while true do before the first go, and an end after the last turtle.turnLeft() for endless viewing fun & pleasure. Some Self explanitory Functions Some of these functions have up, down, left, and right variants, of which you can find on the Turtle Api page. The most self expanitory functions I didn't comment. turtle.forward() turtle.back() turtle.up() turtle.down() turtle.turnLeft() turtle.turnRight() turtle.select(slotId) -- select an item in the turtle's slot turtle.place() -- place a block turtle.drop(count) -- drop an item turtle.refuel() -- refuel the turtle If I missed anything, tell me. Also, if you have any questions/comments/additions/snide-remarks, please let me know in the comment, and I'll be right with you Thanks-a-million -XMedders
  4. This tutorial is dedicated to shawnmick23, as he wanted to see the bridge from C's include directive to ComputerCraft's os.loadAPI function. Even though I don't know a whole lot of C, I know a whole lot of lua . API's can be used for many different things! The most common uses are Effecient distribution of code packages, Efficient storing of functions, etc. So, today We will be learning one of the most useful things in the os api for computercraft. This is the function os.loadAPI() The function os.loadAPI takes a parameter of a string which is the filename. e.g. os.loadAPI("filenamehere") Once you call this, all of the functions in that file will from then on be available from inside the file that called it. However, whenever you edit the api, you will need to call it again for the changes to take place. The best way to do this is to call the loading of the api in the first line of the program that you're editing. An Example api would be a file named ccolorapi - Custom Color Api! -- This is an api for blah blah blah blah. -- made by your name here, please give credit! apihelp = { --custom defined help dictionary, much like peripheral.getMethods() --function name, function desc {"clearColor","Makes the background color the specified color"}, {"setColorVars","Sets all of the variables that have to do with colors"} } function listMethods() for i = 1,#apihelp-1 do print(apihelp[i][1]..",") end print(apihelp[#apihelp][1]..".") end function help(func) for i = 1,#apihelp do if apihelp[i][1] == func then return apihelp[i][2] end end end function clearColor(color) -- I can see this function being kinda useful term.setBackgroundColor(color) term.clear() term.setCursorPos(1,1) end function setColorVars(tcolor,bcolor) -- this one, not so much term.setBackgroundColor(bcolor) term.srtTextColor(tcolor) end Then, to reference this api, we would do something along the lines of this os.loadAPI("ccolorapi") clearColor(colors.lime) -- makes the background lime print("HELLO WORLD :D") If you wanted to see the list of functions or the description of a function in the lua prompt or somehting, you would type in the prompt os.loadAPI("ccolorapi") ccolorapi.listMethods() ccolorapi.help("setColorVars") And that's all there is to it, folks Thanks-a-million -XMedders
  5. Hello All! I've scoured this tutorials forum for ComputerCraft tutorials, to see if anyone's done one. I think I saw only one. So, with that said, today I will be doing a tutorial on ComputerCraft. ComputerCraft is a mod that requires creativity. We all have and show this in different ways. With this being said, if you can't grasp the whole ComputerCraft topic the first time around, don't worry! I'm pretty sure first time, it takes everyone a little bit to get used to the whole thing. This tutorial will have screenies of the whole process ComputerCraft Computer Fundamentals First, there are two types of computers in versions pre 1.7 (We're playing Tekkit main, so there are no command computers in 1.6.4.) These are Regular and Advanced Computers. The only real difference between the two is that Advanced computers can draw text and backgrounds in color, and recieve the events mouse_click, and mouse_drag. However, these aren't important right now x). If you can afford an advanced computer, you can use it, but if you can't a regular computer will do just fine for what we will be doing in this tutorial. (img) When you have your computer, just plop it down anywhere in the world (preferably in a protected spot), and it will boot right into the shell. (img) To get an idea of how programs run, type in hello this command will write out the words 'Hello World!'. When this program has finished printing it out, you will notice that you can type again. This is because the function that prints the words is still running, so you can't type while it is writing out. (img) The language that the computers use is called lua. If I'm not mistaken, this version of ComputerCraft uses lua version 5.1, maybe 5.2. So, if you want to use a function from the lua language, check out this page! However, let's not get ahead of ourselves. In this post, I will go over some basic lua snippets, so that you know some of the basic things that you can do with computercraft. Lua Fundamentals Variables: There are two basic variables in lua. These are Strings and Numbers. Think of strings as Words, and Numbers as.. Well.. Numbers. You can't add strings and numbers, because in the alphabet, you can't do 5+v can you? Strings are like this: stringname = "Hello world!" Numbers are like this: numname = 5 If you try to print them, they will return what is on the right side of the equals sign, because when you set a variable, that variable is equal to what you set it to. print(stringname) -- will return Hello world! print(numname) -- will return 5 If you try to add a string and a number, you will get an error like attempt to perform arithmetic on string However if you add two numbers, it will return like so: num1 = 5 num2 = 3 print(num1+num2) -- will return 8, as 5+3 is 8 If you want to add a number to a string, you would do it with concatenation, or putting together of variables. you concatenate with the operator '..' string = "Number of Cookies in the jar: " number = 5 print(string..number) -- will return Number of Cookies in the jar: 5 If you want to make a number a string, or a string a number, you would do this like so. string = "5" number = 7 print(tonumber(string)) -- makes the 5 operable by arithmetic (math) print(tostring(number)) -- makes the 7 unoperable by arithmetic (math) If you want to get the user's input via them typing, you have to use the function input = read() -- variable input can be whatever you want to name it, stores as a string. print(input) -- will print what the user types Harder Functions The best basic function of lua that I know is the if statement. Without this, you wouldn't be able to ask questions based on what the computer is experiencing, and therefore wouldn't have much of a querying system at all. Think of this code as regular english, because it is regular english. name = read() -- get the user's input if name == "fisher" then print('OMG GUYS ITS THAT COOL GUY WE KNOW NAMED XMEDDERS OMGOMGOMG') else print('who dat is?') end There are also elseifs. These are like if name == "fisher" then print('OMG GUYS ITS THAT COOL GUY WE KNOW NAMED XMEDDERS OMGOMGOMG') elseif name == "slit" or name == "rmtworks" then print('omg its '..name..' a staff member who is actually tolerant of me lol') else print('who dat is?') end When you want to do things with the shell (terminal window), you must interface it using the term api. This api has lots of useful functions. term.clear() -- will clear the screen, but won't put the cursor to the top left (1,1) term.setCursorPos(x,y) -- sets the position of the cursor on the screen (where you will print or write next) term.write("sometexthere") -- will write text on the screen, but won't go to the next line after. term.setBackgroundColor(color) -- sets the background color, but for it to take effect, term.clear() must be called. term.setTextColor(color) -- sets the color of the text that you write with. Math is an api that you might not use alot while starting out as a beginner, but it's worth mentioning x). I have only included to functions, because these are the only two I'd ever imagine a beginner would need. math.random(lownumber,highnumber) -- returns a random number between the two specified ones. math.sqrt(number) -- returns the square root of a number (can't be a string.) Writing your own Program! To write your own program, go to your computer and type in edit <anynamehere> the anynamehere part is the name of your program, and caps matters, I would just keep it lowercase. another thing I should mention is that if you edit the file startup, the code in that file will happen when the computer is clicked to start or rebooted. From Here, it is just a regular text editor. I will include some sample code out of the basics that we just talked about down below. To exit this editor, you must hit control, then right, then right arrow, then enter. You have successfully viewed your first file in the editor For our basic program, we will create a locking door mechanism customized to your needs To set this up, you will need to place a door down beside the computer that you are using, like so. (img) Next, click on the computer, and type this in. edit startup You will be taken to the file, and from there, enter in this code. All lines have an explination. You don't need to include what's after the -- or the --. e.g. you don't have to put print("hi") -- this prints hi just print("hi") So, with that said, this is the code for the door! password = "ilovecookies" -- password to get in time = 3 -- time in seconds to get in the door side = "left" -- usable sides are top, bottom, left, right, front, and back while true do -- loop that runs forever rs.setOutput(side,false) -- close door print("What is the password to get in?") -- ask question input = read("*") -- get user's answer if input == password then -- you got the pass right rs.setOutput(side,true) --open door print("You got the password right!") -- congrats else -- if wrong rs.setOutput(side,false) -- close the door print("Sorry, but that's incorrect!") -- nope lol end -- end the if statement sleep(time) -- wait for 'time' end -- end the forever loop. and if you want to disable termination of your door lock, at line 1, put os.pullEvent = os.pullEventRaw to download this code, click here or enter in your computer's shell: pastebin get XcmCyFEZ startup Thanks for viewing this. This took alot of effort on my part (if you count moving your fingers for an hour), or if you like this, please drop a like, and if you have any questions/suggestions/comments/snide-remarks, please leave them down in the comments section and I'd be happy to address them x) Thanks-a-million, XMedders
×
×
  • Create New...

Important Information

By using this site you agree to the following Terms of Use, Guidelines and 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.