Jump to content


MysticT's Content

There have been 177 items by MysticT (Search limited from 10-February 22)


By content type

See this member's


Sort by                Order  

#53118 [WIP]Best Program Evaaa!

Posted by MysticT on 24 November 2012 - 07:56 AM in Programs

View Postdlcruz129, on 24 November 2012 - 07:33 AM, said:

Correct usage: shell.run("pastebin", "get", "abc123", "startup")
You may want to check the changes in the newer versions (I can't remember wich one now). You can use it like he did now ;)/>.



#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

You set it the same way you did to check:
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

View PostJokerRH, on 13 March 2013 - 04:29 AM, said:

math.log(x [, base])
Thats how it's written on the lua documentation, so base should be the base...
That's for Lua 5.2, CC uses Lua 5.1. This is the manual for 5.1, math.log just takes one argument.



#134611 [Solved] Overwritting Fs Crashes

Posted by MysticT on 19 July 2013 - 06:23 PM in Ask a Pro

You don't need to copy the whole fs api, just the open function:
local oldFsOpen = fs.open
function fs.open(path, mode)
  local handle = oldFsOpen(path, mode)
  -- do whatever you want now
  return handle
end



#75372 [Solved] "Non-blocking" os.pullEventRaw()

Posted by MysticT on 16 January 2013 - 03:14 PM in Ask a Pro

View PostRunasSudo, on 16 January 2013 - 02:38 PM, said:

I'm not sure you understand what I want to do.
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.
Well, you said that you wanted to run the loop even when there's no events:

View PostRunasSudo, on 16 January 2013 - 12:09 PM, said:

EDIT: To clarify, os.pullEventRaw() performs as expected in this code (it blocks), but I don't want it to perform as such.
I want the while true loop to continue regardless of whether an event has been fired.
(Also the topic title is "Non-blocking" os.pullEventRaw()) That's why I said that.
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

That's the way ComputerCraft works, you yield to wait for an event to allow other computers to run. Making an infinite loop that doesn't yield until there's an event wouldn't let other computers work.
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

View PostAquilamo, on 28 December 2012 - 03:16 AM, said:

Is there any public information about how ComputerCraft works?
No, there isn't. And even if there were, it wouldn't help you, since it's heavily based on how lua works, using coroutines for each computer.
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 :P



#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

View Postikke009, on 03 February 2013 - 07:42 AM, said:

wonderful job mate. in case you didn't know, the % sign (called modulo) gives you the result of a division stripped of all integers.
so 1 % 4 and 5 % 4 would both yield 0.25
err, not really. It returns the raminder of the integer division. Both 1 % 4 and 5 % 4 would return 1.



#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

You can use the addMonitor function to add the monitor.
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.



#139117 [Openperipheral] Find String In "$$" Comand

Posted by MysticT on 09 August 2013 - 06:12 PM in Ask a Pro

I think the chat message doesn't add the $$ at the start. So, remove the $$ from Bubba's code and it should work with the message you get from the event.



#130484 [Official] CCLite - Lightweight CC Emulator

Posted by MysticT on 30 June 2013 - 05:55 PM in General

View PostKingOfNoobs, on 30 June 2013 - 03:11 PM, said:

I just played around with it a little bit and when I tried to edit a file it gave me this error:
[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 don't think it's a bug in the emulator. You redefined the "table" table in that program, so any program after that can't use table functions (like table.insert). Just give your table another name, and make it local.



#130490 [Official] CCLite - Lightweight CC Emulator

Posted by MysticT on 30 June 2013 - 06:41 PM in General

View PostKingOfNoobs, on 30 June 2013 - 06:05 PM, said:

View PostMysticT, on 30 June 2013 - 05:55 PM, said:

View PostKingOfNoobs, on 30 June 2013 - 03:11 PM, said:

I just played around with it a little bit and when I tried to edit a file it gave me this error:
[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 don't think it's a bug in the emulator. You redefined the "table" table in that program, so any program after that can't use table functions (like table.insert). Just give your table another name, and make it local.
Damn I forgot that! But why should I give it another name or make it local? I just made this to test the emulator.
Well... to avoid that error maybe? :P
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

View PostTableCraft0R, on 07 April 2013 - 07:35 AM, said:

View Postimmibis, on 31 August 2012 - 01:52 PM, said:

Downloads
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!
Then go to the download page and get the 1.4.6 version, which works for 1.4.7. No need for a big text like that, it just makes you look bad.



#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

View Postwrothmonk, on 09 August 2013 - 08:40 AM, said:

Allow me to clarify:
Spoiler
is what I get when I run a program to get the methods for the adventure interface peripheral and the right. When I attempt to call any of the other methods given on page 10 it comes up with either no such method (when calling the methods without wrapping it) or attempt to call nil (when I do wrap it), which to my understanding means the methods dont exist, I'm not wrapping the peripheral properly, or I'm not calling the the method by the right name. I suspect a combination of the last two since it says on the api documentation that the world commands start with 'w.' instead of 'p.' when 'p.' is the peripheral wrap.
Here is an exact copy of what is in the imbibis.cfg
Spoiler
Those methods are not from the peripheral, they are in the world and player "objects" you get calling the "getWorld" and "getPlayerByName" methods from the peripheral. So, if you want to get a player's health you need to do this:
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

View PostCyclonit, on 11 March 2013 - 09:35 AM, said:

file:readLine() is part of the object file.
file.readLine() is part of the function table file.

Both work.
Yes, but the table returned by fs.open is not ment to be used with : like the with io.open. Both should work with this function since it takes no arguments, but using : insted of . passes the table itself as the first argument, so using it with functions that take arguments (like file.write) wouldn't work.

View PostSpongy141, on 11 March 2013 - 11:34 AM, said:

So how will I get it to read a certain string by having it be a local in the file that's being read.
Do you want to read variables from another program? Or just information stored as text?
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).



#68740 [Lua][Error]/[Question] How do i unload a File?

Posted by MysticT on 04 January 2013 - 11:42 AM in Ask a Pro

You can use any loaded api, just that the shell api is not a common loaded api, it is loaded in the shell environment, wich is different from the global one used to load apis.



#68713 [Lua][Error]/[Question] How do i unload a File?

Posted by MysticT on 04 January 2013 - 11:04 AM in Ask a Pro

The problem with the api is that you can't use the shell api there. Apis are loaded in an environment where the shell api table is not defined, so it doesn't exist (it's nil, that's why it says attempt to index a nil value).



#106351 [Lua] Need to test for nil

Posted by MysticT on 05 April 2013 - 09:32 AM in Ask a Pro

I don't see anything wrong. Are you getting an error or it's just not working as expected?

Btw, I have a similar gui api in my os. The file's on github if you are interested.



#106332 [Lua] Need to test for nil

Posted by MysticT on 05 April 2013 - 09:05 AM in Ask a Pro

The problem is that the "container" table has the functions stored inside it. So, when you iterate the table with pairs, it gets those functions and then try to index them (in v.draw).
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

No problem.
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()

View PostKingdaro, on 05 April 2013 - 09:08 AM, said:

Or just use a numeric loop.

  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.
Using another table would be better (imho), since you know that the "objects" you are looking for will be there and nothing else.
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 :P



#133756 [Lua] Highly Secure Door lock

Posted by MysticT on 15 July 2013 - 04:44 PM in Programs

View Postreububble, on 15 July 2013 - 04:21 PM, said:

View Postrhyleymaster, on 15 July 2013 - 01:43 PM, said:

The only way to make it 'Not prone to disk' is to edit the roms, which you cant do on a server unless you edit the resource pack itself.
No, no that is not the only way. Remember how computers can check if there is a disk near them and eject it instantly? Remember how you can ensure the computer is not turned off by the user (most people can do this part), and did you know that you can also stop any computer from turning your computer off also?
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?
1) Press Ctrl+S to shut down the computer.
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

View Postreububble, on 16 July 2013 - 03:03 AM, said:

Ctrl+S. I never even use Ctrl+S, no wonder. How about attach a computer to your computer which is told to continually turnOn the other computer until it knows you're not pressing Ctrl+S?

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!
Then just turn off the other computer first :P



#96711 [lua] Command Line Arguments

Posted by MysticT on 13 March 2013 - 12:05 PM in Ask a Pro

View Posteleure, on 13 March 2013 - 10:26 AM, said:

just tested on my desktop. the following prints 'example':
~/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.
I was actually telling you that you were right, but that it doesn't work in CC.

View PostChunLing, on 13 March 2013 - 10:46 AM, said:

But this does work for ordinary functions with variable parameters.
Indeed it does. I thought that was only available on lua 5.2. Just tested and it works. It's weird that it doesn't work for command line arguments.



#96670 [lua] Command Line Arguments

Posted by MysticT on 13 March 2013 - 10:18 AM in Ask a Pro

View Posteleure, on 13 March 2013 - 10:12 AM, said:

Quote

The given options (see below) are executed and then the Lua program in file script is loaded and executed. The given args are available to script as strings in a global table named arg.
from http://www.lua.org/manual/5.1/lua.html. computercraft must re-assign arg to {...}, so apparently my post only applies to normal lua programs
Well, that's what the lua interpreter (wich is used to run lua programs) does. CC doesn't do this, so it's not an option here. It would be easy to implement it anyway.

View PostLyqyd, on 13 March 2013 - 10:13 AM, said:

I have this nagging feeling that there is a built-in table, though. Something like arg or args. I will double-check this this evening.
I think that's only in lua 5.2, and it works with functions too. Or at least I think I read that somewhere :P



#113826 [help] local variables in environments

Posted by MysticT on 24 April 2013 - 07:45 AM in Ask a Pro

No, local variables are not saved in the environment. The only way to access local variables is to be in the same scope (function, loop, etc.) or using the debug library (wich is not available in CC).