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  

#152908 Broken Player Detector

Posted by MysticT on 14 November 2013 - 11:47 AM in Ask a Pro

The problem is in the "authorise" function:
function authorise(request)
		players = fs.open("disk/allowed","r")
		for player in players:lines() do
				if request == player then
						return true
				else
						return false
				end
		end
end
You check the first line of the file, and if it matches return true, if it doesn't returns false without checking the other lines.
Change it to this and it should work:
function authorise(request)
		players = fs.open("disk/allowed","r")
		for player in players:lines() do
				if request == player then
						return true
				end
		end
	    return false
end



#152858 How To Use Math.random To Randomize The Contents Of A Table? [solved!]

Posted by MysticT on 13 November 2013 - 07:36 PM in Ask a Pro

I guess you want a random value from the table. You need to use math.random to get a random index like this:
local weatherTable = { 66, 43, 90, 21 }
local randomWeather = weatherTable[math.random(1, #weatherTable)]
print(randomWeather)
What it does is generate a random number between 1 and the table size, so you can use it to index the table.



#146156 Mouse Click Flicker-How To Remove?

Posted by MysticT on 22 September 2013 - 10:21 AM in Ask a Pro

This line:
event, button, xPos, yPos = os.pullEvent("mouse_click")
is overwriting the button variable with a number (the button number from the mouse_click event).



#144589 Api Advanced

Posted by MysticT on 12 September 2013 - 07:05 PM in Tutorials

View PostSymmetryc, on 12 September 2013 - 06:49 PM, said:

Correct me if I'm wrong, but that's not how you use __add; it passes the left and right values, not self and other.
"left and right" "self and other", different names, same thing.
function t.someFunc(self, other)
-- is the same as:
function t:someFunc(other)
-- just another way to define functions

EDIT: oh, I see what you mean. If the left value is not self, then yes, this won't work.



#144549 Directory Size

Posted by MysticT on 12 September 2013 - 02:08 PM in Ask a Pro

View PostLyqyd, on 12 September 2013 - 01:56 PM, said:

That's an... interesting approach, MysticT.
Well, directories take some space too (512 bytes, not much but you have to include it too), so it's easier that way.

View PostZiriee, on 12 September 2013 - 01:58 PM, said:

View PostMysticT, on 12 September 2013 - 01:49 PM, said:

This should work:
-snip-
Brilliant! The fact that the size of ROM is 2.2Mb and rom/programs/secret/alongtimeago is 2.1Mb made me grin uncontrollably. My mouth hurts now.
Yeah, that's one big ascii movie xD



#144544 Directory Size

Posted by MysticT on 12 September 2013 - 01:49 PM in Ask a Pro

This should work:
local function getSize(path)
  local size = fs.getSize(path) -- get the size of the file/directory
  if fs.isDir(path) then -- if it's a directory, get the size of its contents
    local l = fs.list(path)
    for i = 1, #l do
      size = size + getSize(fs.combine(path, l[i]))
    end
  end
  return size
end

print("ROM Size: ", getSize("/rom"))



#142099 Fill Api

Posted by MysticT on 28 August 2013 - 01:03 PM in APIs and Utilities

View Postjay5476, on 27 August 2013 - 04:42 PM, said:

View PostKingdaro, on 27 August 2013 - 03:52 PM, said:

Would be at least somewhat useful if you could fill in a specific area of the screen, rather then being limited to just the entire screen.
yeh but that's practically in paintutils already
Not really. There isn't a function in the paintutils api for that (at least there wasn't the last time I checked).

Here's a function for that:
function fillArea(x, y, w, h, color)
  if color then
    term.setBackgroundColor(color)
  end
  local line = string.rep(" ", w)
  for i = 0, h-1 do
    term.setCursorPos(x, y + i)
    term.write(line)
  end
end
That's the most efficient way to do it in CC. You could also add some checks to avoid drawing outside of the screen and save a few loops.



#141957 Dir Functions, Need Some Help With My Derp

Posted by MysticT on 27 August 2013 - 02:25 PM in Ask a Pro

Or just use:
shell.resolve("SomeOtherDir")
That should return the same as:
fs.combine(shell.dir(), "SomeOtherDir")



#141916 Package Api

Posted by MysticT on 27 August 2013 - 09:40 AM in APIs and Utilities

View Postmitchfizz05, on 27 August 2013 - 08:20 AM, said:

This is quite fancy!
I recommend that you make a packaging program (like the one in the example) and release it in the programs section.
Thanks.
I want to add some sort of compression before. Otherwise, there's not much use for this.



#141826 Package Api

Posted by MysticT on 26 August 2013 - 03:09 PM in APIs and Utilities

Hello everyone.
This is a little api I wrote that lets you save a directory to a single file. It's like a zip/rar/whatever file, but without compression (for now), so in most cases the file will be larger than the directory.
The package is a binary file, so you can include any binary files and they should pack/unpack correctly.

I wrote it while working on something bigger, but I thought that someone might find this usefull (probably not, but whatever :P).
So, here it is:

Download:
pastebin get gx10mzbk

Functions:
package.pack(path, outPath) -- pack directory "path" to file "outPath"
--[[
Packs a directory
Parameters:
  - path: the path to the directory to pack
  - outPath: the path to save the package file
Return Values:
  - result: boolean indicating if the operation was successful
  - error: error message in case of error
--]]

package.load(path)
--[[
Loads a package file
Parameters:
  - path: the path to the package file
Return Values:
  - entries: table containing the package entries. nil in case of error
  - error: error message in case of error
--]]

package.unpack(path, outPath)
--[[
Unpacks a package file
Parameters:
  - path: the path to the package file
  - outPath: the path to save the directory
Return Values:
  - result: boolean indicating if the operation was successful
  - error: error message in case of error
--]]

Examples:
Pack:
Spoiler
Unpack:
Spoiler

Any feedback and bug reports are welcome.



#141561 Fill Api

Posted by MysticT on 24 August 2013 - 06:49 PM in APIs and Utilities

Easier way:
local function fillScreen(color)
  term.setBackgroundColor(color)
  term.clear()
end



#140305 Page Needs To Be Updated

Posted by MysticT on 16 August 2013 - 08:42 PM in Wiki Discussion

View Posttheoriginalbit, on 16 August 2013 - 06:55 PM, said:

View PostMysticT, on 16 August 2013 - 06:25 PM, said:

Have you requested edit privilege for the wiki? There's a pinned topic for that.
Yes, I've had edit privilege before, and updated quite a few pages, but for some reason it won't allow me to edit some pages, this one being one of them.
That's weird... Well, I don't know how the wiki works. AfterLifeLochie will have to answer this :P
Meanwhile, someone that can edit the wiki should do it. There's been a lot of people asking how to do thigs that can be solved with that function or something else related (like wraping wired peripherals). The update to the wiki should help with that.



#140281 Page Needs To Be Updated

Posted by MysticT on 16 August 2013 - 06:25 PM in Wiki Discussion

Have you requested edit privilege for the wiki? There's a pinned topic for that.



#139626 [1.4.5] NPaintPro

Posted by MysticT on 12 August 2013 - 04:13 PM in Programs

View Postdpd_84, on 12 August 2013 - 03:20 PM, said:

when I try to run 3DPrint I get an error: 3DPrint:18: attempt to index ? (a nil value)

Does anyone know how to fix this??
Are you trying to run it on a computer? You need a turtle to use that program.



#139625 Computer Screen Open/close Event?

Posted by MysticT on 12 August 2013 - 04:07 PM in Suggestions

But CC doesn't have laptops :)



#139614 [Closed]Hello Overly Complex World - Most Complex "hello World" Scrip...

Posted by MysticT on 12 August 2013 - 02:49 PM in General

View PostIcanbreathecode, on 12 August 2013 - 02:13 PM, said:

PS: I forgot to mention, the deadline will be July 1st, hopefully I can remember, knowing how I forget everything.
There's either too much time (almost a year), or the deadline is over :P

I'm pretty bored right now, so I'll see what I can come up with.



#139593 Does Lua Have A "xor" Function For Printing?

Posted by MysticT on 12 August 2013 - 01:42 PM in Ask a Pro

View PostGamerNebulae, on 12 August 2013 - 01:36 PM, said:

Sorry, I was a little vague there. I didn't mean the bitwise xor. I meant the xor function for printing stuff. That would make my life so much easier at the moment, but CraftOS doesn't have that. It makes the text the color of the background. You would need a rather difficult construction for that at the moment.
I'm not sure what you mean. I never heard of something like "xor function for printing".
Now, if you want to set the text color to the same as the background, you don't need any xor, and or whatever. You only need to know the background color (easy if you are setting it), and set the text color to the same one.



#139590 Does Lua Have A "xor" Function For Printing?

Posted by MysticT on 12 August 2013 - 01:24 PM in Ask a Pro

The bitwise xor? I just told you the bit api has one... And CraftOS has the bit api...



#139586 Does Lua Have A "xor" Function For Printing?

Posted by MysticT on 12 August 2013 - 01:16 PM in Ask a Pro

If you mean a bitwise xor, the bit api includes one (bit.bxor, IIRC). But I'm not sure how you plan to implement blending, since you can't combine colors.
If you need a logic xor (for if statements for example), lua doesn't have one. But, there's a few ways to get it. If you only use booleans, the easiest way is:
if bool1 == not bool2 then
end



#139467 Figuring out how to set the number this is in a table to a variable

Posted by MysticT on 11 August 2013 - 03:28 PM in Ask a Pro

Ok, let me see if I understood what you want. You need a function that returns the key (or index) of a certain value inside a table. So, if you have the table { "some value", aVariable, 6, "my value" }, and you search for "my value", it would return 4.
If that's what you need, here's a function that does that:
local function tableCheck(t, val)
  for i = 1, #t do --# loop through the table. If you need non-numerical keys, you need to use pairs.
	if t[i] == val then --# check if the value matches
	  return i --# return the key/position of the value in the table
	end
  end
end
You can then use it like this:
local t = { "some value", aVariable, 6, "my value" }
local i = tableCheck("my value")
print(i) --# this should print 4



#139419 Getting Sides On Which Peripherals Are

Posted by MysticT on 11 August 2013 - 08:58 AM in Ask a Pro

View PostBubba, on 11 August 2013 - 08:03 AM, said:

View Postimmibis, on 11 August 2013 - 07:15 AM, said:

Use peripheral.getNames() if you want it to work with wired modems.

I believe wired modems use peripheral.getNamesRemote(), though I could be wrong :)
That's the modem method called internally. The peripheral api has the getNames function which checks all sides for peripherals, and if one is a wired modem it calls getNamesRemote to get attached peripherals.

View PostCometWolf, on 11 August 2013 - 08:23 AM, said:

When you're using wired modems you would also have to change up the if statment a little bit
if string.match(peripheral.getType(tSides[i]),"monitor") then
This is because when using a wired modem each connected peripheral gets assigned an id(id_peripheralType). Usually this id is 0, unless you have multiple of the same peirpheral conneted.
That's for the name/side of the peripheral, not for the type. So no need for any extra checks.

OP: This should work for you:
for _,name in ipairs(peripheral.getNames()) do
  --# tell the user there's a peripheral
  print("There's a ", peripheral.getType(name), " on ", name)
  --# if you need to use a certain peripheral, like a monitor:
  if peripheral.getType(name) == "monitor" then
	--# here you can store the monitor side
	monitorSide = name
	--# or directly wrap the monitor
	monitor = peripheral.wrap(name)
	--# or whatever you need to do
	break
  end
end



#139125 Channel Lock For Server Ops V2 Now With Hashed Password

Posted by MysticT on 09 August 2013 - 06:36 PM in Programs

View PostElrond1369, on 09 August 2013 - 06:31 PM, said:

fs = table.remove(fs, 14)
What? :huh:
I can't find that or your previous "fix" in the code anyway.
Also, you are blocking any file/path that contains peripheral...



#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.



#139113 Channel Lock For Server Ops V2 Now With Hashed Password

Posted by MysticT on 09 August 2013 - 06:04 PM in Programs

View PostElrond1369, on 09 August 2013 - 05:55 PM, said:

View PostMysticT, on 09 August 2013 - 05:22 PM, said:

> lua
> t = fs
> file = t.open("/rom/apis/peripheral")
> file.readAll()
Passwords retrieved.
Easy :P/>/>
You should override the fs api if you want to secure files.
if string.find(s, "fs%.")==nil then
error("don't try and change fs to somthing else")
end
Yeah, check again...
I never used "fs.", just "fs". So it won't catch it.

Derp, my bad.
Ok, use this then:
> lua
> t = _G["f".."s"]
> file = t.open("/rom/apis/peripheral", "r")
> file.readAll()
:)

View PostPixelToast, on 09 August 2013 - 05:23 PM, said:

fail sandbox is fail c_C
MysticT: you forgot a "r" ;)
Oh god, how could I? :P
Here it is just for you: "r" xD



#139110 Combining Similar Peripherals

Posted by MysticT on 09 August 2013 - 05:59 PM in Ask a Pro

You still have to use peripheral.wrap with wired modems:
local t = {}
t[1] = peripheral.wrap("glowstone_illuminator_0")
t[2] = peripheral.wrap("glowstone_illuminator_1")
for i = 1, #t do
  t[i].setColor(0x00FFFF)
end

You could also make a function to get all the peripherals automatically:
local function getPeripherals(sType)
  local t = {}
  for _,name in ipairs(peripheral.getNames()) do
	if peripheral.getType(name) == sType then
	  t[#t + 1] = peripheral.wrap(name)
	end
  end
  return t
end
Then you call it and use the same loop as before to call the methods.
local t = getPeripherals("monitor") -- get all the monitors
for i = 1, #t do
  t[i].write("Hello")
end