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

Casper's Programs

Started by Casper7526, 28 January 2012 - 08:46 AM
Casper7526 #1
Posted 28 January 2012 - 09:46 AM
I'll make this look better when I get done doing well the whole damn site.

MiM (Minecraft in Minecraft) (One day I'll continue working on this)
Link: MiM (Direct Fire if your having problems - http://www.mediafire...gbppjttghp1vlhr
About:
Minecraft in Minecraft!
Features:
Creates a new font inside your computer directory which you can then copy to your minecraft.jar!
OldVideo:
Spoiler[media]http://www.youtube.com/watch?v=sYVmooRe4n0[/media]


NBS Converter
Link: NBS Converter
About:
Converts .NBS (Note Block Studio) Files into a custom format designed by me.


Tutorial
Link: Tutorial
About:
An Interactive In-Game Tutorial for ComputerCraft

IN-GAME DEBUGGER (Outdated and kinda pointless as of 1.3)
Link: DEBUG
About:
Gives you some information about where and what caused your program to crash.
Usage = debug <programname> <tracebackcount> <args>
Notes/Bugs:
None ATM, need more test cases.

The program will give you detailed information (as much as I can) about your crash.
A FULL traceback is found in the "debugtraceback" file each time you run debug on your program.

PIC In Action!
Spoiler


Random Programs
I am just going to post all kinds of random programs here that I don't deem worthy to make it into my "you should really check out list"
These programs will be labeled, but their usage and such will prolly not be explained. They also might be buggy as I'm just going to go through and copy the
files that I find first.

Pong
Spoiler


-- Pong V1 for ComputerCraft
-- Coded By Casper
-- Have fun and well... idk I was bored.
controlU = 17
controlD = 31
function diffselect()
term.clear()
print "Select Difficulty:"
print "1. LOL"
print "2. Easy"
print "3. Normal"
print "4. Hard"
print "5. Seriously?"
print "6. Change Bindings off of W/Sn"
diff = io.read()
if diff == "5" then gDiff = 500 end
if diff == "4" then gDiff = 300 end
if diff == "3" then gDiff = 100 end
if diff == "2" then gDiff = 50 end
if diff == "1" then gDiff = 10 end
if diff == "6" then
sleep(.5)
print "Press the key you wish to move upwards with."
local event, earg = os.pullEvent()
controlU = earg
sleep(.5)
print "Press the key you wish to move downards with."
local event, earg = os.pullEvent()
controlD = earg
diffselect()
end
end
diffselect()
gRunning = true
playerY = 2
compY = 2
ballY = 10
ballX = 24
ballA = 0
ballS = 12
ballD = -1
gTimer = false
cTimer = 0
playerScore = 0
compScore = 0
function round(num)
	under = math.floor(num)
	upper = math.floor(num) + 1
	underV = -(under - num)
	upperV = upper - num
	if (upperV > underV) then
		return under
	else
		return upper
	end
end

function score()
term.clear()
if ballX <= 1 then
compScore = compScore + 1
term.setCursorPos(16,9)
term.write("Computer SCOOOORES!")
end
if ballX >= 49 then
playerScore = playerScore + 1
term.setCursorPos(16,9)
term.write("Player SCOOOORES!")
end
sleep(2)
if compScore == 5 or playerScore == 5 then
gRunning = false
term.clear()
term.setCursorPos(16,9)
if ballX >= 49 then term.write("Player WIIIINS!") else term.write("Computer WIIIINS!") end
sleep(2)
end
ballY = 10
ballX = 24
ballA = 0
ballS = 12
gTimer = false
cTimer = 0
rnd = math.random(1, 2)
if rnd == 1 then ballD = -1 else ballD = 1 end
end

function moveplayer(earg)
if earg == controlU then playerY = playerY - 1 end
if earg == controlD then playerY = playerY + 1 end
if playerY < 2 then playerY = 2 end
if playerY > 15 then playerY = 15 end
end


function updateangle(ang)
if ang == 0 then
if ballA <= 0 then ballA = ballA - 2 else ballA = ballA + 1 end
end
if ang == 2 then
if ballA <= 0 then ballA = ballA + 2 else ballA = ballA - 1 end
end
term.clear()
print (ang)
print (ballA)
sleep(1)
end




function contact()
if (ballY == playerY and ballX == 3) or (ballY == compY and ballX == 47) then
if ballA <= 0 then ballA = ballA - 1 else ballA = ballA + .6 end
return (true)
end
if (ballY == playerY + 1 and ballX == 3) or (ballY == compY + 1 and ballX == 47) then
if ballA >= 1.25 then ballA = ballA - .45 end
if ballA <= -1.25 then ballA = ballA + .45 end
if ballA <= 0 then ballA = ballA - .35 else ballA = ballA + .35 end
return (true)
end
if (ballY == playerY + 2 and ballX == 3) or (ballY == compY + 2 and ballX == 47) then
if ballA <= 0 then ballA = ballA + 1 else ballA = ballA - .6 end
return (true)
end
return (false)
end

function movecomp()
if ballY > compY + 1 then compY = compY + 1 else compY = compY - 1 end
if compY < 2 then compY = 2 end
if compY > 15 then compY = 15 end
cTimer = false
end

function moveball()
ballX = ballX + ballD
if ballX == 3 and contact() == true then
ballD = 1
ballX = 4
ballS = ballS + (ballS / 3)
end
if ballX == 47 and contact() == true then
ballD = -1
ballX = 46
ballS = ballS + (ballS / 3)
end
if ballX == 1 then score() end
if ballX == 49 then score() end

if ballA >= 1.75 then ballA = ballA - .35 end
if ballA <= -1.75 then ballA = ballA + .35 end
oldbally = ballY
ballY = ballY + round(ballA)
if ballY <= 2 or ballY >= 17 then
ballY = oldbally
ballA = ballA * -1
end
if ballS > 30 then
rnd = math.random(1, 10)
ballS = ballS - rnd
end


gTimer = false
if ballS >= 150 and moved == false then
moved = true
moveball()
end
rnd = math.random(1, gDiff) * .1
cTimer = cTimer + rnd
if cTimer >= 1 then
movecomp()
cTimer = 0
end
moved = false
end

-- 18 x 49
while gRunning do
term.clear()
y = 1
x = 1
-- Print Game Area
while y < 19 do
term.setCursorPos(1,y)
term.write("|")
term.setCursorPos(49,y)
term.write("|")
y = y + 1
end
while x < 50 do
term.setCursorPos(x,1)
term.write("_")
term.setCursorPos(x,18)
term.write("~")
x = x + 1
end
-- Print Paddles
y = 0
while y < 3 do
term.setCursorPos(3,playerY + y)
term.write("]")
term.setCursorPos(47,compY + y)
term.write("[")
y = y + 1
end
-- Print Score
term.setCursorPos(22,9)
term.write(playerScore.." vs "..compScore)
-- Print Ball
term.setCursorPos(ballX,ballY)
term.write("O")
if gTimer == false then
os.startTimer(2 / ballS)
gTimer = true
end
local event, earg = os.pullEvent()
if event == "timer" then
moveball()
end
if event == "key" and earg == 1 then
term.clear()
break
end
if event == "key" then
moveplayer(earg)
end
end
term.clear()
term.setCursorPos(1,1)

Connect HTTP Parser(Original connect program that uses luajava, you could easily convert to HTTP or just rip the parser from it)
Spoiler


local tArgs = { ... }
term.clear()
print "Please use http://"
jURL = luajava.newInstance("java.net.URL", tArgs[1])

jBufferedReader = luajava.newInstance("java.io.BufferedReader",
	luajava.newInstance("java.io.InputStreamReader",
		jURL:openStream()
	)
)

local str = jBufferedReader:readLine()
tLines = {}
a = 1
local file = io.open( "parse", "w" )
while( str ) do  
file:write( str .. "n")
	str = jBufferedReader:readLine()

end
file:close()

nl = "n"

filename = "parse"

function HTML_ToText (file)
  local text
  local f=io.open (file)
  if f then
	text = f:read ("*a")
	f:close()
  end
  text = string.gsub (text,"(<([^>]-)>)",function (str) return str:lower() end)

  local devkill=
	{
	  ["("..string.char(10)..")"] = " ",
	  ["("..string.char(13)..")"] = " ",
	  ["("..string.char(15)..")"] = "",
	  ["(%s%s+)"]=" ",
	}
  for pat, res in pairs (devkill) do
	text = string.gsub (text, pat, res)
  end

  text = string.gsub (text, "(<%s*head[^>]*>)", "<head>")
  text = string.gsub (text, "(<%s*%/%s*head%s*>)", "</head>")
  text = string.gsub (text, "(<head>,*<%/head>)", "")

  text = string.gsub (text, "(<%s*script[^>]*>)", "<script>")
  text = string.gsub (text, "(<%s*%/%s*script%s*>)", "</script>")
  text = string.gsub (text, "(<script>,*<%/script>)", "")

  text = string.gsub (text, "(<%s*style[^>]*>)", "<style>")
  text = string.gsub (text, "(<%s*%/%s*style%s*>)", "</style>")
  text = string.gsub (text, "(<style>.*<%/style>)", "")


  text = string.gsub (text, "(<%s*td[^>]*>)","t")
  text = string.gsub (text, "(<%s*th[^>]*>)","t")


  text = string.gsub (text, "(<%s*br%s*%/%s*>)",nl)

  text = string.gsub (text, "(<%s*li%s*%s*>)"," *  ")
  text = string.gsub (text, "(<%s*/%s*li%s*%s*>)",nl)

  text = string.gsub (text, "(<%s*div[^>]*>)", nl..nl)
  text = string.gsub (text, "(<%s*p[^>]*>)", nl..nl)
  text = string.gsub (text, "(<%s*tr[^>]*>)", nl..nl)
  text = string.gsub (text, "(<%s*%/*%s*ul[^>]*>)", nl..nl)

  local addresses,c = {},0
  text=string.gsub(text,"<%s*a.-href=['"](%S+)['"][^>]*>(.-)<%s*%/*%s*a[^>]->",
  function (url,name)
	c = c + 1
	name = string.gsub (name, "<([^>]-)>","")


	if name:find("%w") then print(url, name, c) table.insert (addresses, {url, name}) return name.."["..#addresses.."]" else return "" end	
  end)




  local entities = {}
  setmetatable (entities,
  {
	__newindex = function (tbl, key, value)
	  key = string.gsub (key, "(%#)" , "%%#")
	  key = string.gsub (key, "(%&amp;)" , "%%&amp;")
	  key = string.gsub (key, "(%:P/>/>" , "%%;")
	  key = string.gsub (key, "(.+)" , "("..key..")")
	  rawset (tbl, key, value)
	end
  })
  entities =
  {
	["&amp;nbsp;"] = " ",
	["&amp;bull;"] = " *  ",
	["&amp;lsaquo;"] = "<",
	["&amp;rsaquo;"] = ">",
	["&amp;trade;"] = "(tm)",
	["&amp;frasl;"] = "/",
	["&amp;lt;"] = "<",
	["&amp;gt;"] = ">",
	["&amp;copy;"] = "(c)",
	["&amp;reg;"] = "(r)",
	["%&amp;.+%;"] = "",
  }
  for entity, repl in pairs (entities) do
	text = string.gsub (text, entity, repl)
  end


  if #addresses > 0 then
	text=text..nl:rep(2)..("-"):rep(2)..nl
	for key, tbl in ipairs(addresses) do
	  text = text..nl.."["..key.."]"..tbl[1]
	end
  end

  return text

end
local f=io.open(filename..".txt", "w")
f:write(HTML_ToText (filename))
f:close()
term.clear()
local tLines = {}
local f=io.open(filename..".txt", "r" )
local sLine = f:read()
while sLine do
table.insert( tLines, sLine )
sLine = f:read()
end
file:close()
table.insert( tLines, "" )

for n, sLine in ipairs( tLines ) do
print (tLines[n])
sleep(.2)
end
shell.run( "rm", "parse" )
print ("File saved in parse.txt")

Send/Receive Files (Before Rednet, I still use variations of these for myself)
Send
Spoiler


term.clear()
if rs.getBundledInput("back") > 0 then
print ("Someone else is currently sending a file across the server.")
end

local tArgs = { ... }
if #tArgs == 0 then
error( "You must include a valid filename." )
end
filename = tArgs[1]
ioline = "back"

if fs.exists(filename) then
print "Sending File Now..."
local function binary(num)
local bin = {}
num = math.floor(num)
repeat
table.insert(bin, num%2)
num = math.floor(num/2)
until num == 0
return table.concat(bin):reverse()
end

if luajava then javaon = true end

function bit(p)
  return 2 ^ (p - 1)
end
function hasbit(x, p)
  return x % (p + p) >= p
end
function setbit(x, p)
  return hasbit(x, p) and x or x + p
end
function clearbit(x, p)
  return hasbit(x, p) and x - p or x
end
function getline(line)
_ = 1
bin = 0
while true do
if tonumber(string.sub(line, _, _)) == 1 then bin = setbit(bin, bit(_)) end
_ = _ + 1
if _ > string.len(line) then break end
end
return bin
end
if javaon == true then
sys = luajava.bindClass("java.lang.System")
starttime = sys:currentTimeMillis()
end
lines = {}
chars = {}
y = 1
byteslong = 0
output = ""
file = io.open(filename, "r")
while true do
lines[y] = file:read()
if lines[y] == nil then break end
x = 1
while x < string.len(lines[y]) + 1 do
chars[x] = string.sub(lines[y], x, x)
byteslong = byteslong + 1
tmp = string.byte(chars[x])
tmp = binary(tmp)
tmp = tostring(tmp)
while string.len(tmp) < 8 do
	tmp = "0" .. tmp
end
output = output .. tmp
x = x + 1
end
output = output .. "10101101"
byteslong = byteslong + 1
y = y + 1
end
while true do
tmp = string.sub(output,1,16)
out = getline(tmp)
rs.setBundledOutput(ioline, out)
sleep(.05)
if string.len(output) > 16 then
output = string.sub(output,17)
else
break
end
end
rs.setBundledOutput(ioline, 0)
if javaon == true then
timetaken = (sys:currentTimeMillis() - starttime) / 1000
print ("File sent in "..timetaken.." seconds")
print ("File was "..byteslong.." bytes long.")
print ("Thats "..(byteslong / timetaken).." bps")
else
print "Java isn't on or I would tell you how fast that shit flew"
end
file:close()
else
print "You can't send something that doesn't exist dummy."
end
Receive
Spoiler


local tArgs = { ... }
if #tArgs == 0 then
error( "You must include a valid filename." )
end
filename = tArgs[1]
ioline = "back"

function bit(p)
  return 2 ^ (p - 1)
end
function hasbit(x, p)
  return x % (p + p) >= p
end
function setbit(x, p)
  return hasbit(x, p) and x or x + p
end
function clearbit(x, p)
  return hasbit(x, p) and x - p or x
end

bin = {}
x = 1
while true do
event, param1, param2 = os.pullEvent()
if event == "redstone" then
bin[x] = rs.getBundledInput(ioline)
if bin[x] == 0 then break end
x = x + 1
end
end
total = x - 1
x = 1
tmp1 = ""
tmp2 = ""
output = ""
while true do

a = 1
while true do
if hasbit(bin[x],bit(a)) then
if a <= 8 then tmp1 = tmp1 .. "1" else tmp2 = tmp2 .. "1" end
else
if a <= 8 then tmp1 = tmp1 .. "0" else tmp2 = tmp2 .. "0" end
end
a = a + 1
if a == 17 then break end
end

newl = tonumber("10101101", 2)
tmp1 = tonumber(tmp1, 2)
tmp2 = tonumber(tmp2, 2)
if tmp1 == newl then tmp1 = "n" else tmp1 = string.char(tmp1) end
if tmp2 == newl then tmp2 = "n" else tmp2 = string.char(tmp2) end
output = output .. tmp1 .. tmp2
tmp1 = ""
tmp2 = ""
x = x + 1
if x > total then break end
end
file = io.open(filename, "w")
file:write(output)
file:close()

CCIRC: (ComputerCraft IRC) (Not really outdated, but 1.3 can allow connection to real IRC's through peripherals
SpoilerLink: CCIRC
About:
A virtual IRC server that can be used in SSP and SMP
Features:
Almost all the lovely features of a real IRC I can handle.

LuaJava CC Debugger(Requires LuaJava)
Spoiler


sys = luajava.bindClass("java.awt.datatransfer.Clipboard")


frame = luajava.newInstance("java.awt.Frame", "CC Debugger Console")
console = luajava.newInstance("java.awt.TextArea")
buttons_pn = luajava.newInstance("java.awt.Panel")
execute_bt = luajava.newInstance("java.awt.Button", "Run")
clear_bt = luajava.newInstance("java.awt.Button", "Clear")
exit_bt = luajava.newInstance("java.awt.Button", "Quit")

frame:setSize(600,300)

buttons_pn:add(execute_bt)
buttons_pn:add(clear_bt)
buttons_pn:add(exit_bt)

BorderLayout = luajava.bindClass("java.awt.BorderLayout")

frame:add(BorderLayout.NORTH, console)
frame:add(BorderLayout.SOUTH, buttons_pn)
frame:pack()
frame:show()
frame:toFront()
frame:repaint()

execute_cb = {
actionPerformed = function(ev)
_test = loadstring(console:getText())
setfenv( _test, getfenv() )
_test()

end
}

jproxy = luajava.createProxy("java.awt.event.ActionListener",execute_cb)

execute_bt:addActionListener(jproxy)


clear_cb = {actionPerformed= function (ev)
  console:setText("");
end
}

jproxy = luajava.createProxy("java.awt.event.ActionListener" ,clear_cb)
clear_bt:addActionListener(jproxy)

exit_cb = { actionPerformed=function (ev)
  frame:setVisible(false)
  frame:dispose()
end
}


jproxyb = luajava.createProxy("java.awt.event.ActionListener" ,exit_cb)

exit_bt:addActionListener(jproxyb)

close_cb = {  }
function close_cb.windowClosing(ev)
  frame:setVisible(false)
  frame:dispose()
end

function close_cb.windowActivated(ev)
end

jproxy = luajava.createProxy("java.awt.event.WindowListener", close_cb)
frame:addWindowListener(jproxy)

Weee
Casper7526 #2
Posted 31 January 2012 - 09:40 PM
Added Debug program.
FuzzyPurp #3
Posted 01 February 2012 - 04:43 AM
Added Debug program.

Getting an error running the debugger on line 2,

EDIT: Didn't check the usage, derp!
hobnob11 #4
Posted 17 February 2012 - 03:55 PM
errr, i just made a program to check the lable of a disk and then activate some pistons to open a door, basicly a keycard type thing, anyway when i run it i get this error:

[string "door"]:3: '=' expected

so i try this debig program… and i get THE SAME ERROR…


string ["deBUGtmp"]:8: '=' expected

ima post my door code in another thread and see if anyone can help

EDIT: http://www.computercraft.info/forums2/index.php?/topic/110-string-door3-expected/ (link to my door code :D/>/> )
Espen #5
Posted 17 February 2012 - 04:10 PM
@hobnob11:
Answered you in your linked thread.
Casper7526 #6
Posted 17 February 2012 - 07:15 PM
Heh, my debug program was made so that if you DONT get a line number, it will help you debug your problem. If you receive a line number, well then you kinda know where the problem is already. It's for those nasty attempt to call nils and such like that.
smithy21 #7
Posted 18 February 2012 - 10:07 AM
How can you make the IRC Program Connect To A Different IRC Server?
Casper7526 #8
Posted 18 February 2012 - 02:49 PM
The IRC program is a virtual IRC, it's not really a real IRC so it can't really just hook up to another server ^_^/>/>
Jaan #9
Posted 27 February 2012 - 09:55 AM
Best programs i been ever seen! :o/>/>
But! I need help with installing the Minecraft in minecraft (mineception ;)/>/>) ;)/>/>
I got the .png file and i did put the .png in to minecraft.jar, then when i run minecraft, the font was really screwd up! :P/>/>
Casper7526 #10
Posted 27 February 2012 - 06:06 PM
What do you mean the font was really screwed up ? hehe

It uses the extended ascii part of the default font to show the sprites, therefor I think if you have your localization as something that uses those extended ascii you might definitly get some screwyness.
Wired2coffee #11
Posted 29 February 2012 - 04:12 AM
Brilliant! I love MiM!
Av3ng3d Nobl3 #12
Posted 03 March 2012 - 02:33 AM
Dude, does the nbs converter go to text or something else?
Casper7526 #13
Posted 03 March 2012 - 04:01 AM
yeah it converts nbs files into text (a format I designed for my own use) so you would either need to use that format or well write your own converter :unsure:/>/>
Xtansia #14
Posted 03 March 2012 - 04:26 AM
yeah it converts nbs files into text (a format I designed for my own use) so you would either need to use that format or well write your own converter :unsure:/>/>

Do you still have your interpreter code?
Casper7526 #15
Posted 03 March 2012 - 05:00 AM
Well any interp code will basically only work on whatever setup you have for noteblocks.
My text format is pretty self explanatory though and writing an interp program isn't that much work.

T10 = tempo of 10 (like your looking at it in nbs)
1 = use octave 1
2 = use octave 2
3 = use octave 3 (only used for the last F#)
PI = piano
CS = clicks/sticks
BD = bass drum
BG = bass guitar
SD = snare drum
All the notes…

. = play notes / rest
Av3ng3d Nobl3 #16
Posted 03 March 2012 - 08:53 PM
When i go 2 run the nbs converter in computercraft it says io:27 bad argument: string expected, got nil
Casper7526 #17
Posted 03 March 2012 - 09:38 PM
let's assume you named the program nbs (when you downloaded it)
Usage: <nbs file> <txt file>
nbs mysong.nbs converted.txt
Av3ng3d Nobl3 #18
Posted 04 March 2012 - 12:58 AM
I tried that it nbs:6: says attempt to call index ? (a nil value)
Casper7526 #19
Posted 04 March 2012 - 04:54 AM
I'm not sure what your having an issue with, is the nbs program placed on a computer? and is the nbs song placed in the same place as the program?

If still not working and you can't get it to work, attach the nbs file your looking to convert.
Av3ng3d Nobl3 #20
Posted 04 March 2012 - 04:59 PM
Yeah i tried everything heres the nbs file link
http://www.mediafire.com/?n9lpa92cvrplnbu
Casper7526 #21
Posted 04 March 2012 - 07:49 PM
I assume because you didn't rename the nbs to 1 word and were trying to type nbs James Bond Theme.nbs blah.txt

I renamed the nbs to bond.nbs then did

nbs bond.nbs bond.txt

http://pastebin.com/N0p42V7B
Av3ng3d Nobl3 #22
Posted 05 March 2012 - 08:02 PM
How do u play the converted nbs file?
Casper7526 #23
Posted 05 March 2012 - 08:45 PM
You gotta write a player yourself as the "player" would be custom to whoever setup the noteblock system (the colors and computers and ect ect)
Av3ng3d Nobl3 #24
Posted 05 March 2012 - 10:37 PM
Could you show me how to make the piano? plz
Av3ng3d Nobl3 #25
Posted 12 March 2012 - 10:56 PM
plz respond
Casper7526 #26
Posted 13 March 2012 - 12:54 AM
I'm not sure what you mean by "make" the piano…. You simply read each line of the nbs file and tell your computer to send a redstone signal to that note at that time.
Av3ng3d Nobl3 #27
Posted 15 March 2012 - 07:14 PM
Could u put a sample player 4 download so i can figure it out
crimsonknight3 #28
Posted 16 March 2012 - 03:14 PM
A quick question for you casper, is it possible to connect to other irc servers through your program? Its such a great idea but your irc channel is dead beyond belief but there are other irc servers i use from time to time, got a nice massive monitor put up, just waiting for a wireless keyboard peripherial lol
Casper7526 #29
Posted 16 March 2012 - 03:36 PM
CCIRC = "virtual irc"

It's not a real IRC server, and now that peripherals are out, someone can easily write a IRC peripheral to connect to real IRC servers. So CCIRC will stay up, but only as a "proof of concept" sorta thing. I highly doubt it will ever be used very much.
crimsonknight3 #30
Posted 16 March 2012 - 03:54 PM
Well i take my hat off to you anyway as its an amazing concept!! Socialism of smp but without the lag or mess or grief haha
maarten1012 #31
Posted 24 March 2012 - 04:38 PM
I assume because you didn't rename the nbs to 1 word and were trying to type nbs James Bond Theme.nbs blah.txt

I renamed the nbs to bond.nbs then did

nbs bond.nbs bond.txt

http://pastebin.com/N0p42V7B

when i do: nbs nyan.nbs nyansong.txt i get the same error?
ds84182 #32
Posted 26 March 2012 - 02:59 AM
May I change your NBS converter to support my audio file format. I'll give you credit.

EDIT: Nevermind… It seems like the code is way too messy for me (NO TABS)

EDIT AGAIN: Does It Support Layers?
Casper7526 #33
Posted 26 March 2012 - 07:46 AM
Layers? It supports everything but volume levels. And yes the code is messy (there are tabs, just not online) but even with tabs the code is messy looking lol.
Loopin #34
Posted 28 March 2012 - 11:35 PM
Im getting a error on ccirc.

appears like this:ccirc:32: bad argument : number expected, got nil
Bmandk #35
Posted 01 June 2012 - 06:16 PM
Casper, I'm wondering if you can make a decoder sheet so I can see what is what in the txt file and compare it to the equivalent things in NBS. The only thing I could figure out was what the dots and the nodes were.

EDIT: Ok, I got most, except the octaves. Those are just messed up.
ElectricOverride #36
Posted 10 October 2012 - 05:32 PM
I'll make this look better when I get done doing well the whole damn site.

MiM (Minecraft in Minecraft) (One day I'll continue working on this)
Link: MiM (Direct Fire if your having problems - http://www.mediafire...gbppjttghp1vlhr
About:
Minecraft in Minecraft!
Features:
Creates a new font inside your computer directory which you can then copy to your minecraft.jar!
OldVideo:
Spoiler[media]http://www.youtube.com/watch?v=sYVmooRe4n0[/media]


NBS Converter
Link: NBS Converter
About:
Converts .NBS (Note Block Studio) Files into a custom format designed by me.


Tutorial
Link: Tutorial
About:
An Interactive In-Game Tutorial for ComputerCraft

IN-GAME DEBUGGER (Outdated and kinda pointless as of 1.3)
Link: DEBUG
About:
Gives you some information about where and what caused your program to crash.
Usage = debug <programname> <tracebackcount> <args>
Notes/Bugs:
None ATM, need more test cases.

The program will give you detailed information (as much as I can) about your crash.
A FULL traceback is found in the "debugtraceback" file each time you run debug on your program.

PIC In Action!
Spoiler


Random Programs
I am just going to post all kinds of random programs here that I don't deem worthy to make it into my "you should really check out list"
These programs will be labeled, but their usage and such will prolly not be explained. They also might be buggy as I'm just going to go through and copy the
files that I find first.

Pong
Spoiler


-- Pong V1 for ComputerCraft
-- Coded By Casper
-- Have fun and well... idk I was bored.
controlU = 17
controlD = 31
function diffselect()
term.clear()
print "Select Difficulty:"
print "1. LOL"
print "2. Easy"
print "3. Normal"
print "4. Hard"
print "5. Seriously?"
print "6. Change Bindings off of W/Sn"
diff = io.read()
if diff == "5" then gDiff = 500 end
if diff == "4" then gDiff = 300 end
if diff == "3" then gDiff = 100 end
if diff == "2" then gDiff = 50 end
if diff == "1" then gDiff = 10 end
if diff == "6" then
sleep(.5)
print "Press the key you wish to move upwards with."
local event, earg = os.pullEvent()
controlU = earg
sleep(.5)
print "Press the key you wish to move downards with."
local event, earg = os.pullEvent()
controlD = earg
diffselect()
end
end
diffselect()
gRunning = true
playerY = 2
compY = 2
ballY = 10
ballX = 24
ballA = 0
ballS = 12
ballD = -1
gTimer = false
cTimer = 0
playerScore = 0
compScore = 0
function round(num)
	under = math.floor(num)
	upper = math.floor(num) + 1
	underV = -(under - num)
	upperV = upper - num
	if (upperV > underV) then
		return under
	else
		return upper
	end
end

function score()
term.clear()
if ballX <= 1 then
compScore = compScore + 1
term.setCursorPos(16,9)
term.write("Computer SCOOOORES!")
end
if ballX >= 49 then
playerScore = playerScore + 1
term.setCursorPos(16,9)
term.write("Player SCOOOORES!")
end
sleep(2)
if compScore == 5 or playerScore == 5 then
gRunning = false
term.clear()
term.setCursorPos(16,9)
if ballX >= 49 then term.write("Player WIIIINS!") else term.write("Computer WIIIINS!") end
sleep(2)
end
ballY = 10
ballX = 24
ballA = 0
ballS = 12
gTimer = false
cTimer = 0
rnd = math.random(1, 2)
if rnd == 1 then ballD = -1 else ballD = 1 end
end

function moveplayer(earg)
if earg == controlU then playerY = playerY - 1 end
if earg == controlD then playerY = playerY + 1 end
if playerY < 2 then playerY = 2 end
if playerY > 15 then playerY = 15 end
end


function updateangle(ang)
if ang == 0 then
if ballA <= 0 then ballA = ballA - 2 else ballA = ballA + 1 end
end
if ang == 2 then
if ballA <= 0 then ballA = ballA + 2 else ballA = ballA - 1 end
end
term.clear()
print (ang)
print (ballA)
sleep(1)
end




function contact()
if (ballY == playerY and ballX == 3) or (ballY == compY and ballX == 47) then
if ballA <= 0 then ballA = ballA - 1 else ballA = ballA + .6 end
return (true)
end
if (ballY == playerY + 1 and ballX == 3) or (ballY == compY + 1 and ballX == 47) then
if ballA >= 1.25 then ballA = ballA - .45 end
if ballA <= -1.25 then ballA = ballA + .45 end
if ballA <= 0 then ballA = ballA - .35 else ballA = ballA + .35 end
return (true)
end
if (ballY == playerY + 2 and ballX == 3) or (ballY == compY + 2 and ballX == 47) then
if ballA <= 0 then ballA = ballA + 1 else ballA = ballA - .6 end
return (true)
end
return (false)
end

function movecomp()
if ballY > compY + 1 then compY = compY + 1 else compY = compY - 1 end
if compY < 2 then compY = 2 end
if compY > 15 then compY = 15 end
cTimer = false
end

function moveball()
ballX = ballX + ballD
if ballX == 3 and contact() == true then
ballD = 1
ballX = 4
ballS = ballS + (ballS / 3)
end
if ballX == 47 and contact() == true then
ballD = -1
ballX = 46
ballS = ballS + (ballS / 3)
end
if ballX == 1 then score() end
if ballX == 49 then score() end

if ballA >= 1.75 then ballA = ballA - .35 end
if ballA <= -1.75 then ballA = ballA + .35 end
oldbally = ballY
ballY = ballY + round(ballA)
if ballY <= 2 or ballY >= 17 then
ballY = oldbally
ballA = ballA * -1
end
if ballS > 30 then
rnd = math.random(1, 10)
ballS = ballS - rnd
end


gTimer = false
if ballS >= 150 and moved == false then
moved = true
moveball()
end
rnd = math.random(1, gDiff) * .1
cTimer = cTimer + rnd
if cTimer >= 1 then
movecomp()
cTimer = 0
end
moved = false
end

-- 18 x 49
while gRunning do
term.clear()
y = 1
x = 1
-- Print Game Area
while y < 19 do
term.setCursorPos(1,y)
term.write("|")
term.setCursorPos(49,y)
term.write("|")
y = y + 1
end
while x < 50 do
term.setCursorPos(x,1)
term.write("_")
term.setCursorPos(x,18)
term.write("~")
x = x + 1
end
-- Print Paddles
y = 0
while y < 3 do
term.setCursorPos(3,playerY + y)
term.write("]")
term.setCursorPos(47,compY + y)
term.write("[")
y = y + 1
end
-- Print Score
term.setCursorPos(22,9)
term.write(playerScore.." vs "..compScore)
-- Print Ball
term.setCursorPos(ballX,ballY)
term.write("O")
if gTimer == false then
os.startTimer(2 / ballS)
gTimer = true
end
local event, earg = os.pullEvent()
if event == "timer" then
moveball()
end
if event == "key" and earg == 1 then
term.clear()
break
end
if event == "key" then
moveplayer(earg)
end
end
term.clear()
term.setCursorPos(1,1)

Connect HTTP Parser(Original connect program that uses luajava, you could easily convert to HTTP or just rip the parser from it)
Spoiler


local tArgs = { ... }
term.clear()
print "Please use http://"
jURL = luajava.newInstance("java.net.URL", tArgs[1])

jBufferedReader = luajava.newInstance("java.io.BufferedReader",
	luajava.newInstance("java.io.InputStreamReader",
		jURL:openStream()
	)
)

local str = jBufferedReader:readLine()
tLines = {}
a = 1
local file = io.open( "parse", "w" )
while( str ) do  
file:write( str .. "n")
	str = jBufferedReader:readLine()

end
file:close()

nl = "n"

filename = "parse"

function HTML_ToText (file)
  local text
  local f=io.open (file)
  if f then
	text = f:read ("*a")
	f:close()
  end
  text = string.gsub (text,"(<([^>]-)>)",function (str) return str:lower() end)

  local devkill=
	{
	  ["("..string.char(10)..")"] = " ",
	  ["("..string.char(13)..")"] = " ",
	  ["("..string.char(15)..")"] = "",
	  ["(%s%s+)"]=" ",
	}
  for pat, res in pairs (devkill) do
	text = string.gsub (text, pat, res)
  end

  text = string.gsub (text, "(<%s*head[^>]*>)", "<head>")
  text = string.gsub (text, "(<%s*%/%s*head%s*>)", "</head>")
  text = string.gsub (text, "(<head>,*<%/head>)", "")

  text = string.gsub (text, "(<%s*script[^>]*>)", "<script>")
  text = string.gsub (text, "(<%s*%/%s*script%s*>)", "</script>")
  text = string.gsub (text, "(<script>,*<%/script>)", "")

  text = string.gsub (text, "(<%s*style[^>]*>)", "<style>")
  text = string.gsub (text, "(<%s*%/%s*style%s*>)", "</style>")
  text = string.gsub (text, "(<style>.*<%/style>)", "")


  text = string.gsub (text, "(<%s*td[^>]*>)","t")
  text = string.gsub (text, "(<%s*th[^>]*>)","t")


  text = string.gsub (text, "(<%s*br%s*%/%s*>)",nl)

  text = string.gsub (text, "(<%s*li%s*%s*>)"," *  ")
  text = string.gsub (text, "(<%s*/%s*li%s*%s*>)",nl)

  text = string.gsub (text, "(<%s*div[^>]*>)", nl..nl)
  text = string.gsub (text, "(<%s*p[^>]*>)", nl..nl)
  text = string.gsub (text, "(<%s*tr[^>]*>)", nl..nl)
  text = string.gsub (text, "(<%s*%/*%s*ul[^>]*>)", nl..nl)

  local addresses,c = {},0
  text=string.gsub(text,"<%s*a.-href=['"](%S+)['"][^>]*>(.-)<%s*%/*%s*a[^>]->",
  function (url,name)
	c = c + 1
	name = string.gsub (name, "<([^>]-)>","")


	if name:find("%w") then print(url, name, c) table.insert (addresses, {url, name}) return name.."["..#addresses.."]" else return "" end	
  end)




  local entities = {}
  setmetatable (entities,
  {
	__newindex = function (tbl, key, value)
	  key = string.gsub (key, "(%#)" , "%%#")
	  key = string.gsub (key, "(%&amp;)" , "%%&amp;")
	  key = string.gsub (key, "(%:P/>/>" , "%%;")
	  key = string.gsub (key, "(.+)" , "("..key..")")
	  rawset (tbl, key, value)
	end
  })
  entities =
  {
	["&amp;nbsp;"] = " ",
	["&amp;bull;"] = " *  ",
	["&amp;lsaquo;"] = "<",
	["&amp;rsaquo;"] = ">",
	["&amp;trade;"] = "(tm)",
	["&amp;frasl;"] = "/",
	["&amp;lt;"] = "<",
	["&amp;gt;"] = ">",
	["&amp;copy;"] = "(c)",
	["&amp;reg;"] = "(r)",
	["%&amp;.+%;"] = "",
  }
  for entity, repl in pairs (entities) do
	text = string.gsub (text, entity, repl)
  end


  if #addresses > 0 then
	text=text..nl:rep(2)..("-"):rep(2)..nl
	for key, tbl in ipairs(addresses) do
	  text = text..nl.."["..key.."]"..tbl[1]
	end
  end

  return text

end
local f=io.open(filename..".txt", "w")
f:write(HTML_ToText (filename))
f:close()
term.clear()
local tLines = {}
local f=io.open(filename..".txt", "r" )
local sLine = f:read()
while sLine do
table.insert( tLines, sLine )
sLine = f:read()
end
file:close()
table.insert( tLines, "" )

for n, sLine in ipairs( tLines ) do
print (tLines[n])
sleep(.2)
end
shell.run( "rm", "parse" )
print ("File saved in parse.txt")

Send/Receive Files (Before Rednet, I still use variations of these for myself)
Send
Spoiler


term.clear()
if rs.getBundledInput("back") > 0 then
print ("Someone else is currently sending a file across the server.")
end

local tArgs = { ... }
if #tArgs == 0 then
error( "You must include a valid filename." )
end
filename = tArgs[1]
ioline = "back"

if fs.exists(filename) then
print "Sending File Now..."
local function binary(num)
local bin = {}
num = math.floor(num)
repeat
table.insert(bin, num%2)
num = math.floor(num/2)
until num == 0
return table.concat(bin):reverse()
end

if luajava then javaon = true end

function bit(p)
  return 2 ^ (p - 1)
end
function hasbit(x, p)
  return x % (p + p) >= p
end
function setbit(x, p)
  return hasbit(x, p) and x or x + p
end
function clearbit(x, p)
  return hasbit(x, p) and x - p or x
end
function getline(line)
_ = 1
bin = 0
while true do
if tonumber(string.sub(line, _, _)) == 1 then bin = setbit(bin, bit(_)) end
_ = _ + 1
if _ > string.len(line) then break end
end
return bin
end
if javaon == true then
sys = luajava.bindClass("java.lang.System")
starttime = sys:currentTimeMillis()
end
lines = {}
chars = {}
y = 1
byteslong = 0
output = ""
file = io.open(filename, "r")
while true do
lines[y] = file:read()
if lines[y] == nil then break end
x = 1
while x < string.len(lines[y]) + 1 do
chars[x] = string.sub(lines[y], x, x)
byteslong = byteslong + 1
tmp = string.byte(chars[x])
tmp = binary(tmp)
tmp = tostring(tmp)
while string.len(tmp) < 8 do
	tmp = "0" .. tmp
end
output = output .. tmp
x = x + 1
end
output = output .. "10101101"
byteslong = byteslong + 1
y = y + 1
end
while true do
tmp = string.sub(output,1,16)
out = getline(tmp)
rs.setBundledOutput(ioline, out)
sleep(.05)
if string.len(output) > 16 then
output = string.sub(output,17)
else
break
end
end
rs.setBundledOutput(ioline, 0)
if javaon == true then
timetaken = (sys:currentTimeMillis() - starttime) / 1000
print ("File sent in "..timetaken.." seconds")
print ("File was "..byteslong.." bytes long.")
print ("Thats "..(byteslong / timetaken).." bps")
else
print "Java isn't on or I would tell you how fast that shit flew"
end
file:close()
else
print "You can't send something that doesn't exist dummy."
end
Receive
Spoiler


local tArgs = { ... }
if #tArgs == 0 then
error( "You must include a valid filename." )
end
filename = tArgs[1]
ioline = "back"

function bit(p)
  return 2 ^ (p - 1)
end
function hasbit(x, p)
  return x % (p + p) >= p
end
function setbit(x, p)
  return hasbit(x, p) and x or x + p
end
function clearbit(x, p)
  return hasbit(x, p) and x - p or x
end

bin = {}
x = 1
while true do
event, param1, param2 = os.pullEvent()
if event == "redstone" then
bin[x] = rs.getBundledInput(ioline)
if bin[x] == 0 then break end
x = x + 1
end
end
total = x - 1
x = 1
tmp1 = ""
tmp2 = ""
output = ""
while true do

a = 1
while true do
if hasbit(bin[x],bit(a)) then
if a <= 8 then tmp1 = tmp1 .. "1" else tmp2 = tmp2 .. "1" end
else
if a <= 8 then tmp1 = tmp1 .. "0" else tmp2 = tmp2 .. "0" end
end
a = a + 1
if a == 17 then break end
end

newl = tonumber("10101101", 2)
tmp1 = tonumber(tmp1, 2)
tmp2 = tonumber(tmp2, 2)
if tmp1 == newl then tmp1 = "n" else tmp1 = string.char(tmp1) end
if tmp2 == newl then tmp2 = "n" else tmp2 = string.char(tmp2) end
output = output .. tmp1 .. tmp2
tmp1 = ""
tmp2 = ""
x = x + 1
if x > total then break end
end
file = io.open(filename, "w")
file:write(output)
file:close()

CCIRC: (ComputerCraft IRC) (Not really outdated, but 1.3 can allow connection to real IRC's through peripherals
SpoilerLink: CCIRC
About:
A virtual IRC server that can be used in SSP and SMP
Features:
Almost all the lovely features of a real IRC I can handle.

LuaJava CC Debugger(Requires LuaJava)
Spoiler


sys = luajava.bindClass("java.awt.datatransfer.Clipboard")


frame = luajava.newInstance("java.awt.Frame", "CC Debugger Console")
console = luajava.newInstance("java.awt.TextArea")
buttons_pn = luajava.newInstance("java.awt.Panel")
execute_bt = luajava.newInstance("java.awt.Button", "Run")
clear_bt = luajava.newInstance("java.awt.Button", "Clear")
exit_bt = luajava.newInstance("java.awt.Button", "Quit")

frame:setSize(600,300)

buttons_pn:add(execute_bt)
buttons_pn:add(clear_bt)
buttons_pn:add(exit_bt)

BorderLayout = luajava.bindClass("java.awt.BorderLayout")

frame:add(BorderLayout.NORTH, console)
frame:add(BorderLayout.SOUTH, buttons_pn)
frame:pack()
frame:show()
frame:toFront()
frame:repaint()

execute_cb = {
actionPerformed = function(ev)
_test = loadstring(console:getText())
setfenv( _test, getfenv() )
_test()

end
}

jproxy = luajava.createProxy("java.awt.event.ActionListener",execute_cb)

execute_bt:addActionListener(jproxy)


clear_cb = {actionPerformed= function (ev)
  console:setText("");
end
}

jproxy = luajava.createProxy("java.awt.event.ActionListener" ,clear_cb)
clear_bt:addActionListener(jproxy)

exit_cb = { actionPerformed=function (ev)
  frame:setVisible(false)
  frame:dispose()
end
}


jproxyb = luajava.createProxy("java.awt.event.ActionListener" ,exit_cb)

exit_bt:addActionListener(jproxyb)

close_cb = {  }
function close_cb.windowClosing(ev)
  frame:setVisible(false)
  frame:dispose()
end

function close_cb.windowActivated(ev)
end

jproxy = luajava.createProxy("java.awt.event.WindowListener", close_cb)
frame:addWindowListener(jproxy)

Weee

i have installed the font, now i have tried to run the game, but both attempts ge stuck on genores then in a min or so it says: bios:25: too long without yielding
Lyqyd #37
Posted 10 October 2012 - 07:59 PM
Please do not quote the entire first post for no reason.
AndreWalia #38
Posted 23 November 2012 - 04:59 PM
This is bloody amazing!! Mind if i use the Pong game in my OS??
i_am_th0r #39
Posted 12 December 2012 - 12:43 AM
On your interactive tutroial program i think some of the lines of codes are wrong because i will write my own script first than see if it works and if it dont i will re-write it with the exact code of the examples to see if it would pass and it still dont like i went through like several Simulations where your code has errors (the examples)
Tiin57 #40
Posted 12 December 2012 - 12:48 AM
On your interactive tutroial program i think some of the lines of codes are wrong because i will write my own script first than see if it works and if it dont i will re-write it with the exact code of the examples to see if it would pass and it still dont like i went through like several Simulations where your code has errors (the examples)
Casper hasn't been on in months.
Landril #41
Posted 03 January 2013 - 03:15 AM
Will the nbs converter be getting a new link? I would really appreciate it. :)/>
LayZee #42
Posted 16 October 2013 - 04:05 PM
How did you do a stack trace in your debugger?
Lyqyd #43
Posted 16 October 2013 - 04:57 PM
This is pretty ancient. Locked.