[Question] os.getComputerLabel()
#1
Posted 10 October 2012 - 07:16 AM
Thanks a lot Scruffy. also im new at Lua!
If you want the code just ask! :3
#2
Posted 10 October 2012 - 07:20 AM
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
Posted 10 October 2012 - 07:32 AM
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
#5
Posted 10 October 2012 - 09:26 AM
JoshhT, on 10 October 2012 - 07:32 AM, said:
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
Posted 10 October 2012 - 09:36 AM
Orwell, on 10 October 2012 - 09:26 AM, said:
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
Posted 10 October 2012 - 06:47 PM
JoshhT, on 10 October 2012 - 07:32 AM, said:
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
Posted 11 October 2012 - 05:34 AM
Lyqyd, on 10 October 2012 - 06:47 PM, said:
JoshhT, on 10 October 2012 - 07:32 AM, said:
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.
#10
Posted 11 October 2012 - 01:15 PM
JoshhT, on 11 October 2012 - 05:34 AM, said:
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
Posted 13 October 2012 - 12:26 AM
Ditto8353, on 11 October 2012 - 01:15 PM, said:
JoshhT, on 11 October 2012 - 05:34 AM, said:
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'.
#12
Posted 13 October 2012 - 12:28 AM
#13
Posted 13 October 2012 - 12:30 AM
#15
Posted 13 October 2012 - 11:29 PM
MAY NIL KILL THEM ALL AND LEAD US TO GLORY!
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users