This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
ScruffyRules's profile picture

[Question] os.getComputerLabel()

Started by ScruffyRules, 10 October 2012 - 06:16 AM
ScruffyRules #1
Posted 10 October 2012 - 08:16 AM
im making a menu screen and i want the computer(s)/turtle(s) Label to be in the menu (left top) so i want the output of os.getComputerLabel() to a write("") or a print("") can any one help me? i want it to be write("") more than print("").
Thanks a lot Scruffy. also im new at Lua!

If you want the code just ask! :3
Luanub #2
Posted 10 October 2012 - 08:20 AM
Try this

local lbl = os.getComputerLabel()

term.setCursorPos(1,1) -- change this to where you want it to print
write(lbl)

You should probably go through some of the tutorials before going to much further. This is pretty basic.
JoshhT #3
Posted 10 October 2012 - 08:32 AM
I agree with luanub. This is very basic stuff.

You could do either,

print(os.getComputerLabel())
write(os.getComputerLabel())

And if you think you might forget to label a computer and run this program.

local comp = os.getComputerLabel()

if comp ~= null then
  -- print or write comp.
  print(comp)
end
ScruffyRules #4
Posted 10 October 2012 - 08:37 AM
I agree with luanub. This is very basic stuff.

You could do either,

print(os.getComputerLabel())
write(os.getComputerLabel())

Thank you very much! im very tired so im not thinking that well!
Orwell #5
Posted 10 October 2012 - 10:26 AM
I agree with luanub. This is very basic stuff.

You could do either,

print(os.getComputerLabel())
write(os.getComputerLabel())

And if you think you might forget to label a computer and run this program.

local comp = os.getComputerLabel()

if comp ~= null then
  -- print or write comp.
  print(comp)
end

I just want to add that you can also take this exception in account by doing it like this:

term.setCursorPos(1,1)
term.write(os.getComputerLabel() or 'unlabeled')
JoshhT #6
Posted 10 October 2012 - 10:36 AM
I just want to add that you can also take this exception in account by doing it like this:

term.setCursorPos(1,1)
term.write(os.getComputerLabel() or 'unlabeled')

I did not know this. Still learning the ins and outs of lua.
With java though, the most similar thing would be like,

string lbl = os.getComputerLabel();
system.println(lbl != null ? lbl : "Unlabeled");
I'm pretty sure that's right, haven't used that in a while. Lol.
Lyqyd #7
Posted 10 October 2012 - 07:47 PM
I agree with luanub. This is very basic stuff.

You could do either,

print(os.getComputerLabel())
write(os.getComputerLabel())

And if you think you might forget to label a computer and run this program.

local comp = os.getComputerLabel()

if comp ~= null then
  -- print or write comp.
  print(comp)
end

Also, in Lua, we use nil, not null.
JoshhT #8
Posted 11 October 2012 - 06:34 AM
I agree with luanub. This is very basic stuff.

You could do either,

print(os.getComputerLabel())
write(os.getComputerLabel())

And if you think you might forget to label a computer and run this program.

local comp = os.getComputerLabel()

if comp ~= null then
  -- print or write comp.
  print(comp)
end

Also, in Lua, we use nil, not null.

I also did not know this. Lol.
Haven't done much OOP in lua/CC yet. It's kind of limited in that regard.
ScruffyRules #9
Posted 11 October 2012 - 08:18 AM
I just want to add that you can also take this exception in account by doing it like this:

term.setCursorPos(1,1)
term.write(os.getComputerLabel() or 'unlabeled')
oooooOOOhh Thank you!
Ditto8353 #10
Posted 11 October 2012 - 02:15 PM
Haven't done much OOP in lua/CC yet. It's kind of limited in that regard.

Read the Lua Manual, specifically the portion on metatables in Part 2 which leads into OO. The syntax will take some time to get used to, but Lua is far from being 'limited'.
JoshhT #11
Posted 13 October 2012 - 01:26 AM
Haven't done much OOP in lua/CC yet. It's kind of limited in that regard.

Read the Lua Manual, specifically the portion on metatables in Part 2 which leads into OO. The syntax will take some time to get used to, but Lua is far from being 'limited'.
In regards to that post I was referring to ComputerCraft.
Lyqyd #12
Posted 13 October 2012 - 01:28 AM
ComputerCraft does not limit the possibility of creating object-oriented code in any way.
JoshhT #13
Posted 13 October 2012 - 01:30 AM
I meant inside computercraft. I give up. Lol.
ScruffyRules #14
Posted 13 October 2012 - 05:46 AM
I meant inside computercraft. I give up. Lol.
i would have too!
Kadecamz #15
Posted 14 October 2012 - 12:29 AM
FUCK NULL!!!!


MAY NIL KILL THEM ALL AND LEAD US TO GLORY!