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

[1.43] os.getComputerLabel () returns nil at startup

Started by PonyKuu, 10 October 2012 - 06:31 AM
PonyKuu #1
Posted 10 October 2012 - 08:31 AM
I have a turtle with a label set, and it uses that label as hostname (it is an API global variable)
When it starts up automatically it doesn't set hostname to its label.
startup script basically shell.run's my program. If I start the program manually, hostname will be set correctly.
PonyKuu #2
Posted 10 October 2012 - 09:04 AM
Also, I should say that hostname is set using a simple API function:


function setHostname (host)
    hostname = host
end
jag #3
Posted 10 October 2012 - 09:10 AM
The setHostname function is pretty unnecessary, but you could do with
if os.getComputerLabel() ~= "TheNameYouWant" then
  os.setComputerLabel("TheNameYouWant")
end
And so you wont have a automatic way of setting the label, kinda…
PonyKuu #4
Posted 10 October 2012 - 09:14 AM
Well, I don't want hostname to always be the computer label. It is for current project only… And I probably will use that API again. It is very smal, but…
Well, if it is a bug, I think it should be fixed. If it is not - I'll find other way to make what I want to.
Cloudy #5
Posted 10 October 2012 - 11:23 AM
It works fine in startup - just tested. Must be an error in your code somewhere.

I tested it with the very simple print(os.getComputerLabel()) in a startup file.
PonyKuu #6
Posted 10 October 2012 - 11:44 AM
And what if it is in another script? And startup uses shell.run () to run that script?
Cloudy #7
Posted 10 October 2012 - 01:54 PM
Then it will work fine? The chances are that it is something in your code. It doesn't even matter where the code is being called from.
PonyKuu #8
Posted 10 October 2012 - 03:32 PM
As I said when I run that script manually it works. I'll post my code later, since I don't have access to it now.
PonyKuu #9
Posted 10 October 2012 - 06:19 PM
Oh, I'm sorry, it works on startup, but it fails if I load my SSP world, and computer starts up automatically and autostarts the program via shell.run(). THEN os.getComputerLabel() returns nil.
Cloudy #10
Posted 10 October 2012 - 08:20 PM
Aha! I tried it out, and got the same issue - however, tried in my dev build and works fine :P/>/> Go figure! So, fixed in next version.
PonyKuu #11
Posted 10 October 2012 - 08:22 PM
Yay! Thank you ^_~