Jump to content


cntkillme's Content

There have been 24 items by cntkillme (Search limited from 10-February 22)


By content type

See this member's

Sort by                Order  

#268211 Eulers Number on Monitor

Posted by cntkillme on 12 July 2017 - 06:59 AM in Ask a Pro

It's not euler's number, it's just short-hand for "times 10 to the power of."
Anyways: print(string.format("%.0f", num))



#267182 fs.open/io.open creating files in root directory?

Posted by cntkillme on 22 May 2017 - 06:58 AM in Ask a Pro

Oh yeah. For some reason I just assumed there was some global "working directory" since I totally forgot about multishell.



#267179 fs.open/io.open creating files in root directory?

Posted by cntkillme on 22 May 2017 - 05:01 AM in Ask a Pro

I have a script in /dir but when I create a file in it and run that script it creates the file in the root directory instead of in /dir.
I know I can use shell.resolve to solve this but why isn't this implicit?

Edit this seems to happen with every function that expects a path (i.e. os.run, etc.)



#267174 Running 2 programs within the same shell on 2 different windows?

Posted by cntkillme on 21 May 2017 - 09:48 PM in Ask a Pro

I just opened all relevant scripts in a text editor and just did a find-and-replace of package to pkmnpackage but yeah I've posted a bug report on the github repo.



#267158 Running 2 programs within the same shell on 2 different windows?

Posted by cntkillme on 21 May 2017 - 06:58 AM in Ask a Pro

Hmm this is gonna be painful, since the new versions of CC have package now it's tricking the packman script.



#267154 Running 2 programs within the same shell on 2 different windows?

Posted by cntkillme on 21 May 2017 - 05:19 AM in Ask a Pro

So it'd probably have a good idea to have some sort of "active" window in the case to handle key events and such (perhaps flip around these windows via ctrl + arrow keys). Alright gonna check out multishell's source, thanks!

Heh, I'll just use lyqydos and not reinvent the wheel since it's already been done and better. Sure it's slightly different than what I want but it's far more flexible.



#267149 Running 2 programs within the same shell on 2 different windows?

Posted by cntkillme on 21 May 2017 - 12:07 AM in Ask a Pro

Aha. This turned out cleaner than I expected. https://puu.sh/vWtqN/3d18573c86.mp4
Still have to handle certain things like the mouse_click events and such to make sure they only fire for windows they're in but that'll be a piece of cake.

Is there a list of all events somewhere on the wiki? found it

Hmm. I'm reinventing the wheel. There's probably a better "windows" API that handles this for me. Anyways:
https://puu.sh/vWx6J/80685016ed.mp4



#267148 Need to protect files

Posted by cntkillme on 20 May 2017 - 10:51 PM in Ask a Pro

Hmm, didn't realize you could insert a computer in a disk drive. Gotta rely on other mods to prevent people from breaking your stuff I guess.



#267145 Need to protect files

Posted by cntkillme on 20 May 2017 - 09:31 PM in Ask a Pro

You could always edit bios.lua and have it require a password to boot from the disk and to change it can't you?



#267131 Running 2 programs within the same shell on 2 different windows?

Posted by cntkillme on 20 May 2017 - 11:26 AM in Ask a Pro

I guess I could probably use coroutines here, any time the first thread pauses I can redirect the terminal if I have to continue the other one (and vice versa).



#267128 Running 2 programs within the same shell on 2 different windows?

Posted by cntkillme on 20 May 2017 - 11:05 AM in Ask a Pro

I ended up wrapping the term table entirely, although I still don't like this method.

local _term = term
_G.term = setmetatable({ }, {
  __index = function(_, key)
	local env
	_, env = pcall(getfenv, 4) -- i dont know how reliable this is going to be
	if _ then
	  if env == envA then
		return termA[key]
	  elseif env == envB then
		return termB[key]
	  end
	end
	return _term[key]
  end})



#267127 Running 2 programs within the same shell on 2 different windows?

Posted by cntkillme on 20 May 2017 - 10:44 AM in Ask a Pro

I'm trying to figure out how I can run 2 different programs within the same shell using 2 different windows.
So my first approach was to do:

local sX, sY = term.getSize()
local fileA, fileB = "blah", "blah blah"
local termA = window.create(term.current(), 1, 1, sX, sY/2)
local termB = window.create(term.current(), 1, sY/2+1, sX, sY/2)


parallel.waitForAny(
   function() os.run({ term = termA }, fileA) end,
   function() os.run({ term = termB }, fileB) end
)

However this fails to work unless all outputting I do is through term (for example when I call print). I then tried to wrap term.current and force it to return termA if the first script called it and termB if the second one did:

local envA = { term = termA }
local envB = { term = termB }
local _current = term.current
function term.current()
  local env = getfenv(2)
  if env == envA then
    return termA
  elseif env == envB then
    return termB
  else
   return _current()
  end
end

But that didn't work. Is there a way to do what I want? I don't know much about the CC API so if this is obvious I'm sorry :P.



#267126 Creating Userdata?

Posted by cntkillme on 20 May 2017 - 09:52 AM in Ask a Pro

Oh... well that is incredibly useful and convenient :o



#267122 Creating Userdata?

Posted by cntkillme on 20 May 2017 - 05:37 AM in Ask a Pro

The problem with that is I don't want to keep opening my file just to write to it. I'm storing the handle until the program terminates or they close it themselves. (ideally, until it goes out of scope but that's not possible on CC since __gc doesn't fire on tables)



#267111 Avoiding common bad practices in your code

Posted by cntkillme on 19 May 2017 - 07:48 PM in Tutorials

When talking about Lua you're not supposed to think of functions, tables, and closures as pointers even though they really are, you're supposed to think of them as values. The only difference being they're not cloned when you assign to another variable (unlike numbers and booleans).
And all functions in Lua are closures regardless if they have any upvalues. All a closure is, though, is a pointer to a function prototype (contains static info. like constants, instructions, and nested prototypes), its upvalues, and its environment.



#267108 Creating Userdata?

Posted by cntkillme on 19 May 2017 - 07:30 PM in Ask a Pro

You could probably just wrap the entire OS table if you want, no need to copy it. You'd put any of your custom functions in that table but then have indexing it fallback to the real OS table (via __index metafield).



#267093 require function

Posted by cntkillme on 19 May 2017 - 02:32 AM in Suggestions

Oh my god it was literally added yesterday LOL gg



#267091 require function

Posted by cntkillme on 19 May 2017 - 02:06 AM in Suggestions

I assume this has probably been requested plenty of times but all the alternatives I read weren't any good.

os.loadAPI clutters the global environment and forces the name of the API to be the file name.
dofile requires the script to be recompiled every time.
os.run is just not a good solution either.

Why doesn't require exist? I mean sure it's easy to implement on our own but having it be an actual feature makes it so we don't have to create a startup script for each computer just to do it.

I understand there is overhead but again if the package table can be accessed we can free libraries we no longer need to use.



#267090 Creating Userdata?

Posted by cntkillme on 19 May 2017 - 12:49 AM in Ask a Pro

Yeah this specific computer is running multiple scripts at the same time via multishell tabs.
Anyways, the problem with not closing it is that the file will stay open until the computer is rebooted/shutdown. Although yeah I mean my solution currently is to wrap os.pullEvent and os.pullEventRaw to accept a callback function that is called if the signal was terminate.

Seems like a clean way to do it, no?



#267087 Creating Userdata?

Posted by cntkillme on 19 May 2017 - 12:00 AM in Ask a Pro

Don't all scripts share the same global environment though? If I overwrite it in one script wouldn't it affect the rest?

I might just end up not using rednet.receive if last comes to last but I'm curious to if there is a way to do this more nicely. I don't really understand why `newproxy` was removed since it'd be perfect in this scenario.


I was thinking I might be able to set the metatable of the file object returned to have __gc but io.open and fs.open return tables so that's also a no go.

Edit: Nope never mind they don't share the same env. although they fallback to the same table with the built-ins. If I call rednet.receive after writing over os.pullEventRaw, wouldn't it change all script in that case. Although this could be a good thing, I can have it take an optional "onTerminate" function.



#267072 Creating Userdata?

Posted by cntkillme on 17 May 2017 - 08:42 PM in Ask a Pro

So Lua 5.1 normally has the newproxy function that can create userdata but ComputerCraft doesn't have it.

The reason I need this is that in the case the script is terminated or it errors or something I want to ensure I clean up everything correctly. The reason is that for my Logger class it only opens the file once and stores the handle. The problem though is since tables don't fire the __gc metamethod in 5.1 I cannot guarantee this file is closed.

My original solution was to return an object created from newproxy and the __gc metamethod would be fired in the case that went out of scope.

I know I could use os.pullEventRaw and handle it when the script is terminated but then that prevents me from using rednet.receive which is a wrapper function I really like. Also it doesn't entirely handle the case when the logger object goes out of scope (although I can ensure that won't happen I guess).

Is there another way to do what I need?



#267066 [MC 1.8.9-1.11.2] CC Tweaks

Posted by cntkillme on 17 May 2017 - 06:54 AM in Peripherals and Turtle Upgrades

I'm using the 1.8.9 version and a mod called "Simple Covers". Facading works perfectly fine but if it obstructs the path (like this or even like this) it ends up not being connected anymore.
Is this facading mod I'm using just bad and if so do you know of any for 1.8.9 as I can't find any working ones.



#267065 Is there a way I can get the label of a computer connected to a network?

Posted by cntkillme on 16 May 2017 - 11:01 PM in Ask a Pro

Oh alright thanks for clearing that up.



#267043 Is there a way I can get the label of a computer connected to a network?

Posted by cntkillme on 15 May 2017 - 06:47 AM in Ask a Pro

I'm wondering if it's possible to get the label of some computer connected to a wired network.
I know I can get a handle to it using peripheral.wrap but I don't think I can get the label from there.

My current solution is to have one computer just ask the other computer what its label is.


Also, another unrelated question: I read that if you label your computer, destroy it, recreate one, and set the label to what it was previously all the data would be saved. Is there a way to disable this since it sort of ruins multiplayer for me?