dlcruz129, on 24 November 2012 - 07:33 AM, said:
- ComputerCraft | Programmable Computers for Minecraft
- → MysticT's Content
MysticT's Content
There have been 177 items by MysticT (Search limited from 10-February 22)
#96218 [SOLVED] Test if the color exists and how to call [see post]
Posted by
MysticT
on 12 March 2013 - 07:58 AM
in
Ask a Pro
term.setBackgroundColor(colors[color]) -- color is the passed string, like "blue" or "red", etc.
You may want to check in colours too, just in case someone writes grey instead of gray or something:
local col = colors[color] or colours[color]
if not col then
error("That color doesn't exist!")
end
term.setBackgroundColor(col)
#96559 [SOLVED] Test if the color exists and how to call [see post]
Posted by
MysticT
on 13 March 2013 - 04:54 AM
in
Ask a Pro
JokerRH, on 13 March 2013 - 04:29 AM, said:
Thats how it's written on the lua documentation, so base should be the base...
#75372 [Solved] "Non-blocking" os.pullEventRaw()
Posted by
MysticT
on 16 January 2013 - 03:14 PM
in
Ask a Pro
RunasSudo, on 16 January 2013 - 02:38 PM, said:
When one of my threads runs coroutine.yield("mouse_click") for example, my API needs to not resume it again until it has pulled a mouse_click event. In the meantime, however, it should still be running other coroutines. This implementation, however, does not let any other coroutines run until it has pulled said event.
I have a window manager that spawns two threads. One updates a clock, and one waits for a mouse_click, then exits the program. With this implementation, it does not run the clock-updating function until an event has been pulled. Not what I want to happen. When I use the parallel API to run both functions at the same time, it works.
RunasSudo, on 16 January 2013 - 12:09 PM, said:
I want the while true loop to continue regardless of whether an event has been fired.
For what I see, that code should work. Can we see the code you use to start the threads and what they run maybe?
#75354 [Solved] "Non-blocking" os.pullEventRaw()
Posted by
MysticT
on 16 January 2013 - 02:19 PM
in
Ask a Pro
Your workaround (starting a timer to fire an event) should work (you could also queue a fake event so it doesn't wait for the timer), but note that it would make computers lag a lot (if there's more than one computer in the world).
Why would you want to do it anyway? there's no need to, you just have to make the "threads" work like that (wait for an event then act accordingly).
#65144 [Question]Other programming languages?
Posted by
MysticT
on 28 December 2012 - 03:43 AM
in
Ask a Pro
Aquilamo, on 28 December 2012 - 03:16 AM, said:
Writing an entirely new mod would make it easier to write the interpreter (you can use an existing one), but you have to make the mod, including the blocks, items, etc. and all the network handling.
Conclusion: just stick to lua
#83294 [Question] how to check if a variable is even or odd
Posted by
MysticT
on 03 February 2013 - 10:04 AM
in
Ask a Pro
ikke009, on 03 February 2013 - 07:42 AM, said:
so 1 % 4 and 5 % 4 would both yield 0.25
#100601 [Question, Solved] How would i make everything i write show on monitor?
Posted by
MysticT
on 23 March 2013 - 09:19 AM
in
Ask a Pro
Example:
os.loadAPI("sync")
sync.addMonitor("left") -- add the monitor on the left
sync.redirect(true) -- this makes the output to be on the monitor and the terminal
Put that in a program and run it. After that all the output should be seen on both the terminal and the monitor(s) you added.
#130484 [Official] CCLite - Lightweight CC Emulator
Posted by
MysticT
on 30 June 2013 - 05:55 PM
in
General
KingOfNoobs, on 30 June 2013 - 03:11 PM, said:
[string "edit"]:53:attemp to call field `insert`(a nile value)
The code of the file was(i just made a little program to test this emulator):
table = {"hi", "dude", "hello"}
for i,v in ipairs(table) do
write(v)
if i < #table then write(", ") end
end
I hope you can find and fix the bug!#130490 [Official] CCLite - Lightweight CC Emulator
Posted by
MysticT
on 30 June 2013 - 06:41 PM
in
General
KingOfNoobs, on 30 June 2013 - 06:05 PM, said:
MysticT, on 30 June 2013 - 05:55 PM, said:
KingOfNoobs, on 30 June 2013 - 03:11 PM, said:
[string "edit"]:53:attemp to call field `insert`(a nile value)
The code of the file was(i just made a little program to test this emulator):
table = {"hi", "dude", "hello"}
for i,v in ipairs(table) do
write(v)
if i < #table then write(", ") end
end
I hope you can find and fix the bug!I'm just giving you a fix for the problem. If you are not going to use that code, then don't use the fix. But check your code before saying there's a bug (either in CC or some emulator).
#107114 [MC 1.7.10] [CC 1.65] Immibis's Peripherals
Posted by
MysticT
on 07 April 2013 - 07:54 AM
in
Peripherals and Turtle Upgrades
TableCraft0R, on 07 April 2013 - 07:35 AM, said:
immibis, on 31 August 2012 - 01:52 PM, said:
Download the mod from here.
Archive:
version 51.x.x for MC 1.4.5
version 50.x.x for MC 1.2.5/1.3.2/1.4.2
version 49.x.x for MC 1.2.5
Requirements: Minecraft Forge, ComputerCraft, and Immibis Core (which you can download from the same page).
I need 1.4.7 build because my mods isn't all updated to 1.5.1
Please!
#139046 [MC 1.7.10] [CC 1.65] Immibis's Peripherals
Posted by
MysticT
on 09 August 2013 - 12:08 PM
in
Peripherals and Turtle Upgrades
wrothmonk, on 09 August 2013 - 08:40 AM, said:
Here is an exact copy of what is in the imbibis.cfg
# Configuration file
####################
# block
####################
block {
I:peripherals.block.id=3414
I:peripherals.lan-wire.id=464
}
####################
# general
####################
general {
B:autoAssign=false
B:enableTPSCommand=true
#
S:peripherals.adminPassword=
B:peripherals.enableAdventureMapInterface=true
B:peripherals.enableCraftingAcceleratorComponents=true
B:peripherals.enableCraftingCryptoAccelerator=true
B:peripherals.enableCraftingLANModem=true
B:peripherals.enableCraftingLANWire=true
B:peripherals.enableCraftingMagCardDevice=true
B:peripherals.enableCraftingMagCards=true
B:peripherals.enableCraftingRFIDCards=true
B:peripherals.enableCraftingRFIDReader=true
B:peripherals.enableCraftingRFIDWriter=true
B:peripherals.enableCraftingSpeaker=true
B:peripherals.enableLAN=true
B:peripherals.enableLANSenderSpoofing=true
I:peripherals.rfidTicksPerScan=10
}
####################
# item
####################
item {
I:peripherals.component=28230
I:peripherals.magstripe=10153
I:peripherals.rfid=16230
}
local p = peripheral.wrap("right")
local player = p.getPlayerByName(username)
if player then
print("Player Health: ", player.getHealth())
end
#95867 [Lua][Question] fs question
Posted by
MysticT
on 11 March 2013 - 11:38 AM
in
Ask a Pro
Cyclonit, on 11 March 2013 - 09:35 AM, said:
file.readLine() is part of the function table file.
Both work.
Spongy141, on 11 March 2013 - 11:34 AM, said:
It's not possible (or at least too hard) to read a local variable from another program without modifying it, or interpreting it (unless of course it is made to return the value, in which case you just have to run the program and get the return value).
#106332 [Lua] Need to test for nil
Posted by
MysticT
on 05 April 2013 - 09:05 AM
in
Ask a Pro
A solution would be to add the values to another table inside the "container" table, like this:
function newContainer()
local container = {}
super = newObject("container")
setmetatable(container, { __index = super })
container.objects = {}
function container:addObject(object)
table.insert(self.objects, object)
end
function container:removeObject(object)
table.remove(self.object, object) -- NOTE: this won't look fot the object and remove it, you'll have to make a loop to iterate trhough the table and remove it yourself
end
function container:drawObjects()
for _,v in pairs(self.objects) do
if v.draw then
v.draw()
end
end
end
function container:handleObjectEvents(e)
for _,v in pairs(self.objects) do
if v.handleEvents then
v:handleEvents(e)
end
end
end
return container
end
#106340 [Lua] Need to test for nil
Posted by
MysticT
on 05 April 2013 - 09:13 AM
in
Ask a Pro
One more thing. You could make tables that contains the functions you want, and then use metatables to "add" them to your "objects", so you don't create new functions for every new object.
Example:
local myClass = {}
function myClass:doSomething(arg1, arg2)
print("Hello world!")
self.someVariable = arg1 + arg2
end
function newObject()
local obj = {}
obj.someVariable = 0
setmetatable(obj, { __index = myClass })
return obj
end
local testObject = newObject()
testObject:doSomething()
Kingdaro, on 05 April 2013 - 09:08 AM, said:
function container:drawObjects() for i=1, #self do if self[i].draw then self[i]:draw() end end end function container:handleObjectEvents(e) for i=1, #self do if self[i].handleEvents then self[i]:handleEvents(e) end end end
It's way faster than using pairs anyway. I also recommend setting functions like "draw" and "handleEvents" as default in the objects for your container, so you don't have to check if the methods exist before calling them.
It's true that using a numerical iterator is faster than pairs, so it probably would be better to use it instead (but also using another table).
And it's always good to check for values before using them, it prevents weird unexpected errors
#133756 [Lua] Highly Secure Door lock
Posted by
MysticT
on 15 July 2013 - 04:44 PM
in
Programs
reububble, on 15 July 2013 - 04:21 PM, said:
rhyleymaster, on 15 July 2013 - 01:43 PM, said:
If you can't turn it off, can't insert a disk while it's on, and you're not allowed to break the computer/door, then how are you meant to get in without a password?
2) Place disk drive next to the computer.
3) Insert disk with blank startup file.
4) Click the computer to turn it on.
5) ????
6) PROFIT!
Also, why was this post revived? O.o
#133856 [Lua] Highly Secure Door lock
Posted by
MysticT
on 16 July 2013 - 09:43 AM
in
Programs
reububble, on 16 July 2013 - 03:03 AM, said:
side="right" -- if the main computer is on the right
while true do
os.pullEvent("redstone")
if rs.getInput(side) then
parallel.waitForAny(
function()
while true do
peripheral.call(side,turnOn)
os.queueEvent('blah') os.pullEvent('blah') -- to yield
end
end,
function()
while true do
os.pullEvent("redstone")
if rs.getInput(side) then
break
end
end
end)
end
end
end
Now all you need to do is to add into the previous code
if ev=="key" then if p1=29 then rs.setOutput(side,true) sleep(0.05) rs.setOutput(side,false) -- remember that 'side' needs to be the side the other computer is on else rs.setOutput(side,true) sleep(0.05) rs.setOutput(side,false) end end
this is fun!
#96711 [lua] Command Line Arguments
Posted by
MysticT
on 13 March 2013 - 12:05 PM
in
Ask a Pro
eleure, on 13 March 2013 - 10:26 AM, said:
~/tmp/arguments.lua example
lua certainly does have a global table named arg.
edit: lyqyd was referring to exactly the same feature as i am.
ChunLing, on 13 March 2013 - 10:46 AM, said:
#96670 [lua] Command Line Arguments
Posted by
MysticT
on 13 March 2013 - 10:18 AM
in
Ask a Pro
eleure, on 13 March 2013 - 10:12 AM, said:
Quote
Lyqyd, on 13 March 2013 - 10:13 AM, said:
- ComputerCraft | Programmable Computers for Minecraft
- → MysticT's Content


