This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
lucasarnulphy's profile picture

Wireless redstone

Started by lucasarnulphy, 06 December 2012 - 02:55 AM
lucasarnulphy #1
Posted 06 December 2012 - 03:55 AM
Hello, I've tried to made a program to put on redstone wirelessely but it didn't work, can you help me and explain me too how to copy and past code in computercraft
Thanks
PixelToast #2
Posted 06 December 2012 - 04:22 AM
to transfer a message wirelessly you will need to use the rednet modem
to detect redstone you will need to use

os.pullEvent("redstone")

now use

rs.getOutput("side")
to return the output of that side
here is an example:

sender:

rednet.open("top") -- replace the top with the side the modem is on
local on=false
local last=false
while true do
if rs.getOutput("front") then -- replace front with what side you want to send
  on=true
else
  on=false
end
if on~=last then
  rednet.send(4,tostring(on)) -- replace 4 with the receivers id
  last=on
end
os.pullEvent("redstone")
end
receiver:
rednet.open("top")
while true do
	p={rednet.receive()}
	if p[1]==6 then -- replace 6 with the senders id
		if p[2]=="true" then
			rs.setOutput("back",true)
		else
			rs.setOutput("back",false)
		end
	end
end

as far as i know you can only paste 10 chars at a time :s
if your on a server either get access to the mods/computercraft/ folder
or upload your code to http://pastebin.com
then take the pastebin.com/xxxxxxxxx
and go into a computer and type this in the shell

pastebin get xxxxxxxxx filename
(where xxxxxxxx be the code in the url)

you can also check out CCcopy but i havent tried it because i have a github and an auto updater
lucasarnulphy #3
Posted 06 December 2012 - 04:25 AM
Thanks
lucasarnulphy #4
Posted 06 December 2012 - 04:34 AM
Error pastebin bios:338 :1: '=' espected
PixelToast #5
Posted 06 December 2012 - 04:42 AM
Error pastebin bios:338 :1: '=' espected
you are supposed to run pastebin program from the shell not the lua prompt
lucasarnulphy #6
Posted 06 December 2012 - 06:31 AM
Thanks but what do you mean by shell ? the windows than opens when you open a computer if it is so it says "no such program"
bjornir90 #7
Posted 06 December 2012 - 06:42 AM
Thanks but what do you mean by shell ? the windows than opens when you open a computer if it is so it says "no such program"
The shell is the first window you see when you rght-click a non-used computer. The one with the ">" :)/> Are you sure you type it like that :


pastebin get idOfFile nameOfFile
Lyqyd #8
Posted 06 December 2012 - 06:44 AM
That's the error one receives when http is disabled.
bjornir90 #9
Posted 06 December 2012 - 06:48 AM
Oh yes, you must enble http by editing the mod_computercraft config file and set the line http_enabled="false" to http_enabled="true" or something like that to make it work :)/>
lucasarnulphy #10
Posted 06 December 2012 - 06:49 AM
Ok thanks do you have a tutorial that shows how to enable http
bjornir90 #11
Posted 06 December 2012 - 06:55 AM
Ok thanks do you have a tutorial that shows how to enable http
It's explained at the top of this page : http://computercraft.info/wiki/index.php?title=HTTP_(API)
lucasarnulphy #12
Posted 06 December 2012 - 07:06 AM
The link doesn't work, can you tell me where is the mod_computercraft config file

Thanks
Cranium #13
Posted 06 December 2012 - 07:16 AM
Fixed link.
lucasarnulphy #14
Posted 06 December 2012 - 07:38 AM
The receiver work but the sender not :

My sender :


rednet.open("left")
local on=false
local last=false
while true do
if rs.getOutput("right")
else
  on=false
end
if on~=last then
  rednet.send(46,tostring(on))
  last=on
end
os.pullEvent("redstone")
end

Error bios:338: [string "sender"]:6 'then' expected
ChunLing #15
Posted 06 December 2012 - 07:44 AM
Expected behavior of this code is to set the variable on to false, and keep it false under every circumstance. It also sets last to false, and if it somehow becomes not false, it sets it equal to on (which is always false) and sends a rednet message containing "false" (the value of tostring(on)).

It repeats the loop every time there is a redstone event.

So, if this is not what you were trying to do (and I guess it is not), then what were you trying to do?
lucasarnulphy #16
Posted 06 December 2012 - 07:52 AM
In the hight of the topic, there is what I want to do, PixelToast answered me and give me an exaample code , when I try to launch the sender code there is an error Error bios:338: [string "sender"]:6 'then' expected
Dlcruz129 #17
Posted 06 December 2012 - 04:19 PM
Fixed code for you, "then" expected is pretty self-explanatory, all if statements in Lua require the word "then" at the end. I also indented your code.

rednet.open("left")
local on=false
local last=false
while true do
  if not rs.getOutput("right") then
    on=false
  end
  if on~=last then
    rednet.send(46,tostring(on))
    last=on
  end
end
ChunLing #18
Posted 06 December 2012 - 08:16 PM
Yes, that repairs the problem with the missing then. I still don't believe it causes this code to do anything useful, though. And it burns cycles like crazy too.

put on redstone wirelessely
That's not a lot of information, but I presume PixelToast's code was an answer to it. Why did you alter it so drastically? It had two very important elements that you don't have in your current loop, a way to change on to true when there was redstone output (though what good that does I still don't know) and the os.pullEvent("redstone") so that the loop only ran when there was a change in the redstone state.

Please explain exactly what behavior you desire from the code.