Jump to content


The Crazy Phoenix's Content

There have been 73 items by The Crazy Phoenix (Search limited from 10-February 22)


By content type

See this member's


Sort by                Order  

#268689 Turtle bomber

Posted by The Crazy Phoenix on 30 July 2017 - 12:58 PM in Ask a Pro

View PostReinified, on 30 July 2017 - 11:26 AM, said:

You need to open your rednet modem before broadcasting. Open it first thing.

No, you don't. Modems only need to be opened to receive from them.



#268667 Message remote execution

Posted by The Crazy Phoenix on 29 July 2017 - 11:20 PM in Ask a Pro

loadstring(message)()
/thread

loadstring(message) creates a function using the code inside the message variable, and the "()" following it calls that function.
If you don't want an error to crash your program, you can use pcall to invoke the loaded string instead. pcall will catch the error (it's basically how the Shell and Lua programs catch errors)

local ok, err = pcall(loadstring(message))
if not ok then
	-- There was an error calling the function.
	printError(err)
end

If the string does not compile, then loadstring will return nil. All that needs to be done is verify that it isn't nil before attempting to call the function.

local func, err = loadstring(message)
if func ~= nil then
	local ok, err = pcall(func)
	if not ok then
		-- Runtime error
		printError(err)
	end
else
	-- Compilation error
	printError(err)
end



#268644 netNav - Networked mapping system and turtle pathfinding

Posted by The Crazy Phoenix on 28 July 2017 - 09:26 PM in Programs

 blunty666, on 28 July 2017 - 05:05 PM, said:

 Creator, on 23 December 2016 - 11:52 PM, said:

How does your algorithm work? I kinda looked into it, but don't quite get it.

Sorry I completely missed this post!

It's just the A* algorithm but in 3 dimensions, so instead of just looking forward, back, left, and right, it also looks up and down when looking at which path to take.

It's not a straight forward implementation of A* though, it actually starts searching from both the start and end goals at the same time (essentially runs two instances of the A* algorithm), and detects when the two paths meet which ends up being the optimal path between the two points. It does all the calculation in one thread, but switches execution between the two algorithms when it notices the open nodes jumping around a lot (ie when it is not searching down a continuous path but is searching through lots of very different options). This helps it to find a path quicker when either the start or goal point is in a very complicated area and not in open space - there is a more mathematical explanation for why this is quicker if you want it!).

The other custom part of the algorithm is the heuristic it uses for tie breaking, it is set up to prefer going in straight lines instead of diagonals as they end up being quicker when you factor in the time it takes for the turtle to turn.

In terms of mapping the environment, the turtles all have 2 maps they use to determine the best path. The shared map that all turtles update is used as more of a suggestion of the best path - if a lot of turtles keep finding an object at the same point the value of that point in the shared map will keep increasing, so the turtles become less likely to try and go there. Then all turtles also maintain a local map that gets wiped between each call to netNav.goto, this is used to record obstacles that the turtle has ran into in this pathfinding session, so if they find an obstacle it gets recorded in the local map and the turtle will not attempt to go to that point again in that pathfinding session.

Hope that sheds a bit more light on it!? I will try and write all this down in a more ordered format at some point, just to remind myself how it works!!!

Doesn't A*'s design make accounting for turns simpler by adjusting the cost based on the turtle's facing?

I'd also be interested in the explanation as to why your approach is faster than simply pathfinding from the destination to the current location.



#268632 rednet:87: Expected number

Posted by The Crazy Phoenix on 28 July 2017 - 02:39 PM in Ask a Pro

The server won't receive any messages because you haven't opened any modems.
Modems only need to be opened for receiving, you don't need to open them for sending.

tonumber("connect") is nil, that's the cause of the error. "connect" is not a valid string representation of a number



#268630 Corrupt-A-Wish!

Posted by The Crazy Phoenix on 28 July 2017 - 02:35 PM in Forum Games

Granted, someone told you yesterday, but you've already forgotten.

I wish I could find something to do whenever I'm bored.



#268621 The Quartz Platform - IKTM [1.10.2] [Latest CC] [Other Mods] [Sponge] [GriefP...

Posted by The Crazy Phoenix on 27 July 2017 - 06:15 PM in Servers

View PostCLNinja, on 25 June 2017 - 10:56 PM, said:

I was immediately banned for writing code that did nothing but lag a SINGLE computer, and was reversible. GG

Lagging a single computer lags all the computers on the server due to how CC runs the computers.



#268620 Just wanted to say thank you for the mod!

Posted by The Crazy Phoenix on 27 July 2017 - 06:10 PM in General

Tekkit still exists.



#268609 Corrupt-A-Wish!

Posted by The Crazy Phoenix on 27 July 2017 - 12:45 PM in Forum Games

Granted, it'll be mixed into the next outdoor puddle you encounter.

I wish I didn't burnout any time I try working on any programming project that isn't small.



#268608 Textpaint - A better Paint Program

Posted by The Crazy Phoenix on 27 July 2017 - 12:41 PM in Programs

Why would we use this over the CraftOS paint program?



#268597 Temporarily change your computer ID and version string!

Posted by The Crazy Phoenix on 26 July 2017 - 11:32 PM in APIs and Utilities

Alternatively, use peripheral.call or the modem API instead of the rednet API, then you don't have to spoof your ID.



#268591 Corrupt-A-Wish!

Posted by The Crazy Phoenix on 26 July 2017 - 05:17 PM in Forum Games

Granted. It's a replica of the Colossus, but you'll have to pay for it.

I wish I could come up with a wish that does not involve coming up with wishes.



#268586 help with buttons

Posted by The Crazy Phoenix on 26 July 2017 - 11:57 AM in Ask a Pro

Are you using an advanced computer / monitor? "mouse_click" only works on advanced.
If you're only planning on listening to the "mouse_click" event, use os.pullEvent("mouse_click") so that you don't have to manually filter events.

The given snippet of code won't compile because there are 2 "end" statements too many.



#268581 Copy _ENV

Posted by The Crazy Phoenix on 26 July 2017 - 09:14 AM in Ask a Pro

Keep in mind that setfenv will not work if you've disabled Lua 5.1 functions in the CC configuration files. I prefer to avoid using it to be compatible with all settings if I'm programming something not just for myself.

Metatables are still vulnerable to getmetatable(_ENV).__index though, so you should also set "__metatable = {}" to force getmetatable to return the table {} and setmetatable to error.



#268565 How to easily anonymize yourself.

Posted by The Crazy Phoenix on 26 July 2017 - 12:50 AM in Tutorials

Your method also has the downside of losing the computer ID if the program crashes.
Sure, you could use pcall to catch any potential errors, but it's still safer to use peripheral.call/modem.



#268564 Corrupt-A-Wish!

Posted by The Crazy Phoenix on 26 July 2017 - 12:35 AM in Forum Games

Granted, but any paper within 5 metres of it will disappear as long as your printer still has ink.

I wish there were no desensitization to positive feelings and any form of entertainment were no less effective than it currently is.



#268562 Copy _ENV

Posted by The Crazy Phoenix on 25 July 2017 - 11:53 PM in Ask a Pro

To force programs to use your modified version of the API, you don't actually need to copy their _ENV, you just need to change it.
Ideally this would be achieved without ever touching the _G environment (and thankfully it can).

If you need a more in-depth explanation for any of the following code, feel free to ask.

env = {fs = {...}}
setmetatable(env, {__index = _G})

--# For every function
env[name] = function(...)
	_ENV = env
	--# Keep in mind that anything that isn't local or global (i.e. something in the previous _ENV) cannot be accessed beyond this point
	return func(...)
end

To get the APIs to use your environment, you'd need to reload them with the proper environment.
For example, if I wanted to load the settings API into the environment:

local settings_env = {}
setmetatable(settings_env, {__index = env})
local func, err = loadfile("/rom/apis/settings", settings_env)
if func then
	--# Call the function in a way that the error will not terminate the program
	local status, err = pcall(func)
	if status then
		settings_env._ENV = nil
		env.settings = settings_env
	else
		--# Runtime error
		printError(err)
	end
else
	--# Compile error
	printError(err)
end

Both these solutions still don't work with os.run or loadfile, but there's a nice workaround for that.

env.os.run = load(string.dump(os.run), "filename", "t", env)
env.loadfile = load(string.dump(os.run), "filename", "t", env)



#268560 Control redstone over wireless modems!

Posted by The Crazy Phoenix on 25 July 2017 - 11:14 PM in APIs and Utilities

You may be able to use those sync keys to add a layer of security to your protocol.

For example, if you were to generate a server ID from the sync key (which you'd keep secret), you could then create a single hash of the message, sync key and some sort of timestamp (to prevent someone from retransmitting a previously transmitted message).
Then all the server needs to do is hash the received message with its copy of the sync key and compare it to the received hash to verify that the sender can be trusted.
It may not be as good as one-way key encryption, but it's certainly better than nothing and very easy to implement. There are plenty of SHA-1 implementations on these forums.



#268546 help with a function

Posted by The Crazy Phoenix on 25 July 2017 - 07:08 PM in Ask a Pro

Here's your while body reduced only to conditions and calls that alter the output.

if fuel.getAnalogInput(fuelside) > 14 then
	mainpwr.setAnalogOutput(mainpwrsde, 0)
elseif temp.getAnalogInput(tempsd) > 10 or sat.getAnalogInput(satsd) < 3 then
	mainpwr.setAnalogOutput(mainpwrsde, 0)
elseif oldfuel < fuel.getAnalogInput(fuelside) then
	for i = 1, 15 do
		[...]
	end
end

You should check if the above is written the way you want it to behave.
If the issue still exists, check that the sleep just before the break has the right delay.

I recommend that you fix your indentation to make your code easier to read.



#268539 help with a function

Posted by The Crazy Phoenix on 25 July 2017 - 10:22 AM in Ask a Pro

The "break" statement ends the for loop. Once the for loop has ended, the program jumps back to the start of the while loop and "mainpwr.setAnalogOutput(mainpwrsde, 0)" runs.
If your intention is to continue the loop, use "continue" (jumps to the next iteration). If you want to do something else after finding the point where >8 then add code after the for loop.



#268510 Quartz OS. True sandboxed users.

Posted by The Crazy Phoenix on 24 July 2017 - 04:32 PM in Operating Systems

View PostMineRobber___T, on 06 July 2017 - 06:05 AM, said:

Also, instead of disallowing read/write on files, simply use CC's inbuilt read-only files feature.

fs.isReadOnly is not checked by the other fs API functions, which means that even though the edit program doesn't work, the files can still be edited using fs.open.



#268509 Secure File System [sfs]

Posted by The Crazy Phoenix on 24 July 2017 - 04:23 PM in APIs and Utilities

Example startup program will crash because "sfs.start" cannot be called with no arguments (attempt to index nil). What's the point of using a table if it only a single field is used?
Use "error(msg, index)" instead of just "error(msg)" to make it easier for users to debug their programs.
The screen appears to flicker when the program is active.
Attempting to run a file with no read access crashes the shell.
It is possible to set the user to root, granting full access regardless of what user was previously set.
getfenv(sfs.setOtherRead).start({userName = "root"})
The environments of other SFS API functions can also be used in that manner.



#268507 litPix - Little Pixels without Limits [v0.8]

Posted by The Crazy Phoenix on 24 July 2017 - 03:41 PM in APIs and Utilities

You can use "term.getSize" to get the size of the display. That will allow your program to work correctly on customized computers, pocket computers and monitors.



#268506 SBox | Sandboxing utility

Posted by The Crazy Phoenix on 24 July 2017 - 03:30 PM in APIs and Utilities

The rom is no longer accessible if the sandbox isn't set to a directory inside the root directory (e.g. "SBox /1/2" doesn't work)
In other cases, the sandbox fails if using "../rom/../<path>" (can be used to access "/<path>")