- ComputerCraft | Programmable Computers for Minecraft
- → The Crazy Phoenix's Content
The Crazy Phoenix's Content
There have been 73 items by The Crazy Phoenix (Search limited from 10-February 22)
#269112 Webserver crossing dimensions.
Posted by
The Crazy Phoenix
on 19 August 2017 - 01:22 PM
in
Ask a Pro
#268851 Using HTTP to gather a variable in php to process in lua
Posted by
The Crazy Phoenix
on 07 August 2017 - 06:53 PM
in
Ask a Pro
Twijn, on 09 July 2017 - 11:10 PM, said:
(Note: Even in that case, you could remove all of the '.' in lua; though this would mean you'd have to keep the format consistent. Ie, you couldn't move from 1.0 to 1.0.1 or 1.0.0 to 1.0.01 without potentially causing issues. (like from going from 1.0.11 from 1.0.2, you'd have to put 1.0.20 as it'd be comparing 1011 to 102)
I've set up these two samples to hopefully demonstrate this & help your understanding:
First webpage
https://cc.tylertwin...var/1point0.php
<?php
header("Content-Type: text/plain");
echo "1.0";
?>
Second webpage
https://cc.tylertwin...var/1point1.php
<?php
header("Content-Type: text/plain");
echo "1.1";
?>
Lua:
pastebin run 1VZga5iN
This will check both versions and tell if they're up to date with the default version (1.0). You can additionally run `pastebin run 1VZga5iN 1.1` and you'll see the issue that the 1.0 webpage will return false, as if it's out of date when the client would technically be ahead.
The "Content-Type" headers are not very necessary. It's more used to make it more viewable in a webpage (and technically more correct), because it sees it as a text document instead of an HTML page.
Alternatively, you can use string.gmatch and compare each version number individually. This works with strings like "1.0.1".
function isOutdated(current, remote)
local cfunc = current:gmatch("%d+")
local rfunc = remote:gmatch("%d+")
local cnum = tonumber(cfunc())
local rnum = tonumber(rfunc())
while cnum and rnum do
if cnum ~= rnum then
return cnum < rnum
end
cnum = tonumber(cfunc())
rnum = tonumber(rfunc())
end
return rnum ~= nil
end
#268689 Turtle bomber
Posted by
The Crazy Phoenix
on 30 July 2017 - 12:58 PM
in
Ask a Pro
#269165 True Encrypted Chat (no name found lul)
Posted by
The Crazy Phoenix
on 22 August 2017 - 04:15 AM
in
Programs
Namely, that algorithm involves using the binary decomposition of the operand. Here's some pseudocode.
function modulo(n, m)
p = {m}
while p[#p] < n do
p[#p + 1] = 2 * p[#p]
end
while n < m do
p[#p] = nil
if n > p[#p] then
n = n - p[#p]
end
end
return n
end
Naturally, you're free to come up with your own algorithm.
#268808 to find out how to get informations about a pixel
Posted by
The Crazy Phoenix
on 05 August 2017 - 08:06 PM
in
Ask a Pro
#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
#268608 Textpaint - A better Paint Program
Posted by
The Crazy Phoenix
on 27 July 2017 - 12:41 PM
in
Programs
#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
#268950 Stargate program won't update screen?
Posted by
The Crazy Phoenix
on 11 August 2017 - 05:26 AM
in
Ask a Pro
Move your os.pullEvent to just before the "if y == 6 then" line.
Sleep(0.1) is also unnecessary because os.pullEvent will yield the program.
#269324 Sorting
Posted by
The Crazy Phoenix
on 29 August 2017 - 05:30 PM
in
Ask a Pro
#268509 Secure File System [sfs]
Posted by
The Crazy Phoenix
on 24 July 2017 - 04:23 PM
in
APIs and Utilities
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.
#268506 SBox | Sandboxing utility
Posted by
The Crazy Phoenix
on 24 July 2017 - 03:30 PM
in
APIs and Utilities
In other cases, the sandbox fails if using "../rom/../<path>" (can be used to access "/<path>")
#268898 Remote controlling a computer
Posted by
The Crazy Phoenix
on 09 August 2017 - 09:10 PM
in
Ask a Pro
Dave-ee Jones, on 09 August 2017 - 03:49 AM, said:
In regards to inconsistent screen sizes I figured that the screens would have to be downsized to be consistent (well, virtually consistent).
If you want the same screen, then just call the server's term functions when you transmit to the client. For example...
-- Set modem, tch, rch here
local server_term = term.current()
local custom_term = {}
for name, func in pairs(server_term) do
custom_term[name] = function(...)
modem.transmit(tch, rch, {name = name, args = {...}})
return func(...)
end
end
term.redirect(custom_term) -- Used to be current_term (it was a mistake)
-- Wait for the client to be running here
term.clear()
term.setCursorPos(1, 1)
-- Run program of choice here
Instead of only transmitting. This sample will work if the client's screen is not smaller in at least one dimension.
You can use term functions that aren't the current term, you just use their table as if it were the term API (without redirect, native and current of course).
#268887 Remote controlling a computer
Posted by
The Crazy Phoenix
on 09 August 2017 - 01:52 AM
in
Ask a Pro
Solution 1: Drawing is done pixel-by-pixel regardless so the client doesn't need the GUI code. Even then, function wrapping allows one to know what functions are being called. It's simply a matter of calling on the client the matching function when called on the server (after syncing the screens of course)
For example, create a custom term table that wraps each term function by also sending the called function to the client, which simply calls them as it receives them. Then, you'd call term.redirect on that table to make term functions use it instead.
Problem 2: Depends on problem 1, therefore not an actual issue.
Solution 2: If it were an issue, the program could be transmitted from the server to the client, allowing the client to run the exact same program regardless of its local copy.
Problem 3: Somewhat of an issue, but the cause is misunderstood.
Solution 3: The mouse events contain information about the pixel touched. If the server's screen is bigger, you'd simply force the server to run at a lower resolution by changing term.getSize (ideally through redirection). If the screens aren't the same size, you can then simply discard mouse events that are out of bounds on the resized screen. On the server, this would be done by overriding os.pullEventRaw.
#269215 redstone loops clock output
Posted by
The Crazy Phoenix
on 24 August 2017 - 11:34 AM
in
Ask a Pro
#269194 redstone loops clock output
Posted by
The Crazy Phoenix
on 23 August 2017 - 03:32 PM
in
Ask a Pro
#268632 rednet:87: Expected number
Posted by
The Crazy Phoenix
on 28 July 2017 - 02:39 PM
in
Ask a Pro
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
#268704 rednet:87: Expected number
Posted by
The Crazy Phoenix
on 31 July 2017 - 11:49 AM
in
Ask a Pro
Feolthanos, on 31 July 2017 - 11:00 AM, said:
You could create a file that tracks the number, but that'd mean that the program breaks if you tamper with the save data.
Instead, try using fs.complete("user#", dir) and then using the length operator to count how many files start with "user#".
Then, to make sure, verify that the next index exists, and as long as it doesn't, keep incrementing.
In other words...
local files = fs.complete("user#", dir)
local index = #files + 1
while (fs.exists("user#"..index)) do
index = index + 1
end
#268719 read() persisting after parallel waitForAny returned a different function
Posted by
The Crazy Phoenix
on 31 July 2017 - 11:45 PM
in
Ask a Pro
local killed = false
local oldPullEvent = os.pullEvent
function os.pullEvent(filter)
while true do
local event, r1, r2, r3, r4, r5 = os.pullEvent()
--# In place of this comment, check if the event would trigger the custom behaviour and, if so, set killed = true and return an enter key event.
if not filter or event == filter then
return event, r1, r2, r3, r4, r5
end
end
end
local input = read()
if killed then
--# Custom behaviour
else
--# Enter pressed by the user
end
os.pullEvent = oldPullEvent
There are different ways of editing os.pullEvent to cause the behaviour you want. This is only one way of doing it.
#268510 Quartz OS. True sandboxed users.
Posted by
The Crazy Phoenix
on 24 July 2017 - 04:32 PM
in
Operating Systems
MineRobber___T, on 06 July 2017 - 06:05 AM, said:
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.
#268948 Problems with string and variables (exporting program)
Posted by
The Crazy Phoenix
on 11 August 2017 - 05:20 AM
in
Ask a Pro
#268923 Problems with string and variables (exporting program)
Posted by
The Crazy Phoenix
on 10 August 2017 - 07:02 AM
in
Ask a Pro
If you want to validate the user's input, try disk.hasData(response1). If it returns true, that means that the disk drive exists and contains a floppy disk.
#268871 Potential Computercraft Bug
Posted by
The Crazy Phoenix
on 08 August 2017 - 11:23 AM
in
Ask a Pro
In fact, you don't even need multithreading if you listen to the rednet_message or modem_message event.
local timer = os.startTimer(0.3)
local fuel = false
local state = false
while true do
local event, data, msg = os.pullEvent()
if event == "rednet_message" and data == 7 then
fuel = msg == "fuelLow" and true or (msg == "fuelGood" and false or fuel)
elseif event == "timer" and data == timer then
if fuel then
state = not state
rs.setOutput("left", state)
else
-- No delay next time fuel is low.
state = false
end
timer = os.startTimer(0.3)
end
end
#268865 Potential Computercraft Bug
Posted by
The Crazy Phoenix
on 08 August 2017 - 09:39 AM
in
Ask a Pro
Instead of using a shared variable and repeatedly checking, use os.queueEvent and os.pullEvent to signal to the alert function what it should do.
#268774 PIM Help
Posted by
The Crazy Phoenix
on 03 August 2017 - 09:22 AM
in
Ask a Pro
- ComputerCraft | Programmable Computers for Minecraft
- → The Crazy Phoenix's Content


