Posted 17 May 2013 - 11:06 PM
hello, i'm making a railcraft track control program. I'm calling it RailCraft OS (it probably shouldn't/wouldn't be called an OS, but that's what i'm gonna call it)
I've made a little boot up logo the computer write's to the monitor "rcOS"
then the program loads some tables (coords of signal controller boxes)
then it checks to see how long the table is ex. [1] to [7]
then writes 7 'O' onto the screen
the problem is that the write() is conflicting with the other write()
ex. write("rcOS")
later on we have a for loop that writes depending on what a table variable is.
ex.
So what's happening is the write("rcOS") isn't appearing on the screen, just the write("O") which is way later on in the code.
So I decided to put the boot logo in a separate file and then have that file run the main program
startup file shows boot logo then runs main program: http://pastebin.com/MGmm1BdG
note that *–* is meaning that I put '–' so that the code ignores shell.run()
The same thing is happening but some even weirder trickery is going on.
if I put *–*shell.run("rcOS") then the logo "randomly" appears ex. the first time I run this program after I change the above it won't write, but the second time and onwards it will write. As soon as I put shell.run("rcOS") then the logo stops displaying.
So here's the weird part. I didn't have function runNextFile() I just had shell.run("rcOS") at the end of the code thinking it would be ran last. NOPE! this program ran ("rcOS") as soon as it started running. BUT, this main code had print() and other commands, none of those displayed or showed up. I noticed it was writing to the screen code from this file. ex. write("O")
I think it even ran the code multiple times, or was changing the textScale.
I put shell.run() into a function hoping this would force it to be ran last. (I think it kind of worked but could be still running in the background)
So incase that wasn't clear:
I run "startup" which SHOULD show "rcOS" on the monitor (it doesn't) but during this time is writing the following to the monitor:
"O O O O O O
O O O O O O" (these O's are from the main program, which should NOT be running yet)
BUT none of the print(variable) is running, (I have sleep() throughout the file) nothing else is running from the main program I think.
Then after the main sleep time is over the print() and all the other data start showing up.
I'm a bit frustrated at this point, if you need any more info ask, and i'll give.
Question #2 (it's shorter) (also the main reason why I split the program into two different programs)
You can't have "m.setTextScale() twice in a program. I can't display "rcOS" at scale 5 and then near the bottom of the script have "O" displayed at scale 2. (I think "rcOS" isn't displayed)
So I thought, if I can only have m.setTextScale() written ONCE in a file then how about we write it to a variable?
textScale = 5 – Not local, it needs to be accessed throughout the code
function scale()
m.setTextScale(textScale) –now wrapped to a variable :D/>
end
so now when I want to change the text size I do this
textScale = 2
scale()
So now maybe it will work?? Nope, it just ignores the upper most part and displays the bottom part
the uppermost part:
textScale = 5 –I don't need to put 5 and scale() because it's like that at default, but why not? what if I want to call the boot logo to run again. I might want to call it on PC shutdown, which means I would have to change it back to 5
scale()
m.write("rcOS")
I'm thankful for any help :D/>
I've made a little boot up logo the computer write's to the monitor "rcOS"
then the program loads some tables (coords of signal controller boxes)
then it checks to see how long the table is ex. [1] to [7]
then writes 7 'O' onto the screen
the problem is that the write() is conflicting with the other write()
ex. write("rcOS")
later on we have a for loop that writes depending on what a table variable is.
ex.
--Set variables: --these variables tell the program to write the 'O''s to the next line before we reach the end of the monitor
X =2
Y = 2
inc = 1 --inc stands for increment
for i = 1, table.getn(tableY()) do --calls the function tableY, it returns the length of the table ex.[7]
m.setCursorPos(X,Y)
m.write("O")
X = X+2
inc = inc+1
if inc == 5 then Y=Y+2 inc = 1 X=2 end
end
So what's happening is the write("rcOS") isn't appearing on the screen, just the write("O") which is way later on in the code.
So I decided to put the boot logo in a separate file and then have that file run the main program
startup file shows boot logo then runs main program: http://pastebin.com/MGmm1BdG
m = peripheral.wrap("top")
if m == nil then error("Error: Monitor not found") end --if no monitor then error()
m.clear() --clear monitor incase there is previous data on it
sleep(1.5)
local maxw,maxh = m.getSize() --get monitor size
local Calc = 1
if maxh <= 4 then Calc = 0 end --calculate if the monitor is small, and if so use 0 so that the text centers to the screen better (aesthetic purposes only)
print(Calc)
local mx = math.floor(maxw/2-1)
local mh = math.floor(maxh/2+Calc) --Takes screen size ex. 30 and /2 to find center of screen(15)
print("w", maxw)
print("h", maxh)
m.setCursorPos(mx,mh) -- sets cursor to the above
--m.setCursorPos(math.floor(maxw/2-1),math.floor(maxh/2)) --Change +1 to +0 if you have a small monitor --This one didn't seem to be working, so I was testing the above code, using variables. (didn't work)
print(mx)
print(mh)
m.setTextScale(5)
m.setTextColor(16384)
m.write("rcOS") --should display to screen, but it doesn't
sleep(2)
function runNextFile()
shell.run("rcOS") --Runs the main program
end
runNextFile()
note that *–* is meaning that I put '–' so that the code ignores shell.run()
The same thing is happening but some even weirder trickery is going on.
if I put *–*shell.run("rcOS") then the logo "randomly" appears ex. the first time I run this program after I change the above it won't write, but the second time and onwards it will write. As soon as I put shell.run("rcOS") then the logo stops displaying.
So here's the weird part. I didn't have function runNextFile() I just had shell.run("rcOS") at the end of the code thinking it would be ran last. NOPE! this program ran ("rcOS") as soon as it started running. BUT, this main code had print() and other commands, none of those displayed or showed up. I noticed it was writing to the screen code from this file. ex. write("O")
I think it even ran the code multiple times, or was changing the textScale.
I put shell.run() into a function hoping this would force it to be ran last. (I think it kind of worked but could be still running in the background)
So incase that wasn't clear:
I run "startup" which SHOULD show "rcOS" on the monitor (it doesn't) but during this time is writing the following to the monitor:
"O O O O O O
O O O O O O" (these O's are from the main program, which should NOT be running yet)
BUT none of the print(variable) is running, (I have sleep() throughout the file) nothing else is running from the main program I think.
Then after the main sleep time is over the print() and all the other data start showing up.
I'm a bit frustrated at this point, if you need any more info ask, and i'll give.
Question #2 (it's shorter) (also the main reason why I split the program into two different programs)
You can't have "m.setTextScale() twice in a program. I can't display "rcOS" at scale 5 and then near the bottom of the script have "O" displayed at scale 2. (I think "rcOS" isn't displayed)
So I thought, if I can only have m.setTextScale() written ONCE in a file then how about we write it to a variable?
textScale = 5 – Not local, it needs to be accessed throughout the code
function scale()
m.setTextScale(textScale) –now wrapped to a variable :D/>
end
so now when I want to change the text size I do this
textScale = 2
scale()
So now maybe it will work?? Nope, it just ignores the upper most part and displays the bottom part
the uppermost part:
textScale = 5 –I don't need to put 5 and scale() because it's like that at default, but why not? what if I want to call the boot logo to run again. I might want to call it on PC shutdown, which means I would have to change it back to 5
scale()
m.write("rcOS")
I'm thankful for any help :D/>