9 posts
Location
White Plains, NY
Posted 18 March 2013 - 11:15 AM
So I'm attempting to set up a computer controlled frame elevator and am running into problems with my coding.. I've gotten the mechanics running properly by switches and got the messages to go between the computers… for some reason it's not running the bundled output for me.. Where am i going wrong?
Screenshots:
Spoiler
Elevator Up Frame Motor Circuit:
Elevator Down Frame Motor Circuit:
Elevator Motor Control Computer:
Elevator with Touch Screen and Selection Computer:
Selection/Touchscreen Code:
http://pastebin.com/xgqecL2iMotor Control Code:
http://pastebin.com/WvxV8jSg
1511 posts
Location
Pennsylvania
Posted 18 March 2013 - 11:21 AM
Can you tell us what line it throws an error? Or does it not throw an error?
9 posts
Location
White Plains, NY
Posted 18 March 2013 - 11:50 AM
doesn't throw an error but when the motor control computer receives the rednet message (tested and it does) it doesn't do anything
1522 posts
Location
The Netherlands
Posted 18 March 2013 - 12:29 PM
When you activate a bundled cable, you immediately stop it. You should use:
rs.setBundledOutput( yourSide, color )
sleep(0.4)
-- disable it again
i hope this helps you
9 posts
Location
White Plains, NY
Posted 18 March 2013 - 12:49 PM
When you activate a bundled cable, you immediately stop it. You should use:
rs.setBundledOutput( yourSide, color )
sleep(0.4)
-- disable it again
i hope this helps you
except that i'm doing it to pulse the deployer and frame motor… each cycle of that loop should move the elevator up or down one block
9 posts
Location
White Plains, NY
Posted 19 March 2013 - 04:33 AM
ok got the up/down functions to work.. my only problem now is the curfloor variable keeps resetting to ground.. i guess this is bad too when the computer reboots (server reboot or manual in game).. should i be trying to store the curfloor variable in a file so it always knows where it is? how would i do that?
1522 posts
Location
The Netherlands
Posted 19 March 2013 - 04:45 AM
You would do something like this:
To set to the file:
local file = fs.open( "floor", "w" )
file.write( textutils.serialize(currFloor) ) -- textutils not really needed
file.close()
To read the file
local file = fs.open( "floor", "w" )
local reader = file.readAll()
file.close()
local currFloor = textutils.unserialize( reader )
This is how you should write to a file, if you have questions about this, please be sure to ask them!
9 posts
Location
White Plains, NY
Posted 19 March 2013 - 06:25 AM
ok I've used what you gave me to read/write to files.. but i'm getting an error of "elevator:51: attempt to call nil" when it runs any of the 3 compare functions (top, second or ground)
I've updated the pastebin for the motor control program to what i'm using now..
7508 posts
Location
Australia
Posted 20 March 2013 - 02:03 PM
Not too sure why the problem is. it seems that it was not able to open the file. give this code a try, i just changed the order of some things a little
http://pastebin.com/7pr0H8Yy
9 posts
Location
White Plains, NY
Posted 20 March 2013 - 03:01 PM
still having a bit of trouble with it.. looked in the data file and it's got groundground in it… kinda why I was trying to do 2 data files.. one for the current floor info and one for the selected floor.. didn't know how to make it read/write different lines…
it seems to work otherwise except I'm tweaking the delays for the deployer/frame motor system (frame motor keeps going off before the deployer)..
I updated with the latest changes I've made.. (p.s. obviously all the print statements are for debugging purposes since this terminal is buried underground)
can you suggest how to get the file stuff working with your way of one data file or what I need to change to use 2? the code you added/changed is a bit confusing (ie. the persistdata function and the whole t1, t2 thing)
thanks for the help so far guys!
7508 posts
Location
Australia
Posted 20 March 2013 - 03:07 PM
oh oops… fix this…
local function persistData()
local h = fs.open('.data', 'w')
h.write(curfloor..'\n')
h.write(sel)
h.close()
end
also add this to the start of the loadOnStartup file
if not fs.exists('.data') then
curfloor = <some default value>
sel = <some default value>
end
the method I implemented you need to have it run loadOnStartup
everytime the script starts… the t1 and t2 variables are there so that if the line is nil we wont be overriding the existing data.
there is no need to be reading from the file all the time, which is how you were doing it. the
persistData function is there to write the data out to file.
9 posts
Location
White Plains, NY
Posted 21 March 2013 - 06:16 AM
I made the changes.. should the loadOnStartup() function get called somewhere? it looks like it never gets used?
when i add it under the rednet.open statement i get a tried to reference nil from line 12 ( the t1=h.readLine() )
also when i add the ..'n' to the persistData() function i get a tried to concatenate string and nil error for that line
oh oops… fix this…
local function persistData()
local h = fs.open('.data', 'w')
h.write(curfloor..'\n')
h.write(sel)
h.close()
end
also add this to the start of the loadOnStartup file
if not fs.exists('.data') then
curfloor = <some default value>
sel = <some default value>
end
the method I implemented you need to have it run loadOnStartup
everytime the script starts… the t1 and t2 variables are there so that if the line is nil we wont be overriding the existing data.
there is no need to be reading from the file all the time, which is how you were doing it. the
persistData function is there to write the data out to file.
1522 posts
Location
The Netherlands
Posted 21 March 2013 - 06:41 AM
I made the changes.. should the loadOnStartup() function get called somewhere? it looks like it never gets used?
when i add it under the rednet.open statement i get a tried to reference nil from line 12 ( the t1=h.readLine() )
also when i add the ..'n' to the persistData() function i get a tried to concatenate string and nil error for that line
oh oops… fix this…
local function persistData()
local h = fs.open('.data', 'w')
h.write(curfloor..'\n')
h.write(sel)
h.close()
end
also add this to the start of the loadOnStartup file
if not fs.exists('.data') then
curfloor = <some default value>
sel = <some default value>
end
the method I implemented you need to have it run loadOnStartup
everytime the script starts… the t1 and t2 variables are there so that if the line is nil we wont be overriding the existing data.
there is no need to be reading from the file all the time, which is how you were doing it. the
persistData function is there to write the data out to file.
The load on startfile, by that he means put it at the top of your code.
Also try currFloor, ofcourse this is a variable you can change
7508 posts
Location
Australia
Posted 21 March 2013 - 03:14 PM
I made the changes.. should the loadOnStartup() function get called somewhere? it looks like it never gets used?
when i add it under the rednet.open statement i get a tried to reference nil from line 12 ( the t1=h.readLine() )
the loadOnStartup() should be called just before the while loop starts. oh file is open in wrong mode, i did 'w' instead of 'r' … that'll teach me to code late at night.
also when i add the ..'n' to the persistData() function i get a tried to concatenate string and nil error for that line
its meant to be '\n' thats the newline character… im not sure why it was saying that the new line is nil o.O what did you do?
Fixed version that incorporates all the suggested changes:
http://pastebin.com/22NUMBHL
9 posts
Location
White Plains, NY
Posted 21 March 2013 - 04:07 PM
so still not sure what's up but using your latest code I'm still getting the concatenate nil and string for line 27, the h.write(curfloor..'\n') line.. honestly every time i've tried to do concatenates it seems to do that..
oh and the .data file is empty.. could explain the nil part?
7508 posts
Location
Australia
Posted 21 March 2013 - 04:17 PM
yeh maybe delete the .data file and run it again, the nil error is saying that the curfloor variable is empty, not sure why tho, maybe its coz the .data was in the system. also, shouldn't be needed, but just incase add after line 118 a call to persistData()
9 posts
Location
White Plains, NY
Posted 21 March 2013 - 07:52 PM
updated the code one last time cause…. IT WORKS! finally.. took a bit more tweaking of the deployer/motor breaker/motor timings but it's done!
thanks for all the help guys!
18 posts
Posted 22 June 2013 - 08:29 PM
whats the max amount of floors?