25 posts
Posted 14 November 2012 - 01:03 PM
Is there a way to determine in lua if the computer running the program is a turtle or a static computer?
NEVERMIND < I figured out:
if(turtle~=nil)then
–is turtle
else
–is computer
end
2447 posts
Posted 14 November 2012 - 01:10 PM
if turtle then
– is turtle
else
– is not turtle
end
1054 posts
Posted 14 November 2012 - 01:10 PM
local isTurtle = turtle ~= nil
Edit: ninja'd :)/>/> :P/>/>
1688 posts
Location
'MURICA
Posted 14 November 2012 - 01:23 PM
if (turtle)
– is turtle
else
– is not turtle
end
I know you were just making an example, but the missing "then" is really bothering me :P/>/>
3790 posts
Location
Lincoln, Nebraska
Posted 14 November 2012 - 01:26 PM
*GASP*
Cloudy made a noob mistake leaving out that 'then'.
Heh, I make that mistake all the time though.
871 posts
Posted 14 November 2012 - 01:30 PM
give him a break, cloudy's busy doing java code all day, working on CC and CCSensors. In java, that was perfectly fine. :P/>/>
3790 posts
Location
Lincoln, Nebraska
Posted 14 November 2012 - 01:34 PM
Well, when you put it that way, I guess I can give him some slack. Workin' hard to make the rest of us happy. GO CLOUDY, YOU CAN DO IT!
1548 posts
Location
That dark shadow under your bed...
Posted 14 November 2012 - 01:44 PM
nothing like people going psycho on the forums to cheer you up :P/>/> lets all scream random stuff lol -rolls eyes-
2447 posts
Posted 14 November 2012 - 10:05 PM
Damn it! Edited :P/>/>
3 posts
Location
France
Posted 23 November 2012 - 06:57 AM
computerScreenSize = {51,19}
turtleScreenSize = {39,13}
actualSize = {term.getSize()}
if actualSize == computerScreenSize then
actualTerminal = "computer"
elseif actualSize == turtleScreenSize then
actualTerminal = "turtle"
else
actualTerminal = "monitor"
print("This terminal is a "..actualTerminal)
Cannot detect if run on a monitor (will print "This terminal is a monitor")
1688 posts
Location
'MURICA
Posted 23 November 2012 - 07:41 AM
Cannot detect if run on a monitor (will print "This terminal is a monitor")
First off, it's missing an end.
computerScreenSize = {51,19}
turtleScreenSize = {39,13}
actualSize = {term.getSize()}
if actualSize == computerScreenSize then
actualTerminal = "computer"
elseif actualSize == turtleScreenSize then
actualTerminal = "turtle"
else
actualTerminal = "monitor"
end --## added the end here
print("This terminal is a "..actualTerminal)
Secondly, tables don't really work like that. They have the same values, but are entirely different objects, and won't come out as the same when compared. You'll probably just have to compare the tables' individual values. I would personally make a function for doing so for convenience.
function compare(first, second)
for k,v in pairs(first) do
if first[k] ~= second[k] then
return false
end
end
return true
end
computerScreenSize = {51,19}
turtleScreenSize = {39,13}
actualSize = {term.getSize()}
if compare(actualSize, computerScreenSize) then
actualTerminal = "computer"
elseif compare(actualSize, turtleScreenSize) then
actualTerminal = "turtle"
else
actualTerminal = "monitor"
end --## added the end here
print("This terminal is a "..actualTerminal)
1548 posts
Location
That dark shadow under your bed...
Posted 23 November 2012 - 08:00 AM
is there no way to see if the term has been redirected? can we not access the redirect stack? that would make everything sooo much easier
8543 posts
Posted 23 November 2012 - 09:19 AM
No, we can't access the redirect stack. One trick we can use is this:
if turtle and (term.getSize()) == 39 then
--is a turtle.
elseif not turtle and (term.getSize() == 51 then
--is a computer.
else
--is a monitor.
end