YourFace = "Hello" Print(YourFace) Worldz = "World!" Print(World) end
[CC]Code Cleanup
#61
Posted 07 July 2013 - 09:48 PM
#62
Posted 08 July 2013 - 01:59 AM
Creeper367, on 07 July 2013 - 09:48 PM, said:
YourFace = "Hello" Print(YourFace) Worldz = "World!" Print(World) end
#63
Posted 08 July 2013 - 10:41 AM
YourFace = "Hello" print(YourFace) Worldz = "World!" print(Worldz)
My turn
local symbols = {"@", "#", "$", "%", "&", "*"}
local colors = {colors.green, colors.blue, colors.yellow, colors.lime, colors.white, colors.magenta, colors.black}
local x == 0
local y == 0
function printScreenRan(amoSym)
for i = 1, 19 do
y = i
for I = 1, 20
x = I
num = Math.random(amoSym)
term.setCursorPos(xPos, yPos)
term.setBackGroundColor(colors[8])
term.setTextColor(colors[num])
print("" ..symbols[numbers])
end
end
end
printScreenRan(6)
#64
Posted 18 July 2013 - 06:40 AM
local symbols = {"@", "#", "$", "%", "&", "*"}
local colors = {colors.green, colors.blue, colors.yellow, colors.lime, colors.white, colors.magenta, colors.black}
local x = 0
local y = 0
function printScreenRan(amoSym)
for i = 1, 19 do
y = i
for I = 1, 20
x = I
num = math.random(amoSym)
term.setCursorPos(x, y)
term.setBackgroundColor(colors[7])
term.setTextColor(colors[num])
print(symbols[num])
end
end
end
printScreenRan(6)
parallel.waitForBoth(
Function()
while True do
os.pullevent("redstone")
end
end,
print read(*)
#65
Posted 19 July 2013 - 02:22 AM
reububble, on 18 July 2013 - 06:40 AM, said:
local symbols = {"@", "#", "$", "%", "&", "*"}
local colors = {colors.green, colors.blue, colors.yellow, colors.lime, colors.white, colors.magenta, colors.black}
local x = 0
local y = 0
function printScreenRan(amoSym)
for i = 1, 19 do
y = i
for I = 1, 20
x = I
num = math.random(amoSym)
term.setCursorPos(x, y)
term.setBackgroundColor(colors[7])
term.setTextColor(colors[num])
print(symbols[num])
end
end
end
printScreenRan(6)
parallel.waitForBoth(
Function()
while True do
os.pullevent("redstone")
end
end,
print read(*)
There is no parallel.waitForBoth()
Function should be function
True should be true
os.pullevent should be os.pullEvent
You didn't close waitForBoth()
#66
Posted 11 August 2013 - 04:04 AM
x = 2
y = 3
Z = 4
term.write("This is a string)
term.setCursorPos(x, y)
term.write(x + z)
If x + z = 7 then
print "yay"
else
print "nay"
End
#67
Posted 11 August 2013 - 04:48 PM
function a() print(a) end function b(nomnom) print(nomnom) end while true do parallel.waitForAny(b(), a()) end
#68
Posted 14 August 2013 - 11:33 AM
jay5476, on 11 August 2013 - 04:48 PM, said:
function a() print(a) end function b(nomnom) print(nomnom) end while true do parallel.waitForAny(b(), a()) end
#69
Posted 14 August 2013 - 01:58 PM
This is using two files, but an all-in-one is below if that's a requirement I missed.
File testapi looks like this:
function printName() print(getfenv(2).shell.getRunningProgram()) endFile testprogram looks like this:
os.loadAPI("testapi")
return testapi.printName()
In the shell, run testprogram like so:> testprogram testapi:2: attempt to index ? (a nil value) > _
All in one:
#70
Posted 24 August 2013 - 12:30 AM
Quote
If you won't post code, I will
This is using two files, but an all-in-one is below if that's a requirement I missed.
File testapi looks like this:
function printName()
print(getfenv(2).shell.getRunningProgram())
endFile testprogram looks like this:
os.loadAPI("testapi")
return testapi.printName()In the shell, run testprogram like so:
> testprogram
testapi:2: attempt to index ? (a nil value)
> _
All in one:
Spoiler
_G.testapi = { printName = setfenv(function()
print(getfenv(2).shell.getRunningProgram())
end,
setmetatable({}, {__index = _G})) }
local function program()
return testapi.printName()
end
local success, result = pcall(setfenv(program, setmetatable({shell = shell}, {__index = _G})))
if not success then
print(result)
end
mine
str = "table"
someTable = {"some","useless","table","thing"}
for k, v in pairs(someTable)
if str = v then
table.remove(someTable, k)
end
end
#71
Posted 24 August 2013 - 01:19 AM
jay5476, on 24 August 2013 - 12:30 AM, said:
Firstly, you can't name a function or variable with a number, or have it begin with a number, that is invalid syntax...
Secondly, before attempting to solve when people use environments (one of the more complicated topics in Lua), I suggest that you have a better understanding of how it works! `getfenv(2)` is perfectly valid and will not error!
The better thing to say here that on a freshly booted computer, environment 2 does not contain a shell table, environment 1 does, meaning that you'll get the error
Quote
jay5476, on 24 August 2013 - 12:30 AM, said:
str = "table"
someTable = {"some","useless","table","thing"}
for k, v in pairs(someTable)
if str = v then
table.remove(someTable, k)
end
end
Quote
Error #2
Quote
I guess I better post one to keep the game going......
local t = {
['key'] = "value",
['foo'] = "bar"
}
local function 1one()
for k,v in next(t) do
t[k] = nil
end
end
one()
#72
Posted 24 August 2013 - 02:09 AM
theoriginalbit, on 24 August 2013 - 01:19 AM, said:
jay5476, on 24 August 2013 - 12:30 AM, said:
Firstly, you can't name a function or variable with a number, or have it begin with a number, that is invalid syntax...
Secondly, before attempting to solve when people use environments (one of the more complicated topics in Lua), I suggest that you have a better understanding of how it works! `getfenv(2)` is perfectly valid and will not error!
The better thing to say here that on a freshly booted computer, environment 2 does not contain a shell table, environment 1 does, meaning that you'll get the error
Quote
jay5476, on 24 August 2013 - 12:30 AM, said:
str = "table"
someTable = {"some","useless","table","thing"}
for k, v in pairs(someTable)
if str = v then
table.remove(someTable, k)
end
end
Quote
Error #2
Quote
I guess I better post one to keep the game going......
local t = {
['key'] = "value",
['foo'] = "bar"
}
local function 1one()
for k,v in next(t) do
t[k] = nil
end
end
one()
well theres one more error that I know of and you helped me solve it for me yesterday
but as for your error, you state one in your reply
#error1
you cannot start a function with a number
#error2
no function called one has been defined
#73
Posted 24 August 2013 - 02:15 AM
theoriginalbit, on 24 August 2013 - 01:19 AM, said:
local t = {
['key'] = "value",
['foo'] = "bar"
}
local function 1one()
for k,v in next(t) do
t[k] = nil
end
end
one()
local t = {
['key'] = "value",
['foo'] = "bar"
}
local function one()
for k,v in next, t do
t[k] = nil
end
end
one()
Variable cannot start with a number (you can have a number in it, but not as the first character);
Not sure about this one but the "next" iterator is used like this "for k,v in next, t do....";
The "one" function doesn't exist since it would have errored at "function 1one()".
local mon = peripheral.warp("buttom")
local mSize = mon.getSizes()
for i == 1, mSize.y, 1 then
for j == 1, mSize.x then
mon.setTextColors(2^random(0,16)
mon.setCursorPos(i, j)
mon.print(" ")
end
#74
Posted 24 August 2013 - 05:06 PM
jay5476, on 24 August 2013 - 12:30 AM, said:
theoriginalbit, on 24 August 2013 - 01:19 AM, said:
That is also not the right answer
Consider, when adjusting testprogram to this:
os.loadAPI("testapi")
return testapi.printName() or nil
An then run it:> testprogram testprogram > _
Why? Because otherwise it's a tail call. Therefore getfenv(2) fails, because the calling environment (that of testprogram, which does contain the shell table) doesn't exist anymore. In fact, any good Lua VM will tell you this when you run getfenv(2) (try it on ideone.com for example). But in CC it appears to silently fail and return nil instead.
#76
Posted 30 August 2013 - 11:21 AM
guy = "@"
guyX = 9
guyY = 9
while true do
event, key = os.pullEvent("key")
If key == keys.Left then
guyX = guyX-1
elseIf key == keys.right then
guyX = guyX+1
Elseif key == keys.up then
guyY = guyY -1
elSeif key == keys.down then
guyY = guyY+1
end
term.clear()
term.setCursorPos(guyX, guyY)
print(guy)
end
#77
Posted 30 August 2013 - 11:58 PM
RatcheT2497, on 30 August 2013 - 11:21 AM, said:
guy = "@"
guyX = 9
guyY = 9
while true do
event, key = os.pullEvent("key")
if key == keys.left then
guyX = guyX-1
elseif key == keys.right then
guyX = guyX+1
elseif key == keys.up then
guyY = guyY -1
elseif key == keys.down then
guyY = guyY+1
end
term.clear()
term.setCursorPos(guyX, guyY)
print(guy)
end
HOLY CAPITALIZATION BATMAN(see what i did there?)
term.print "Bite my face"
term.SetCursorPOS("5", "6")
term.print "NO WAY!'
(Hurts my brain to purposfully write incorrect code...)
#78
Posted 31 August 2013 - 12:32 AM
my code
w,h = term.getSize()
someTable = {}
for x = 1, w do
someTable[x] = x
for y = 1, h do
someTable[x][y] = y
end
end
#79
Posted 04 September 2013 - 09:20 PM
jay5476, on 31 August 2013 - 12:32 AM, said:
my code
w,h = term.getSize()
someTable = {}
for x = 1, w do
someTable[x] = x
for y = 1, h do
someTable[x][y] = y
end
end
I think it needs to be:
w,h = term.getSize() -- Get the size of the screen
someTable = {} -- Define a variable
for x = 1, w do -- Loop from 1 through width
someTable[x] = x -- idk
end -- End
for y = 1, h do -- Loof from 1 through height
someTable[x][y] = y -- idk lol
end -- End
A non-commented version of the above:w,h = term.getSize()
someTable = {}
for x = 1, w do
someTable[x] = x
end
for y = 1, h do
someTable[x][y] = y
end
Now my code:
(You can find all my scripts at pastebin.com/u/ADENCRAFT20000)
local timesToRepeat = tonumber(sTimes)
if timesToRepeat == nil then
print("Error: You need to say how many times to loop")
error()
end
for i = 1, timesToRepeat do
print("lol") - Print a message
end
#80
Posted 08 September 2013 - 03:08 AM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











