RedNet
#1
Posted 25 March 2013 - 02:30 AM
#2
Posted 25 March 2013 - 04:23 AM
rednet.open("side")
rednet.send(id, "dig")
Turtle
rednet.open("side")
Id, msg = rednet.recieve()
shell.run(msg)
#3
Posted 25 March 2013 - 05:42 PM
It is better to use some functions inside the program instead of using shell.run() - that's just a bad style, I think. And if you do use the shell.run() at least check the message you recieved.
rednet.open("side")
while true do
Id, msg = rednet.recieve()
if msg == "Dig" or msg == "Don't dig", or msg == "Whatever you want" then
shell.run(msg)
end
end
#4
Posted 25 March 2013 - 06:36 PM
To run code in string form, you'd have to use loadstring.
Example:
local example = "print('hello, this has been printed by loading a string!')"
local runtime = loadstring(example)
runtime()
Also there is not too much danger of using shell.run directly from the rednet because you will only be able to run programs which have already been created.
#5
Posted 25 March 2013 - 06:39 PM
Bubba, on 25 March 2013 - 06:36 PM, said:
To run code in string form, you'd have to use loadstring.
Example:
local example = "print('hello, this has been printed by loading a string!')"
local runtime = loadstring(example)
runtime()
Is there a way to check if the sent message is actually a valid function to call?
#6
Posted 25 March 2013 - 06:47 PM
remiX, on 25 March 2013 - 06:39 PM, said:
Bubba, on 25 March 2013 - 06:36 PM, said:
To run code in string form, you'd have to use loadstring.
Example:
local example = "print('hello, this has been printed by loading a string!')"
local runtime = loadstring(example)
runtime()
Is there a way to check if the sent message is actually a valid function to call?
Yup, just use pcall(loaded func). Pcall will execute the code, but it won't stop the program if it's invalid
Example:
local invalid = "notafunc()"
local loaded=loadstring(invalid)
local success, catch = pcall(loaded)
print("Success: "..success)
print("Errors (if any): "..catch)
Output:
Success: false
Errors (if any): string:1: attempt to call nil
#7
Posted 25 March 2013 - 06:51 PM
But I think that code would error on the second last line because you can't concatenate string and a boolean
Going to need to tostring it I think xD
#8
Posted 25 March 2013 - 06:54 PM
Edit: Oops nevermind. That's just for strings and numbers, not strings and booleans. Right you are, RemiX
#9
Posted 25 March 2013 - 08:04 PM
Bubba, on 25 March 2013 - 06:36 PM, said:
#10
Posted 25 March 2013 - 08:53 PM
PonyKuu, on 25 March 2013 - 08:04 PM, said:
Bubba, on 25 March 2013 - 06:36 PM, said:
That's what pcall is for. And you think that shell.run should be avoided in all situations? I feel like shell.run does have its uses, although many people use it overly much or in the wrong way.
#11
Posted 25 March 2013 - 09:53 PM
#12
Posted 28 March 2013 - 04:46 PM
PonyKuu, on 25 March 2013 - 09:53 PM, said:
For what he's doing, it's fine. shell.run() is an easy and effective way to handle a program from within another program, like he did with his frame quarry in season 5.
#13
Posted 28 March 2013 - 08:18 PM
function make_hole_incredibly_fast () <place miner> <wait some seconds> <dump stuff> end while true do local message = <wait for message> if message == "I need a hole! NOW!" then make_hole_incredibly_fast () end endAlso, his turtles dump the stuff to a chest only from first 10 slots. Why he ignores other ones? It is possible to find 11 or more different types of blocks in one column, so some of them would stay in turtle.
Also, his master computer doesn't care about what is going on there. It waits 30 seconds and repeats the cycle. So it is possible that miners would mine the same place again. Under certain circumstanses of course, but that's a bit inaccurate... I like his idea of using CC for small utility programs, I just don't like the style...
#14
Posted 28 March 2013 - 08:24 PM
EDIT: And when I say verbose I mean, a ~100 line script that could be redone in a max of ~30 lines
PonyKuu, on 28 March 2013 - 08:18 PM, said:
Edited by TheOriginalBIT, 28 March 2013 - 08:34 PM.
#15
Posted 28 March 2013 - 08:44 PM
TheOriginalBIT, on 28 March 2013 - 08:24 PM, said:
*Kuu looks at his 500-string APIs*
Le sigh....
#16
Posted 28 March 2013 - 08:56 PM
PonyKuu, on 28 March 2013 - 08:44 PM, said:
PonyKuu, on 28 March 2013 - 08:44 PM, said:
Ok if you can get my any of my apis and reduce their size down 66% I will concede my point.
#17
Posted 28 March 2013 - 09:05 PM
I'm not sure if I it is possible to shrink them down... It is possible, I think, I just don't see how to do that. But if I remove ll the comments they would be a bit smaller... Or maybe a lot smaller ~_~
#18
Posted 28 March 2013 - 09:14 PM
if you are talking about the master/module, iirc there were some improvements that could be made. pm me to discuss more, lets not clog up this thread with more off topic stuffz.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











