Jump to content




[Question] os.getComputerLabel()


14 replies to this topic

#1 ScruffyRules

  • Members
  • 98 posts

Posted 10 October 2012 - 07: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

#2 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 10 October 2012 - 07: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.

#3 JoshhT

  • New Members
  • 64 posts
  • LocationAustralia

Posted 10 October 2012 - 07: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


#4 ScruffyRules

  • Members
  • 98 posts

Posted 10 October 2012 - 07:37 AM

View PostJoshhT, on 10 October 2012 - 07:32 AM, said:

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!

#5 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 10 October 2012 - 09:26 AM

View PostJoshhT, on 10 October 2012 - 07:32 AM, said:

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')


#6 JoshhT

  • New Members
  • 64 posts
  • LocationAustralia

Posted 10 October 2012 - 09:36 AM

View PostOrwell, on 10 October 2012 - 09:26 AM, said:

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.

#7 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 10 October 2012 - 06:47 PM

View PostJoshhT, on 10 October 2012 - 07:32 AM, said:

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.

#8 JoshhT

  • New Members
  • 64 posts
  • LocationAustralia

Posted 11 October 2012 - 05:34 AM

View PostLyqyd, on 10 October 2012 - 06:47 PM, said:

View PostJoshhT, on 10 October 2012 - 07:32 AM, said:

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.

#9 ScruffyRules

  • Members
  • 98 posts

Posted 11 October 2012 - 07:18 AM

View PostOrwell, on 10 October 2012 - 09:26 AM, said:

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!

#10 Ditto8353

  • New Members
  • 138 posts

Posted 11 October 2012 - 01:15 PM

View PostJoshhT, on 11 October 2012 - 05:34 AM, said:

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'.

#11 JoshhT

  • New Members
  • 64 posts
  • LocationAustralia

Posted 13 October 2012 - 12:26 AM

View PostDitto8353, on 11 October 2012 - 01:15 PM, said:

View PostJoshhT, on 11 October 2012 - 05:34 AM, said:

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.

#12 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 13 October 2012 - 12:28 AM

ComputerCraft does not limit the possibility of creating object-oriented code in any way.

#13 JoshhT

  • New Members
  • 64 posts
  • LocationAustralia

Posted 13 October 2012 - 12:30 AM

I meant inside computercraft. I give up. Lol.

#14 ScruffyRules

  • Members
  • 98 posts

Posted 13 October 2012 - 04:46 AM

View PostJoshhT, on 13 October 2012 - 12:30 AM, said:

I meant inside computercraft. I give up. Lol.
i would have too!

#15 Kadecamz

  • New Members
  • 113 posts

Posted 13 October 2012 - 11:29 PM

FUCK NULL!!!!


MAY NIL KILL THEM ALL AND LEAD US TO GLORY!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users