Jump to content


flaghacker's Content

There have been 393 items by flaghacker (Search limited from 10-February 22)


By content type

See this member's


Sort by                Order  

#242221 Discover App (Ver. 7.4) - Apps, Snippets, Cloud Storage, Chat Board, Mail, Pr...

Posted by flaghacker on 02 January 2016 - 10:00 PM in Programs

View PostDannySMc, on 02 January 2016 - 12:37 PM, said:

View Postoeed, on 02 January 2016 - 09:04 AM, said:

Why not just an integer that increases every time the app is uploaded?

What like update 1 or update 0.1?

Have people choose their own version system, but keep a parallell number. An example: the first version is called 0.0.1, it's number is one. The second version might be called 0.0.3, it's number is 2. The next version could be 1.2.8, with the number 3.

This approach combines the best of both worlds: there are no restrictions one the version format, but it's still easy to sort and compare versions with the (hidden) number.



#232624 Scaling...?

Posted by flaghacker on 15 September 2015 - 04:40 PM in Ask a Pro

I don't know if this answers your question, but you can simply multiply every coordinate with your scale factor.

If that's not your question, please give us an example.



#232050 Lua interpreter doesn't respect __tostring

Posted by flaghacker on 07 September 2015 - 08:59 PM in Bugs

That could be the case, I'm not sure. Could you try to explicitly use "print" to see if the problem is really the lua program?

Fixed the ')', thanks.



#232049 Saving threads

Posted by flaghacker on 07 September 2015 - 08:55 PM in Ask a Pro

You should consider stuff like disk.isPresent, os.time as well.



#232045 Lua interpreter doesn't respect __tostring

Posted by flaghacker on 07 September 2015 - 08:45 PM in Bugs

Your code sets the metatable for one table, and then tries to serialise another. Try this instead:

local t = {}
setmetatable (t, {__tostring = function () return "test" end})
print (t)

Edit: now I'm confused. Are you only running that one line of code? That shouldn't print anything... Does my code work?



#231474 Modem security

Posted by flaghacker on 30 August 2015 - 05:42 AM in Ask a Pro

The wikipedia page about Diffie HellMan key exchange explains how to achieve a shared secret key. It even has some illustrations :)



#231162 Code to automatically reply to rednet messages

Posted by flaghacker on 26 August 2015 - 03:37 PM in Ask a Pro

Just run a program that uses the rednet api? What part are you getting stuck with?



#230793 Timer and other

Posted by flaghacker on 21 August 2015 - 05:46 PM in Ask a Pro

View Post_zircon_, on 21 August 2015 - 11:08 AM, said:

You could also use coroutines to keep checking if the timer event has been pulled.

function checkTimer()
  while true do
    local event = os.pullEvent()
    if event == "timer" then
	  print("Timer Finished!")
    end
  end
end
local oldPull = os.pullEventRaw
local coTime = coroutine.create(checkTimer)
function os.pullEventRaw(sFilter)
  while true do
    local event = { oldPull() }
    if coroutine.status(coTime) == "suspended" then
	  coroutine.resume(coTime, unpack(event))
    end
    if sFilter == event[1] or not sFilter then
	  return unpack(event)
    end
  end
end

That's a completely wrong implementation, you need to handle event filters and such. Don't try to attempt coroutines if you're not yet familiar worth the computercraft event system.

@OP: the paralell api is the preferred solution if you don't want to rewrite complex functions like read. A basic example would look like this:
function reading()
  while true do
    local text = read()
    print("You wrote " .. text)
  end
end

function waiting()
  while true do
    sleep(3)
    print("3 seconds have passed");
  end
end

paralell.waitForAny(reading, waiting) --NO () after reading & waiting!

You can choose between waitForAny and waitForAll on that last line. Take a look at the wiki.



#230618 How would you create sub-functions?

Posted by flaghacker on 20 August 2015 - 10:38 AM in Ask a Pro

Ah, sorry, I misunderstood your question.

The trick is to return a table containing functions and
possibly values.

function createHuman (name)
  local h = {}
  h.name = name

  h:sayHi = function ()
    print ("hi, I'm " .. self.name)
  end

  return h
end

local bob = createHuman ("bob")
bob:sayHi () --hi, I'm bob

You can make the code more efficient using metatables, as explained here. I'd recommend reading the previous link I posted to, it's the introduction.



#230599 How would you create sub-functions?

Posted by flaghacker on 20 August 2015 - 08:57 AM in Ask a Pro

2 options:

function a.foo(self)
  print(self.something)
end
function a:foo()
  print(self.something)
end

two ways to caal them too:
a.foo(a)
a:foo()

More info about it and related stuff can be found here.



#230418 Rednet Programs

Posted by flaghacker on 18 August 2015 - 01:52 PM in Ask a Pro

View PostLuckyLuke, on 18 August 2015 - 11:52 AM, said:

View Postflaghacker, on 18 August 2015 - 10:19 AM, said:

Sender ids can be faked quite easily by overwriting os.getID or by using the modem api. Don't trust the id, use some other authentication method.

Really?! What kind of security are you using, how do you authorize a connection? :)/>

Real security is nearly impossible to archieve in computercraft, but you can get somewhat secure by switching the modem channel you communicate on regularly. The channel could eg. be (os.getTime() / 2) + 5 or something more complicated. You can also encrypt any data you send, search for an encryption api in programs/apis and utilities.



#230406 Rednet Programs

Posted by flaghacker on 18 August 2015 - 10:19 AM in Ask a Pro

View PostLuckyLuke, on 18 August 2015 - 10:14 AM, said:

I do know the risk of using rednet, thanks for your information! :)/>
I will make sure to check the senderId bevor writing the programm.

Sender ids can be faked quite easily by overwriting os.getID or by using the modem api. Don't trust the id, use some other authentication method.



#230382 Buttons in a pocket computer

Posted by flaghacker on 17 August 2015 - 09:42 PM in Ask a Pro

So, what's your problem?



#230353 Correctly use os.run / multishell.launch

Posted by flaghacker on 17 August 2015 - 09:41 AM in Ask a Pro

View PostHPWebcamAble, on 16 August 2015 - 11:58 PM, said:

View PostLyqyd, on 16 August 2015 - 11:40 PM, said:

Nah, using shell.run is perfectly fine if that's what you're needing to do.
I guess the 'bad practice' I was thinking about is when newbs use it to loop their program.

It's mostly about "unexperienced players" using
shell.run("clear")
to clear the screen. I remember I did it at one point to :)



#230313 How to get mosue position

Posted by flaghacker on 16 August 2015 - 09:24 PM in Ask a Pro

As Lyqyd said, impossible. There are a couple of suggestion threads about this but they basically died because a function like os.getMousePos doesn't work well in a multiplayer environment.

You can however get the mouse position while the user is holding the mouse button via the mouse_drag event.



#230311 fs API help

Posted by flaghacker on 16 August 2015 - 09:18 PM in Ask a Pro

the wiki on the fs api

its most important function, fs.open

a tutorial about it

If you're getting stuck with a specific part, feel free to ask us.



#230254 Request:Todo List

Posted by flaghacker on 16 August 2015 - 06:35 AM in General

What issues are you having with that program? (exact error, when does it happen, ...)



#230253 Correctly use os.run / multishell.launch

Posted by flaghacker on 16 August 2015 - 06:33 AM in Ask a Pro

View PostHPWebcamAble, on 16 August 2015 - 05:28 AM, said:

View Postflaghacker, on 16 August 2015 - 05:10 AM, said:

Most of the time there's not really a good reason to not use shell, could you elaborate?

A select few programs that come with CC use the shell API, and there are obviously a ton of user made ones that do.
The program I'm working on is a File explorer (which you should be looking forward to :D/> ), and it needs to be able to run programs

It seems you missed one of my "not"s in my post. ;) I was asking why you don't use shell.run in place of os. run .



#230247 Correctly use os.run / multishell.launch

Posted by flaghacker on 16 August 2015 - 05:10 AM in Ask a Pro

os.run({shell = shell}, "prog", "arg1")
This should somewhat work.

The shell is a special api that's only available to programs ran with the shell. This way you pass your own shell api to the other program.

I believe shell.getRunningProgram won't work, but you could try that out yourself.

Most of the time there's not really a good reason to not use shell, could you elaborate?

edit: typos



#230141 Safe Run Program

Posted by flaghacker on 15 August 2015 - 12:24 AM in Programs

The problem with these kind of programs is that they're really easy to circumvent (eg fs["delete"]()) and the fact that there's nothing wrong with fs.open and fs.delete, would you consider the default "edit" program malicious?

@Yami, do you want to block infinite loops? Good luck detecting those... And why would you even want to? Most (if not all) programs have them...



#230123 Thaumcraft refilling system

Posted by flaghacker on 14 August 2015 - 09:44 PM in Ask a Pro

View PostHassan51234, on 14 August 2015 - 09:31 PM, said:

I changed it to right still and then i tryed left and still the same erroe

On what side is the monitor actually? Make sure you haven't forgotten the quotes (") around "left".



#230116 mob farm controller

Posted by flaghacker on 14 August 2015 - 08:28 PM in Ask a Pro

Turning red on while keeping the current output would look something like this:
local side = "left"
local addColor = colors.red

rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side), addColor))
The code does "get the current otput, add red to it and set it as the new output".

Turning red off is almost the same, just replace "colors.combine" with "colors.subtract". You can write a couple of functions to make it eaven easier:

function enableColor(side, color)
  rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side), color))
end

Again, with disableColor being the same with "subtract" instead of "combine".

edit: ninja'd



#230030 CCInstall - Create an Installation for your Programm!

Posted by flaghacker on 13 August 2015 - 11:15 PM in APIs and Utilities

Why doesn't the program work on turtles and pocket computers?

Some explenation on how to use the program and what exactly it does would be nice.



#230028 Multiselection file browser - Lattice

Posted by flaghacker on 13 August 2015 - 11:12 PM in Programs

View PostH4X0RZ, on 13 August 2015 - 09:08 PM, said:

View Postflaghacker, on 13 August 2015 - 08:59 PM, said:

But then, shouldn't it be in General or AaP? I think the programs section is only for finished programs.

In my opinion, no. General is for program previews without code, and Ask a pro is for asking questions. This post is a release of an unstable program, so it belongs in programs...



#230027 Thaumcraft refilling system

Posted by flaghacker on 13 August 2015 - 11:09 PM in Ask a Pro

Perhaps you could show us a mscreenshot of the error massage?