Jump to content


HometownPotato's Content

There have been 58 items by HometownPotato (Search limited from 10-February 22)


By content type

See this member's


Sort by                Order  

#203576 Gravity Manipulation Questions

Posted by HometownPotato on 19 January 2015 - 08:36 AM in Ask a Pro

Awsum, actually that's incorrect. Since the Y is vertical and X is horizontal it would be as it is.
But whenever you want to use it you have take note that the y axis increases as you go down, meaning 45 degree rotation would actually be -45 degrees.



#203515 API Dump?

Posted by HometownPotato on 18 January 2015 - 05:30 PM in Ask a Pro

Oh yeah, for some reason that crossed my mind.
Of course I would have to do a deep scan but thanks :)



#203495 API Dump?

Posted by HometownPotato on 18 January 2015 - 11:27 AM in Ask a Pro

I'm wondering if there is an internal function that exists that will generate a list of all the functions available in CC. Not like dumping a function with string.dump or converting back to JSON but like, a way for CC to create a list of all available functions.



#203493 API Dump?

Posted by HometownPotato on 18 January 2015 - 11:14 AM in Ask a Pro

Is there a function to dump everything to a file? I don't want to download the website because I don't need all the stuff on it, just a list of all the functions of ComputerCraft. In certain games that allow user-code, they have something like a DumpFuncToXML function that you could call which would write everything to an XML.

I ask this so I can create a parse it into a small and compact couple of HTML files that should work with all versions of CC (assuming a function like this exists and existed). I don't really want to go manually over the wiki since it might change in the future without me knowing.



#203492 Some kind of "sandbox" for your scripts

Posted by HometownPotato on 18 January 2015 - 11:08 AM in APIs and Utilities

Well this is cool but it is very easy to bypass.
It's really as simple as: getfenv(2).shell.run("prog");

You should block getfenv and loadstring and other functions people shouldn't need.
But setmetatable and getmetatable should stay enabled since there is no point in disabling it and iTable/getFunc should not be local since the sandboxed code will be able to access them if they are local.



#177608 Printer.write too long for the page!

Posted by HometownPotato on 08 May 2014 - 11:47 PM in Ask a Pro

Since all the characters are the same length with the font CC uses (I believe), you can compare the amount of characters and divide that by the maximum that can fit per line. And you will get how many lines you will need (math.ceil it).
So something like:

local text = "blah";
local sX, sY = printer.getPageSize();
local lines = math.ceil(#text / sX)
for y = 1, lines do
   local start = ((y - 1) * sX) + 1;
   local finish = y * sX;
   printer.setCursorPos(1, y)
   printer.write(text:sub(start, finish));
end
The math seemed to have worked out in my head, though I'm not sure it's entirely correct.


Also, you can implement something fairly easy (when lines > paper size Y) to check if it reached the end of the page, then start a new page.



#177200 [Question]

Posted by HometownPotato on 07 May 2014 - 01:11 AM in Ask a Pro

Remove the parenthesis is what he means, so:
os.pullEvent = os.pullEventRaw;

So you set os.pullEvent to the os.pullEventRaw function, since calling it only returns what the function returns which will give you problems and not what you want.



#177170 Help with my ticket machine?

Posted by HometownPotato on 06 May 2014 - 11:25 PM in Ask a Pro

But with hoppers, you can make sure they don't eject anytime they want. So if the "ticket machine" is accessing the server to see if they can enter, may require some time and if they eject it, you _might_ have problems (depending how you handle everything).



#177164 Help with my ticket machine?

Posted by HometownPotato on 06 May 2014 - 11:03 PM in Ask a Pro

I would hide a computer and make everything run on a monitor they can see. Maybe using buttons to "scan ticket" or "eject ticket" and use hoppers to transfer the ticket into a hidden location and fire a dispenser or something to eject.
And you can do a basic, secure encryption as long as you know no one will access that computer (with the scan and eject) since you are using a monitor.



#177161 [help]wireless peripheral api

Posted by HometownPotato on 06 May 2014 - 11:01 PM in Ask a Pro

You may want to change 'return {os.pullEvent("modem_message")}[5]' to ' 'return ({os.pullEvent("modem_message")})[5]' since I always seem to have problems in all versions of Lua doing {...}[x] as opposed to ({...})[x]

Yeah, I meant change sorry.



#176852 Restart a count after reaching a certain value?

Posted by HometownPotato on 05 May 2014 - 03:57 AM in Ask a Pro

Yeah, I realized that right after I posted after re-reading what he posted. Just forgot to edit.



#176824 Door lock redstone output question

Posted by HometownPotato on 04 May 2014 - 11:03 PM in Ask a Pro

Are you sure the redstone is on the left relative to the computer? (not on the bottom or top left, just literally on the block to the left of the computer)?
And if so, are you sure nothing is changing its output other than the computer?



#176821 Memory

Posted by HometownPotato on 04 May 2014 - 10:55 PM in Ask a Pro

bytes



#176797 Setfenv

Posted by HometownPotato on 04 May 2014 - 08:57 PM in Ask a Pro

I know, I've created sandboxes before. But it wasn't my intention of creating any kind of sandbox with that script. I read the title and his first post and gave him an example of setfenv alone, not of sandboxing



#176789 Setfenv

Posted by HometownPotato on 04 May 2014 - 08:36 PM in Ask a Pro

I'm giving an example of setfenv.
And you do use metatables as well for sandboxing.



#176763 Restart a count after reaching a certain value?

Posted by HometownPotato on 04 May 2014 - 06:39 PM in Ask a Pro

What? I didn't pull anything "off the internet."
I just know from testing that it was about that number.



#176723 not (yet) real object oriented stuff

Posted by HometownPotato on 04 May 2014 - 05:21 PM in Ask a Pro

You could use coroutine to run in a "separate" thread.
Also try looking at http://pastebin.com/t0Nb6pbS, it might help you understand OOP in Lua a bit



#176722 Restart a count after reaching a certain value?

Posted by HometownPotato on 04 May 2014 - 05:19 PM in Ask a Pro

It would stop after like, > 2^1000 something iterations, which is not really a big deal.



#176721 Setfenv

Posted by HometownPotato on 04 May 2014 - 05:18 PM in Ask a Pro

Here's a very basic example (make all new added global variables a table for whatever reason)


local oldEnv = getfenv();
setfenv(1, setmetatable({}, {__index = oldEnv; __newindex = function(self, key, value) rawset(self, key, {value}) end;}));



#176564 Restart a count after reaching a certain value?

Posted by HometownPotato on 04 May 2014 - 04:13 AM in Ask a Pro

for i = 1, math.huge do
local counter = (i % 8) + 1;
--code
end



#176561 Verifying that two files are the same

Posted by HometownPotato on 04 May 2014 - 03:53 AM in Ask a Pro

Couldn't you just do something like this:

local x = fs.open("file1");
local c = x.readAll();
x.close();


x = fs.open("file2");
local c2 = x.readAll();
x.close();

if c == c2 then
end

It would check if the contents are the same



#176559 more printers on one computer?

Posted by HometownPotato on 04 May 2014 - 03:51 AM in Ask a Pro

I think you could use wired modems to do this, so printer1 may be perihperal.wrap("printer_0") and your other printer would be printer_1



#176412 Restart a count after reaching a certain value?

Posted by HometownPotato on 03 May 2014 - 05:44 AM in Ask a Pro

globalCount = 0

while true do
globalCount = globalCount + 1
if globalCount == 8 then
globalCount = 0
print("Done")
end
sleep(0)
end



#176229 Check if variable exists and edit problems

Posted by HometownPotato on 02 May 2014 - 05:10 AM in Ask a Pro

That still gives you the same problem, if it's false or nil then it not var will be true



#176222 Check if variable exists and edit problems

Posted by HometownPotato on 02 May 2014 - 02:54 AM in Ask a Pro

Well, if variable then checks if it is not nil and not false. If your variable may be false do: if variable ~= nil then