- ComputerCraft | Programmable Computers for Minecraft
- → BigTwisty's Content
BigTwisty's Content
There have been 106 items by BigTwisty (Search limited from 10-February 22)
#147612 Corrupt-A-Wish!
Posted by
BigTwisty
on 02 October 2013 - 10:26 PM
in
Forum Games
I wish I could come up with something clever to wish for.
#147477 Corrupt-A-Wish!
Posted by
BigTwisty
on 01 October 2013 - 12:13 PM
in
Forum Games
I wish I could hack the human mind.
#147405 Attempt To Index Field '?' (A Boolean Value)
Posted by
BigTwisty
on 30 September 2013 - 02:51 PM
in
Ask a Pro
1:
for c=sizeZmin, sizeYmax doshould be:
for c=sizeZmin, sizeZmax do
2. There are several places where world is referenced with 4 sub tables, but it only seems to be generated with 3.
3. You defined importModel with 2 arguments, but are calling it with 5. The last 3 arguments are being ignored.
Those are just the few I found on a quick scan. If you fix those and it still doesn't work, we can look more in depth.
#147382 Rednet code question.
Posted by
BigTwisty
on 30 September 2013 - 12:27 PM
in
Ask a Pro
and the Redstone API documentation here: http://www.computerc.../Redstone_(API). In the Redstone API, check out the rs.getInput(side) function. Figuring it out from there should be simple enough.
#147123 Multiple Alarm Events.
Posted by
BigTwisty
on 28 September 2013 - 11:48 PM
in
Ask a Pro
CCJJSax, on 27 September 2013 - 09:56 PM, said:
Line 160 is where it should be called and the function is at line 115.
First thing I notice is that night() is the only function that turns on redstone. If the other chime functions work, then I'd look at the chime peripheral and see if redstone affects thruway it works. An easy test would be to comment out line 117 and see if it starts working.
#147066 How to automate quarry/tesseract/chest placing?
Posted by
BigTwisty
on 28 September 2013 - 04:46 PM
in
Ask a Pro
Lyqyd, on 28 September 2013 - 03:13 PM, said:
BigTwisty, on 28 September 2013 - 01:19 AM, said:
You can use either a shiny dust or a shiny ingot on them to cause them to retain their settings when broken. This may only work when they're broken with the crescent hammer. TE adds an "engineering turtle" or similar that has a crescent hammer tool attached. Obviously, craft a turtle and a crescent hammer to get one.
That is awesome! Never knew that. Thanks!
#147035 Asking For Code Review (By Pros)
Posted by
BigTwisty
on 28 September 2013 - 11:07 AM
in
Ask a Pro
Engineer, on 28 September 2013 - 09:13 AM, said:
Do you understand WHY using a goto is bad? A goto statement moves the next executing line pointer to another point in the code, but DOES NOT RETAIN any information on where it was called from. This creates a needlessly complicated flow through the code, leading to confusion and much difficulty when trying to find bugs. In this case, the functions are being used more like a gosub, which moves the next executed line pointer but retains the call point, allowing code continuation from that point when the subroutine is finished.
#147003 Binary Editor In Minecraft
Posted by
BigTwisty
on 28 September 2013 - 01:13 AM
in
Ask a Pro
wojbie, on 27 September 2013 - 03:41 AM, said:
Thats what i am using anyways.
Try:
string.format("X", number)
#147002 Asking For Code Review (By Pros)
Posted by
BigTwisty
on 28 September 2013 - 01:06 AM
in
Ask a Pro
Engineer, on 27 September 2013 - 06:38 PM, said:
One common use for functions is to separate bits of code for readability. Take for instance the "main" function in many applications. The entirety of the main loop is usually contained within that function, and it is only called once, from the bottom of the app. A "setup" function is used the same way. I assume that is what the OP was doing here.
#146890 Asking For Code Review (By Pros)
Posted by
BigTwisty
on 27 September 2013 - 01:06 PM
in
Ask a Pro
Also cleaned up some code indentation.
For the most part this is laid out fairly well. The code is pretty easy to read. There is a bit of redundant code you can remove, and at least one function that is never called, but all in all it isn't too bad.
--Charge Program - p3pt3RQM
--Developed by UltraNoobian
local version = "0.04d"
--API_LOAD
--END API_LOAD
--VAR_LOAD
local args = {...}
local targetCharge = 0
--END VAR_LOAD
--FUNC_DEFINE
function Intro()
print ("--------")
print ("Charging Program - Developed by UltraNoobian")
print ("Using version: " .. version)
print ("--------")
end
function termReset()
term.clear()
term.setCursorPos(1,1)
end
-->> termReset() is never called. Either remove completely or integrate int Intro()
function getVariables()
if args and #args == 1 then
-->> Because args is defined as {...} it will always exist as a table. Remove "args and" as it is redundant.
if tonumber(args[1]) ~= nil and tonumber(args[1]) >= 1 then
targetCharge = tonumber(args[1])
print("Valid Charge: " .. args[1])
elseif tonumber(args[1]) ~= nil and tonumber(args[1]) < 1 then
print("That is not a positive charge. Try again.")
error()
elseif tonumber(args[1]) == nil then
print("Not a number, Please enter a valid number next time you run this program~!")
error()
end
-->> Move the handler for tonumber(args[1]) == nil to the top, then you do not need to check for it for the other 2 cases.
elseif args and #args > 1 then
print("Invalid number of arguements, We only need the charge level!")
error()
-->> use this: error("Invalid number of arguments.", 0)
-->> The 2nd parameter, 0, tells Lua to exit with an error, but not provide a line number.
-->> or do what most Lua programs do; simply ignore the extra parameters.
else
print("")
print("What Charge level would you like to achieve?")
testCharge = read()
-->> You never use the string form of testCharge. Go ahead and use:
-->> testCharge = tonumber(read())
-->> This cleans up later code a lot.
if tonumber(testCharge) ~= nil and tonumber(testCharge) >= 1 then
-->> Replace with: if testCharge and testCharge >= 1 then
targetCharge = tonumber(testCharge)
print("Valid Charge: " .. targetCharge)
elseif tonumber(testCharge) ~= nil and tonumber(testCharge) < 1 then
print("That is not a positive charge. Try again.")
error()
elseif tonumber(testCharge) == nil then
print("Not a number, Please enter a valid number next time you run this program~!")
error()
end
-->> Same concept as above.
end
end
function printVariables()
print("")
print("---NOTICE---")
print("Your current charge level is " .. turtle.getFuelLevel())
print("You are charging to " .. targetCharge .. ".")
print("Press any key to continue...")
read()
end
function chargeFull()
if turtle.getFuelLevel() > targetCharge then
return true
else
return false
end
end
-->> if then else is redundant. Comparisons return a boolean already. Use:
-->> return turtle.getFuelLeve() > targetCharge
function tryBurn(slotID)
while turtle.getItemCount(slotID) > 0 do
if turtle.refuel(1) == false or chargeFull() then
break
end
end
end
function inventoryBurn()
print("Inventory burn commencing...")
print("")
for slotID = 1,16 do
turtle.select(slotID)
lineUpdate("Currently attempting to burn slot " .. slotID .. ".")
tryBurn(slotID)
if chargeFull() then
print("")
print("Your turtle has reached it's target charge level!!")
read()
break
end
end
end
function burnCoolDown()
print("")
print("Begining idle phase, Now is the time to put in fuel...")
print("")
for count = 30,0,-1 do
lineUpdate("Next Inventory Burn in " .. count .. " seconds")
sleep(1.0)
end
print("")
end
-->> burnCoolDown() calls lineUpdate() before it is declared. You need to move the lineUpdate() function above burnCoolDown() so it exists when burnCoolDown() is compiled.
function lineUpdate(string)
local currX,currY = term.getCursorPos()
term.clearLine()
term.setCursorPos(1,currY)
write(string)
end
--END FUNC_DEFINE
--MAIN
Intro()
getVariables()
printVariables()
while not chargeFull() do
inventoryBurn()
if not chargeFull() then
burnCoolDown()
end
end
print("")
print("This program will now terminate.... Thank you for using UltraNoobian's Programs")
#146724 redstone activated terminal
Posted by
BigTwisty
on 26 September 2013 - 04:23 PM
in
Ask a Pro
startup:
while true do
_,side = os.pullEvent("redston")
if side == "back" then
shell.run("prog")
end
end
prog:
begin
-- Do stuff
-- Kick dog
-- Make fun of Lyqyd
-- Get banned from CC forum
until not rs.getInput("back")
#146476 How To Make An Installer.
Posted by
BigTwisty
on 24 September 2013 - 10:33 PM
in
Ask a Pro
PixelToast, on 24 September 2013 - 02:49 PM, said:
BigTwisty, on 24 September 2013 - 02:36 PM, said:
you can use string.dump/luac to turn the program into bytecode, that can be decompiled/dissasembled though, there is a program to randomize the localize names making it harder to dissasemble (i forget where)
sometimes i localize random functions with random function names and make the code completely unreadable, though its kind of hard developing something like that
i find it completely useless to make CC programs closed source, or anything for that matter because there are always ways of retrieving the source
Interesting. I was unaware of this. I would think server admins would dislike this a bit, as they can't go in and see if it is your code screwing up their server. I figured CC was open source by design.
I can see how this might be of use in a war server, however.
#146475 Rednet code question.
Posted by
BigTwisty
on 24 September 2013 - 10:29 PM
in
Ask a Pro
brattus123, on 23 September 2013 - 10:57 PM, said:
rednet.open ("left")
while true do
local event, id, msg = os.pullEvent (rednet.receive ("10"))
if id == 18 then
if msg == "nograv" then
shell.run ("offorbit")
shell.run ("orbit")
end
end
end
Look at your os.pullEvent line. Read the documentation on os.pullEvent, look at your code again, and have a nice facepalm moment.
#146474 While True Do Loop Issue
Posted by
BigTwisty
on 24 September 2013 - 10:24 PM
in
Ask a Pro
If you want to keep it simple, remove the timer stuff from the top and add sleep(5) to the bottom of the loop. Otherwise you'll need to use the value returned by os.startTimer to ensure only the latest timer is being responded to.
#146418 How To Make An Installer.
Posted by
BigTwisty
on 24 September 2013 - 02:36 PM
in
Ask a Pro
2. There is no way to make ANYTHING closed source in ComputerCraft. Everything is saved in source code form. Anyone downloading the 9 files would be able to reading them.
#146413 While True Do Loop Issue
Posted by
BigTwisty
on 24 September 2013 - 01:40 PM
in
Ask a Pro
1. I don't see where the tables named "chest", "mace" or "efurn" are created, so either you aren't showing all your code or these are missing.
2. If you don't tell us what error you are getting, we can't tell you where it is coming from.
3. You have a bunch of useless "else" statements cluttering up your code. Remove them.
4. Proper indentation helps us read it. See corrected indentation here:
chest.condense() --Organize the Chest
local slotnum = chest.getSizeInventory() --Use the Max Invantory Size to calculate the Slot number and Loop amount
local macedone = mace.getStackInSlot(1)
local efurndone = efurn.getStackInSlot(1)
while true do
os.startTimer(5)
event = os.pullEvent()
if event == "timer" then
--push completed items out of the mace and efurn--
mace.push("north", 1, 64)
efurn.push("up", 1, 64)
--start looking for ore--
for i=1,slotnum do -- LOOP!
local tableInfo = chest.getStackInSlot(i)
if tableInfo ~= nil then
for key, value in pairs(tableInfo) do
if string.find(value, "Ore") then -- Find Ore
print("Ore Found! Moving to Macerator!")
chest.push("north", i, 64)
else
end
end
else
end
end
else
end
end
Edit: Ninja'd on the error
#146309 How To Refresh A Clock
Posted by
BigTwisty
on 23 September 2013 - 01:42 PM
in
Ask a Pro
Hellkid98, on 23 September 2013 - 12:52 PM, said:
As long as the variable is local to the function and he is not calling the function recursively from inside itself, this should cause no problems.
Hellkid98, on 23 September 2013 - 12:52 PM, said:
Here's an example
clockTimer = os.startTimer(.8) -- Start the timer for the first time while true do evt, p1, mX, mY = os.pullEvent() if evt == "key" then -- Do something elseif evt == "timer" then clockTimer = os.startTimer(.8) -- Restart the timer when it has ran end end
This will only work if he is doing nothing else. If you look at the image in the OP, there are other menus and things being accessed simultaneously. Like I said, we really need to see the rest of the code. The solution in the previous post makes too many assumptions.
#146289 How To Refresh A Clock
Posted by
BigTwisty
on 23 September 2013 - 11:48 AM
in
Ask a Pro
Second, it is a good idea to not hard code your screen locations, just in case your position is off or you decide to run code on a monitor.
function time() local time = textutils.formatTime(os.time(), true) local w = term.getSize() term.setCursorPos(w - #time + 1, 1) print(time) end
3rd, you need to check the rest of your code to ensure this function is being called regularly. This is why we need to see the rest of your code.
#146263 Rednet code question.
Posted by
BigTwisty
on 23 September 2013 - 07:20 AM
in
Ask a Pro
brattus123, on 23 September 2013 - 12:05 AM, said:
Turtle:
rednet.open ("left")
while true do
local event, id, msg = os.pullEvent ("rednet_message")
if id == 18 then
if msg == "nograv" then
shell.run ("offorbit")
end
end
end
else
shell.run ("orbit")
Proper code indentation would make this syntax error easier to spot.
rednet.open ("left")
while true do
local event, id, msg = os.pullEvent ("rednet_message")
if id == 18 then
if msg == "nograv" then
shell.run ("offorbit")
end
end
end
else
shell.run ("orbit")
The last 2 lines actually belong right after the other shell.run. Right now they are outside your loop and will never run. Can you see how code indentation makes it easier to read your own code?
#146251 [Lua] [Question] Is there something like Select Case?
Posted by
BigTwisty
on 22 September 2013 - 10:42 PM
in
Ask a Pro
kreezxil, on 22 September 2013 - 08:54 PM, said:
#146215 [Lua] [Question] Is there something like Select Case?
Posted by
BigTwisty
on 22 September 2013 - 05:40 PM
in
Ask a Pro
kreezxil, on 22 September 2013 - 12:22 PM, said:
name = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}
function getDay() day=name[tonumber(io.read())] if day ~=nil then print ("It is " .. day) end return day end
while true do print ("What day is it? (1-7) ",getDay() or "Where do you live?!") end
Now you're just cheating. You're just stringing statements together. If you do that, you might as well just put it all on 1 line. Your code is actually quite a step back with respect to efficiency.
The point was to reduce the number of function calls as far as possible to show how little Lua actually needs select case statements. I think we've proven our point.
(I still think my coded was the smallest, though...)
#146158 [Lua] [Question] Is there something like Select Case?
Posted by
BigTwisty
on 22 September 2013 - 10:30 AM
in
Ask a Pro
kreezxil, on 22 September 2013 - 08:48 AM, said:
Shefla, on 22 September 2013 - 08:34 AM, said:
name = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}
while true do
print "What day is it?"
print(name[tonumber(io.read())] and "It is "..day or "Where do you live?!")
end
It seems the day variable in this version is never initialized.
Your're right, I it's total garbage and can't be done the way I wrote it. Day must be captured as a variable before being processed inside the print string.
Nice try! This approach would work if you didn't have to print "It is " before the day.
name = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}
while true do
print("What day is it? ", name[tonumber(io.read())] or "Where do you live?!")
end
#146138 Rednet code question.
Posted by
BigTwisty
on 22 September 2013 - 07:41 AM
in
Ask a Pro
local function backTurn(length)
for i = 1,length do
turtle.back()
end
turtle.turnRight()
end
backTurn(25)
backTurn(12)
backTurn(25)
backTurn(12)
Looking at the last 4 lines it is now easier to (a.) see what the turtle is going to do and (b.) make it do something different if you want.
It should be noted that Lyqyd's code should do he same thing if it is copied in correctly.
- ComputerCraft | Programmable Computers for Minecraft
- → BigTwisty's Content


