504 posts
Posted 04 July 2013 - 11:24 AM
Hey everyone,
some weeks ago i posted the BeeKeeper System program on the forums and i asked for help with term.restore() and term.redirect(). However nobody seem to had an idea or didnt even looked after it… whatever.
So i ask here for some help.
This code
here is the subject.
At line 12 i save the monitor peripheral into the variable "monitor".
On line 13 i redirect the program to the monitor.
Everything works fine!
When the user wants to add a new alveary slot, i want the program to go back to the computer, because the player has to insert some names/letters and i dont want him to write blind and look at the monitors every time.
So at line 120 i have term.restore() and on line 162 and 170 i term.redirect() the program back to the monitor.
But it doesnt even restore it back to the computer.
Sincerly,
unobtanium
7508 posts
Location
Australia
Posted 04 July 2013 - 11:27 AM
So does it print to the monitor instead? or does the text not appear anywhere?
Also, with the indentation it is hard to tell……… is that inside or outside the function?
504 posts
Posted 04 July 2013 - 11:31 AM
It stays on the monitor and prints everything correctly. It just doesnt go back to the computer.
The first redirect is outside the functions.
The other term.redirect() and term.restore() are all in the addAlveary() function.
7508 posts
Location
Australia
Posted 04 July 2013 - 08:06 PM
Ok so I'm not positive, but looking over your code everything seems to look fine (unless I'm missing something). The only thing I can think of is that maybe you at some point in the code have it redirecting to the monitor for a second, or third, or fourth time, meaning that when you do
term.restore it will continue to be directed to the monitor, as redirects are in a stack. So in the event of that being true then try using this code to restore, that way we can rule out the multi redirect theory if the code does nothing. If it works, then you will have to try fix the structure of your program so it doesn't redirect multiple times.
repeat
term.restore()
local w, h = term.getSize()
until w == 51 and h == 19
504 posts
Posted 05 July 2013 - 06:48 AM
Yeah, that might be possible. But if i search term.restore() with Ctrg+F i just find these, which i listed above.
Unless the program fucks something up :S
Does it save this stack where it got redirected even if i terminate the program? Because then it would make sense.
edit:
That worked! I am so thankful again <3
You are awesome xD
2 posts
Location
Germany
Posted 05 July 2013 - 07:37 AM
wouldn't
term.redirect(term.native)
work too?
504 posts
Posted 05 July 2013 - 08:18 AM
Saw that on the wiki, but didnt really understood their expample on this :S
Probably yes.
7508 posts
Location
Australia
Posted 05 July 2013 - 09:33 PM
Does it save this stack where it got redirected even if i terminate the program? Because then it would make sense.
Yes it does, the redirects are saved in a table in the term api, so it is persistent for an entire session, the minute the computer is restarted though the table is lost.
That worked! I am so thankful again <3
You are awesome xD
No problems :)/> That really was all I figured, that it was "stuck" due to some extra redirects, which you may want to find btw, the way I showed to fix isn't a good/permanent solution, you should find out why it was happening in the first place. The code I supplied was more of a test of the conditions. ;)/> :)/>
wouldn't
term.redirect(term.native)
work too?
It would, but it is not the best way to do it as then the
term.native gets added to the redirect stack, it is just better for the problem to be fixed and to use
term.restore.
504 posts
Posted 06 July 2013 - 06:58 AM
Well, there are no extra term.redirect()
I think the problem was, that i tested the program and terminated it every so ofter, but stayed on the monitor. I should have restarted the computer more often or switched it out with an other one. (Maybe.)
8543 posts
Posted 06 July 2013 - 03:43 PM
Yeah, of course, if you run it and terminate it while it's redirected to the monitor, you are building the redirect stack up with extra monitor redirections.
504 posts
Posted 06 July 2013 - 04:11 PM
But it doesnt do it if it gets unload e.g. if i am leaving the game?
*i mean saving it
8543 posts
Posted 06 July 2013 - 05:35 PM
All redirections reset when a computer reboots, of course.