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  

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

Posted by MysticT on 09 August 2013 - 05:22 PM in Programs

> lua
> t = fs
> file = t.open("/rom/apis/peripheral", "r")
> file.readAll()
Passwords retrieved.
Easy :P
You should override the fs api if you want to secure files.



#139090 Lua Cutting A String Short? (How To Change Space To %20)

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

Well, I need to see the code to check for other errors, can you upload it again (it looks like you deleted it or it expired)?



#139083 Lua Cutting A String Short? (How To Change Space To %20)

Posted by MysticT on 09 August 2013 - 03:33 PM in Ask a Pro

You need to encode the url before using it. Look at the url you provided:
http://projectbuilde...e=nulls%20house
note the %20 between nulls and house, that's an encoded space. CC provides a function to do this: textutils.urlEncode(string). Use it on the variables you want to add to the url, like this:
content = http.get("http://smp.projectbuilder.info/fetch.php?cmd=page&ID=dialgate&buffer=0&name=" .. textutils.urlEncode(destination))



#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



#138935 Fs.getdirectory()

Posted by MysticT on 08 August 2013 - 09:07 PM in Suggestions

The current directory is managed by the shell, so you have to use the shell api to get it. Use shell.dir() to get the current directory and shell.setDir(path) to change it.
Note that changing the current directory doesn't affect the fs api, since it uses absolute paths. To get the absolute path to a file in the current directory you can use shell.resolve(filename).
More on the shell api on the wiki.



#138889 Aren't "chunk Loader" Upgrade Supposed To Also Be "wireless"

Posted by MysticT on 08 August 2013 - 02:52 PM in Ask a Pro

You should ask the peripheral developer (miscperipherals?, CC doesn't have chunk loaders), but the way peripherals work in turtles doesn't allow to have 2 peripherals, so you can't have a modem and the chunk loader (again, ask the peripheral developer, he will provide a more accurate answer).



#138739 Get Methods From An Api

Posted by MysticT on 07 August 2013 - 04:43 PM in Ask a Pro

print the key instead (print(t), instead of print(g)).



#138393 Event That Dont Stop Loops

Posted by MysticT on 05 August 2013 - 06:19 PM in Ask a Pro

Well, the problem is that the sensor calls pulls events, so it "eats" the "chat_command" event you want. A solution would be to use the peripheral functions directly without the sensor api. I don't remember the functions and events right now, but take a look at the sensor api file to see how it works.



#138336 Question about rom/help

Posted by MysticT on 05 August 2013 - 02:40 PM in Ask a Pro

That "bug" has been reported at least 2 times before. The problem is, like ZudoHackz said, that the shell looks for programs in the current directory, then on the rest of the path (the path variable in shell, which you can change with shell.setPath).
The solution is simple, use full paths to programs:
cd /rom/help -- go into the /rom/help folder
cd .. -- this will error
/rom/programs/cd .. -- and now you are in /rom



#138281 How To Make Coroutines Run Together With Events?

Posted by MysticT on 05 August 2013 - 11:17 AM in Ask a Pro

Use a timer instead of sleep and handle the "timer" event in the main loop. Something like this:
local clockTimer = os.startTimer(1) -- start a timer for 1 second

-- Main loop
while true do
  local evt, p1, p2, p3, p4, p5 = os.pullEvent()
  if evt == "timer" then
    if p1 == clockTimer then
      displayTime() -- redraw the clock
      clockTimer = os.startTimer(1) -- restart the timer
    end
  elseif evt == "some other event" then
    -- handle the event
  end
end



#136429 [1.5.2] [Cc 1.53] Not Is Not Working Right

Posted by MysticT on 27 July 2013 - 06:48 PM in Ask a Pro

Not a bug. It should be:
if not (1 > 2) then print("test") end
You were comparing the result of "not 1" (wich will always be false) with the number 2.



#135441 Fill A Screen More Efficiently?

Posted by MysticT on 23 July 2013 - 09:10 PM in Ask a Pro

For drawing boxes, you can use something like this:
local function drawBox(x, y, w, h, color)
  local line = string.rep(" ", w)
  term.setBackgroundColor(color)
  for i = 0, h-1 do
    term.setCursorPos(x, y + i)
    term.write(line)
  end
end
That way you draw a full line instead of only one character.



#134704 Printer Levels Finder

Posted by MysticT on 20 July 2013 - 12:00 PM in Ask a Pro

Or:
print("There are ", paper, " page(s) left")
print("You have ", ink, " ink left.")
since print accepts any number of arguments, and will print all of them.



#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



#134155 Arrays/tables

Posted by MysticT on 17 July 2013 - 12:10 PM in Ask a Pro

 Yuri, on 17 July 2013 - 11:51 AM, said:

so i've been trying to use table lately and i don't understand why this is not working i swear it work sometime ago but now it doesn't

ex = {
   a = 1,
   A = 10,
}
print(ex[a])

and this doesn't work and i know i could do ex.a and it would work but need it so it can take a user inputted letter so like
You need to add quotes there:
print(ex["a"])
wich is the same as:
print(ex.a)

 Yuri, on 17 July 2013 - 11:51 AM, said:

another thing is when i try to get how many values are in the table/array like print(#ex) would return 0
Using the lenght operator only returns

Quote

the largest positive numerical index of the given table, or zero if the table has no positive numerical indices.
To get the size of a table with string (or any other type of) keys, you can use a function like this:
local function getTableSize(t)
  local size = 0
  for k,v in pairs(t) do
	size = size + 1
  end
  return size
end



#133993 Char/Pixel Aspect Ratio

Posted by MysticT on 16 July 2013 - 08:32 PM in Ask a Pro

Copied from the CC source:
public static int FONT_HEIGHT = 9;
public static int FONT_WIDTH = 6;
That's for terminal characters/pixels, but I guess it's the same aspect ratio for monitors.



#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



#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



#133384 Lua tables: bad code or Lua/LuaJ bug?

Posted by MysticT on 13 July 2013 - 09:27 PM in Ask a Pro

Well, it works because the first "n" value referenced is the one on the shared table. But, when you assign a value to self.n, self is referencing the "btn1" table, so it sets "n" to 2 in that one, not the shared one. See the comments:
local but = {
n = 1, -- shared n, initialized to 1

a = function (self)
  self.n = 2 -- self is the passed argument, not the "but" table
end,

b = function (self)
  self.n = 1
end
}

local but1 = setmetatable({}, {__index = but})
local but2 = setmetatable({}, {__index = but})

print(but1.n) -- both this "n" references are to the shared value
print(but2.n)

but1:a() -- this would call but.a(but1)

print(but1.n) -- but1.n was set before, so it takes that value
print(but2.n) -- but2.n is not defined, so it uses but.n (the shared value)



#133349 Lua tables: bad code or Lua/LuaJ bug?

Posted by MysticT on 13 July 2013 - 06:31 PM in Ask a Pro

That's how metatables work. The __index metamethod will search the referenced table for the given key if it doesn't exist in the table.
Example:
local someTable = {
key1 = "Hello World!",
key2 = 2
}

local tbl = {
key2 = 10,
key3 = "Some Random String"
}
setmetatable(tbl, { __index = someTable })

print(tbl.key1) -- this will print "Hello World!", from someTable, because the key is not in tbl
print(tbl.key2) -- this will print 10, as the key is present in tbl
print(tbl.key3) -- this will print "Some Random String"

So, when doing oop in lua, you need to define the functions and common variables in the metatable, and "instance" variables in the instance table. Something like this:
local Class = {}

function Class:doSomething()
  print("Test")
end

function Class:test()
  print(self.value)
end

local obj = setmetatable({}, { __index = Class })
obj.value = 10 -- set value in the instance object
obj:doSomething()
obj:test() -- this should print 10, the value we just assigned to obj.value

Hope you understand all that. If you don't, or want to know something else, just ask :)



#132519 Calculate user's input.

Posted by MysticT on 09 July 2013 - 07:59 PM in Ask a Pro

Well, the easiest way is what Lyqyd said, and you can use a custom environment that doesn't have any apis or global functions (so people can't use something like "os.reboot()" or whatever).
Using an empty environment like this should work:
local input = read()
local func = loadstring("return "..input)
if func then
  setfenv(func, {})
  local ok, result = pcall(func)
  if ok then
	print(result)
  else
	printError("Error: ", result)
  end
else
  printError("Invalid input")
end

This way you could also make an environment with some math functions and constants.



#132287 Metatable inconsistency

Posted by MysticT on 08 July 2013 - 07:28 PM in Ask a Pro

This is not a bug in LuaJ, it is done in the bios. The setmetatable function is "replaced" with this:
local nativesetmetatable = setmetatable
function setmetatable( _o, _t )
  if _t and type(_t) == "table" then
    local idx = rawget( _t, "__index" )
    if idx and type( idx ) == "table" then
      rawset( _t, "__index", function( t, k ) return idx[k] end )
    end
    local newidx = rawget( _t, "__newindex" )
    if newidx and type( newidx ) == "table" then
      rawset( _t, "__newindex", function( t, k, v ) newidx[k] = v end )
    end
  end
  return nativesetmetatable( _o, _t )
end
I don't know why this is done, but there must be a reason why they added it.



#131970 Hurt/Heal Forum Staff & Members

Posted by MysticT on 07 July 2013 - 06:04 PM in Forum Games

Heal AfterLifeLochie
Hurt dan200

AfterLifeLochie: 2 (+1)
Cloudy: 6
dan200: 5 (-2)
nitrogenfingers: 3

View PostSymmetryc, on 07 July 2013 - 04:47 PM, said:

hurt ALL.
I see what you did there :P



#131968 tostring, or not tostring?

Posted by MysticT on 07 July 2013 - 06:03 PM in Ask a Pro

You can either tostring apass, or tonumber ovrpass. In this case, I would use tostring:
local rnd = math.random(100, 500)
local apass = tostring((rnd + 11) * 83)
local ovrpass = read()

if ovrpass == apass then
  print("Override Success...")
else
  print("Override Failure...")
end



#131543 Hurt/Heal Forum Staff & Members

Posted by MysticT on 05 July 2013 - 08:43 PM in Forum Games

Oh no, I'm dead!
How dare you! Now I'll have to kill someone...

Heal nitrogenfingers
Hurt theoriginalbit

AfterLifeLochie: 10
Cloudy: 9
dan200: 10
nitrogenfingers: 9
theoriginalbit: 3

Edit: corrected values after above post.