767 posts
Posted 13 January 2013 - 08:57 AM
Hello
i am making a forcefield protector, with 1 computer inside of the forcefield, and one outside… i am trying to make it so, when i rightclick a monitor, the diplay changes to red/green, and then sends a action to a "force" computer, which handles the message, and turning the forcefield on/off. But… in this code, i can only switch ( so it changes to red/green ) if it recives a message at the SAME time, as i click the monitor..
Spoiler
http://pastebin.com/pWAxLc2kCan you see the fail/ can you solve the error i am having?
Thanks in advance :D/>
2088 posts
Location
South Africa
Posted 13 January 2013 - 10:42 AM
Before I go over the code, could you upload a picture of how this is setup?
I've never used forcefields before and want to test them, and help you while doing so :P/>
767 posts
Posted 13 January 2013 - 10:50 AM
oh.. sorry… two minutes…..
2088 posts
Location
South Africa
Posted 13 January 2013 - 11:08 AM
Been 20 :3
Btw, what's the block called? I've searched for Forcefield and Force field, but nothing o.0
767 posts
Posted 13 January 2013 - 11:21 AM
2088 posts
Location
South Africa
Posted 13 January 2013 - 11:24 AM
Damn that looks confusing o_O
I'll try set it up… lol
edit:
I have no clue what's going on xD
Opened the mffs projecter and so many colours…
hmm..
767 posts
Posted 13 January 2013 - 11:26 AM
xD.. i know… should i post a basic code, for the forcefield computer?
NOTE! i used FTB direwolf20's mod pack, in the pictures….
edit… you can also get my map.
767 posts
Posted 13 January 2013 - 11:32 AM
Damn that looks confusing o_O
I'll try set it up… lol
edit:
I have no clue what's going on xD
Opened the mffs projecter and so many colours…
hmm..
ehm did you want my world? then
Spoiler
http://www.mediafire.com/?jgb13624j1ycz94i hope your NEI is working:
search for : "MFFS"
then:
take the card surounded by a red line, which has a "Cube",
then take a green crystal.
then i just took some of the upgrades, and then putted em into the "Opt."
( i used the invisibiality upgrade )
then just shiftclick all stuffs in the mffs projector.
NOTE! the first time i tried this, i died, and my whole world had to be rebuild, because i was using it as a door. so be carefully, so you will ALWAYS be able to disable it.
2088 posts
Location
South Africa
Posted 13 January 2013 - 11:33 AM
If you can, that would be great lol. I searched it on the internet and it says I need a core. Lol No clue what I'm doing. I can't find this core ><
I'm on mindcrack atm, if that's a difference… going to open up direwolf now
767 posts
Posted 13 January 2013 - 11:35 AM
i edited the post with your Quote. :D/> now world is added.. ( remember to use direwolf20's mod pack )
and … when they said you need a core… DERP! thats for the outdated version.. this is the updated version :D/>
and now to a little question about my english… what is BTW standing for? is it "Better Than Wolves" or.. is it AFK?
2088 posts
Location
South Africa
Posted 13 January 2013 - 11:42 AM
Oh ok, lol direwolf had an update and I just clicked no XD I'll update it now then.. haha
btw = by the way.
Updating…
767 posts
Posted 13 January 2013 - 11:44 AM
Ahh… Thank you for that … :D/> now my english has been improved :D/>
2088 posts
Location
South Africa
Posted 13 January 2013 - 11:58 AM
Wow these things are awesome xD
It's working fine for me, except that it's the opposite way around (when it's red, the FF is on, when it's green, the FF is off)
All you have to do is change the colours around.
What is yours doing?
I'll still make the code more efficient though, like it shows a message etc
767 posts
Posted 13 January 2013 - 12:01 PM
but is your code the same as my?
if yes then.. wtf.. then i dunno what is wrong… when i am launching the startup to run the mon, command, it just cant handel the mouse input… only when rednet is sending…..
Why :(/>
2088 posts
Location
South Africa
Posted 13 January 2013 - 12:35 PM
Okay try this.
Delete both config files in each PC and replace the startup files with these:
Code for the PC at the MFFS Projector
Spoiler
--[[
Code for the computer attached to the MFFS projected
--]]
rednet.open("top")
running = true
FF_state = false
col = colours.red
function writeNewState(state)
file = fs.open("config", "w")
if file then
file.write(tostring(state))
file.close()
else
term.setTextColour(colours.red)
print("Error: Could not open the config file")
end
end
if fs.exists("config") then
file = fs.open("config", "r")
FF_state = file.readLine == "true"
rs.setOutput("left", FF_state)
file.close()
else
term.setTextColour(colours.yellow)
print("Information: Config file doesn't exist yet. Making it and setting default state to false.")
writeNewState("false")
end
while running do
col = FF_state and colours.lime or colours.red
term.setTextColour(colours.yellow)
write("Information: Forcefield is currently ")
term.setTextColour(col)
print(FF_state and "online" or "offline")
local id, msg = rednet.receive()
if id == 4 then -- change this to the id of the monitor pc
term.setTextColour(colours.yellow)
if msg == "on" or msg == "off" then
FF_state = not FF_state
rs.setOutput("left", FF_state)
end
end
end
Code for the PC at the monitor
Spoiler
--[[
Code for the computer attached to the monitor
--]]
rednet.open("front")
mon = peripheral.wrap("back")
running = true
col = colors.red
FF_state = false -- off
term.setCursorPos(1, 1)
term.clear()
function writeNewState(state)
file = fs.open("config", "w")
if file then
file.write(tostring(state))
file.close()
else
term.setTextColour(colours.red)
print("Error: Could not open the config file")
end
end
-- Check if file exists and read current state
if fs.exists("config") then
file = fs.open("config", "r")
FF_state = file.readLine() == "true"
col = FF_state and colours.lime or colours.red
file.close()
else
term.setTextColour(colours.yellow)
print("Information: Config file doesn't exist yet. Making it and setting default state to false.")
writeNewState("false")
end
while running do
mon.setBackgroundColour(col)
mon.clear()
term.setTextColour(colours.yellow)
write("Information: Forcefield is currently ")
term.setTextColour(col)
print(FF_state and "online" or "offline")
local event, arg1, arg2, arg3 = os.pullEvent("monitor_touch")
FF_state = not FF_state
col = FF_state and colours.lime or colours.red
writeNewState(FF_state)
rednet.send(force, FF_state and "on" or "off")
end
I just changed how the variables work, it uses true and false (booleans) for the state of the Forcefield, added information about it, etc…
Working perfectly on my side.
767 posts
Posted 13 January 2013 - 12:36 PM
I will test that ASAP!
thanks for helping!
2088 posts
Location
South Africa
Posted 13 January 2013 - 12:48 PM
Oh, forgot that you had two PC's one inside and one outside.
I'll need to change the code again so both monitor update if one of them is clicked on
2088 posts
Location
South Africa
Posted 13 January 2013 - 12:54 PM
Monitor Code
Spoiler
--[[
Code for the computer attached to the monitor
--]]
rednet.open("front")
mon = peripheral.wrap("back")
running = true
col = colors.red
FF_state = false -- off
term.setCursorPos(1, 1)
term.clear()
function writeNewState(state)
file = fs.open("config", "w")
if file then
file.write(tostring(state))
file.close()
else
term.setTextColour(colours.red)
print("Error: Could not open the config file")
end
end
-- Check if file exists and read current state
if fs.exists("config") then
file = fs.open("config", "r")
FF_state = file.readLine() == "true"
col = FF_state and colours.lime or colours.red
file.close()
else
term.setTextColour(colours.yellow)
print("Information: Config file doesn't exist yet. Making it and setting default state to false.")
writeNewState("false")
end
while running do
mon.setBackgroundColour(col)
mon.clear()
term.setTextColour(colours.yellow)
write("Information: Forcefield is currently ")
term.setTextColour(col)
print(FF_state and "online" or "offline")
local event, id, msg, arg3 = os.pullEvent()
if event == "monitor_touch" then
rednet.send(force, FF_state and "on" or "off")
elseif event == "rednet_message" then
if id == 3 and msg == "update" then -- update
FF_state = not FF_state
col = FF_state and colours.lime or colours.red
writeNewState(FF_state)
end
end
end
MFFS Project PC Code
Spoiler
--[[
Code for the computer attached to the MFFS projected
--]]
rednet.open("top")
running = true
FF_state = false
col = colours.red
function writeNewState(state)
file = fs.open("config", "w")
if file then
file.write(tostring(state))
file.close()
else
term.setTextColour(colours.red)
print("Error: Could not open the config file")
end
end
if fs.exists("config") then
file = fs.open("config", "r")
FF_state = file.readLine == "true"
rs.setOutput("left", FF_state)
file.close()
else
term.setTextColour(colours.yellow)
print("Information: Config file doesn't exist yet. Making it and setting default state to false.")
writeNewState("false")
end
while running do
col = FF_state and colours.lime or colours.red
term.setTextColour(colours.yellow)
write("Information: Forcefield is currently ")
term.setTextColour(col)
print(FF_state and "online" or "offline")
local id, msg = rednet.receive()
if id == 4 or id == 2 then -- change this to the id of the monitor pc
term.setTextColour(colours.yellow)
if msg == "on" or msg == "off" then
FF_state = not FF_state
rs.setOutput("left", FF_state)
rednet.send(2, "update")
rednet.send(4, "update")
end
end
end
Make sure you delete the config files first
767 posts
Posted 13 January 2013 - 02:07 PM
Yeah. Thanks again. :D/>