- ComputerCraft | Programmable Computers for Minecraft
- → sjele's Content
sjele's Content
There have been 307 items by sjele (Search limited from 10-February 22)
#116749 Computer Craft Coding Tutorial
Posted by
sjele
on 10 May 2013 - 02:44 AM
in
Tutorials
--[[...]]--
local result
if op == "add" then
result = num1+num2
elseif op == "subtract" then
result = num1-num2
elseif op == "multiply" then
result = num1*num2
elseif op == "divide" then
result = num1/num2
else
result = "Unknown math mode, you can use: add, subtract, multiply and divide"
end
print("The answer is: "..result)
Also i shrunk it down to one print statement, much cleaner this way. (IMO)
Everyone should use local vars whereever they can, teaching them how to use those is much better then only using globals.
here is some info about local vars:
http://www.lua.org/pil/4.2.html
http://www.computerc...__fromsearch__1
Allso if i remmber right, bubba recently answerd a post about local/global, it was good, can't find it now
You could allso use the ternary operator to do this, but thats not really practical in this case, but it still does the job:
print("\nThe answer is "..(op == "add" and num1+num2 or (op=="div"and num1/num2 or (op == "mul" and num1*num2 or (op=="sub" and num1-num2 or "Unknown mode!")))))
Calculator using ternary:
local op
local num1
local num2
local goodModes = "add sub div mul"
repeat
term.clear()
term.setCursorPos(1,1)
write("What math mode would you like to use: ")
op = read()
until goodModes:find(op)
repeat
term.setCursorPos(1,2)
term.clearLine()
write("First number: ")
num1 = tonumber(read())
until type(num1) == "number"
repeat
term.setCursorPos(1, 3)
term.clearLine()
write("Scond number: ")
num2 = tonumber(read())
until type(num2) == "number"
print("\nThe answer is "..(op == "add" and num1+num2 or (op=="div"and num1/num2 or (op == "mul" and num1*num2 or (op=="sub" and num1-num2 or "Unknown mode!")))))
#116354 CodeWars Reloaded - Round 2
Posted by
sjele
on 08 May 2013 - 01:03 PM
in
General
oeed, on 08 May 2013 - 02:49 AM, said:
Much better, this way you still get to compete if you had little time this week (like me).
#110151 AX-OS The OS Of Tomorrow.
Posted by
sjele
on 15 April 2013 - 01:16 AM
in
Operating Systems
This problem exsists in settings.
How to recreate this:
Spam click on one of the 3 selection you can change around 256/257 times
How to loop something properly, without stackoverflows:
http://www.computerc...h-your-program/
http://www.computerc...pic/7999-loops/
#110108 AX-OS The OS Of Tomorrow.
Posted by
sjele
on 14 April 2013 - 10:45 PM
in
Operating Systems
When logging in: While inputing text to one of the feilds I have to click enter to be able to select the other. Not a biggie but a bit annyoying.
#110102 AX-OS The OS Of Tomorrow.
Posted by
sjele
on 14 April 2013 - 10:24 PM
in
Operating Systems
#104368 using the keyboard in computercraft
Posted by
sjele
on 01 April 2013 - 07:29 AM
in
Tutorials
I belive you have a type in there. You start off with key id 200, but end with 208
#104308 [help] Print Error
Posted by
sjele
on 01 April 2013 - 05:24 AM
in
Ask a Pro
local up = 0
function mineup()
repeat
turtle.digUp()
turtle.up()
until turtle.detectUp() == false
repeat
turtle.down()
until turtle.detectDown() == true
end
function ddf()
if turtle.detect() == true then
turtle.dig()
turtle.forward()
else
turtle.forward()
end
end
function checkfuel()
if turtle.getFuelLevel <= 10 then
turtle.select(1)
turtle.refuel()
end
end
print("Hello. Welcome to the Cheesety210 Tree cutting program")
print("Please put your fuel in the first slot.")
turtle.turnRight()
turtle.turnRight()
turtle.turnRight()
turtle.turnRight()
term.clear() --In this line you made the error
print("I should be placed at the bottom of a tree next to it")
print("right next to the tree. A diagram is below.")
print(" [ ] = A log, and T is the turtle")
print("[ ] [ ] ")
print("[ ] [ ] ")
print(" T ")
print(" What is the width/length of the tree? In the example above it's 2.")
local length = read()
if length == 1 then
checkfuel()
ddf()
mineup()
end
if length == 2 then
checkfuel()
ddf()
mineup()
checkfuel()
ddf()
mineup()
checkfuel()
turtle.turnRight()
ddf()
mineup()
checkfuel()
turtle.turnRight()
ddf()
mineup()
checkfuel()
turtle.forward()
end
if length == 3 then
ddf()
mineup()
checkfuel()
ddf()
mineup()
checkfuel()
ddf()
mineup()
checkfuel()
turtle.turnRight()
ddf()
mineup()
checkfuel()
turtle.turnRight()
ddf()
mineup()
checkfuel()
ddf()
mineup()
checkfuel()
turtle.turnLeft()
ddf()
mineup()
checkfuel()
turtle.turnLeft()
ddf()
mineup()
checkfuel()
ddf()
mineup()
end
print("I am done with this tree!")
#103244 [Error][Lua] = Expected but not really..
Posted by
sjele
on 29 March 2013 - 08:29 AM
in
Ask a Pro
#94792 Guys,I think Lyqyd locked my post for absolutely no reason!SEE IF IT MAKES SENSE
Posted by
sjele
on 09 March 2013 - 06:02 AM
in
Forum Discussion
http://www.computerc...rum-guidelines/
#94346 CC Syntax Highlighting/Code Completions v1.2 - Sublime Text 2
Posted by
sjele
on 08 March 2013 - 03:55 AM
in
APIs and Utilities
#89300 Program debugger
Posted by
sjele
on 20 February 2013 - 10:33 PM
in
Programs
I guess this debugger breaks programs, i were lucky i used a test program not a fully functional one.
[edit]
You could told us that the clear thingy removes all the shit from the program
[/edit]
#88925 READ THIS
Posted by
sjele
on 20 February 2013 - 07:18 AM
in
Forum Games
[Edit]
Ninja'd
[/Edit]
- ComputerCraft | Programmable Computers for Minecraft
- → sjele's Content


