Jump to content




Require 'label set' on first boot


12 replies to this topic

#1 Andale

  • Members
  • 46 posts
  • LocationNWIndiana

Posted 25 March 2013 - 04:29 PM

I am certain I can probably figure out a program for it, but how can I make it so every new computer/turtle requires you to set a label on the first boot of it only?
My only idea is to modify the zip to have a default startup program which deletes itself after successfully setting a label.

#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 25 March 2013 - 04:33 PM

You could do a label method (which I forgot to put in, oops, see Kingdaro's post). or you could do a file method like so
if not fs.exists('.firstRunRan') then
  -- create the label here
  local h = fs.open('.firstRunRan', 'r')
  h.close()
end
Makes it easy to do a 'reset' too, just delete the file and your program will think its first run.

#3 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 25 March 2013 - 04:40 PM

Why not just always ask for a label if there is no label, instead of deleting the program?

if not os.getComputerLabel() then
  write 'Set a label for this computer: '
  os.setComputerLabel(read())
end


#4 Andale

  • Members
  • 46 posts
  • LocationNWIndiana

Posted 26 March 2013 - 10:44 AM

Sorry, that self erasre idea was only if I had to make a default startup program. We reset automatically every 3 hours and most users have their programs saved as startup so they don't gotta touch them every time.
My question was maybe poorly stated. It is more like... Do I have to make a default 'startup' file? (which is why I would have it self erase, so people are not confused by it) Is there a method to make a first run only file other than a startup?

#5 faubiguy

  • Members
  • 213 posts

Posted 26 March 2013 - 12:34 PM

If you have access to the server files, you can modify the rom/shell program and add Kingdaro's code, so when the shell starts, it automatically asks for a label. (Anywhere before the main loop at the end would probably work, or before the part where it runs the startup file if you want to it to be done if a user has a startup script that doesn't exit).

You could also modify the part the checks for a startup file to run a second file that's automatically deleted like you said, but I think this makes the most sense for what you're trying to do.

#6 Andale

  • Members
  • 46 posts
  • LocationNWIndiana

Posted 27 March 2013 - 07:32 PM

Ok, so like this then?
I'm editing computercraft.zip\lua\rom\programs\shell.
If I save this shell. into the zip file in the mods folder it should beomce this on next server reload from what I'd guess. (I'm not our server owner, but I do a lot of post setup config these days so I'm double checking everything before doing anything.)
I tried to add a couple programs in the zip before, but I can't tell if I was the one who screwed up or my server owner just happened to wipe/replace it on the upgrade the next day.

This is where I put the code: (in spoiler cuz code usually won't color format on most sites)

Spoiler


#7 faubiguy

  • Members
  • 213 posts

Posted 27 March 2013 - 08:05 PM

Yes, that looks right. And I just thought of this, but I'd probably put
term.clear()
term.setCursorPos(1,1)
after the part where it sets the label, so that if the label gets asked for, the prompt and input don't stay on the screen. If you do that, it should go before the lines of code right before it (before the print(os.version()), so that won't get cleared as well.

#8 Andale

  • Members
  • 46 posts
  • LocationNWIndiana

Posted 28 March 2013 - 03:08 AM

ok, in the end i added faubi's suggestion AND I set it to reboot after just to get it to display the name which Iadded as an else to the if not os.getComputerLabel

Ok, I'm gonna save this to the zip and upload it back in to test

term.setBackgroundColor( bgColour )
term.setTextColour( promptColour )
print( os.version() )
term.setTextColour( textColour )


-- ask for a label on any computer without
if not os.getComputerLabel() then
write 'Set a label for this computer: '
os.setComputerLabel(read())
os.reboot()
else
print(os.getComputerLabel())
end

term.clear()
term.setCursorPos(1,1)

-- If this is the toplevel shell

#9 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 28 March 2013 - 03:13 AM

use code tags man...

so why do you reboot the computer exactly? seems unnecessary.

also whats with the "-- If this is the toplevel shell" comment?

#10 faubiguy

  • Members
  • 213 posts

Posted 28 March 2013 - 03:18 AM

What I meant was for the part
if not os.getComputerLabel() then
write 'Set a label for this computer: '
os.setComputerLabel(read())
reboot()
else
print(os.getComputerLabel())
end

term.clear()
term.setCursorPos(1,1)
to go before
term.setBackgroundColor( bgColour )
term.setTextColour( promptColour )
print( os.version() )
term.setTextColour( textColour )
, That way the terminal gets cleared before it prints CraftOS/TurtleOS, so that doesn't get cleared. Either way, the print(os.getComputerLabel()) wouldn't have an effect, because it gets cleared immediately after.


#11 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

Posted 28 March 2013 - 03:18 AM

View PostTheOriginalBIT, on 28 March 2013 - 03:13 AM, said:

also whats with the "-- If this is the toplevel shell" comment?

That's already in the default shell.

#12 Andale

  • Members
  • 46 posts
  • LocationNWIndiana

Posted 28 March 2013 - 03:50 AM

so uploading it into the zip in the /mods/ folder doesn't do it
there's no 'computer' or 'lua' folder in either my base, mods, or worldname folders that contains the programs folder
there is only a folder named computer under worldname (worldname/computer) that contains the current computers and turtles by id number

did my server screw up somehow? where is it getting the default programs from?

#13 Andale

  • Members
  • 46 posts
  • LocationNWIndiana

Posted 28 March 2013 - 03:53 AM

View Postfaubiguy, on 28 March 2013 - 03:18 AM, said:

What I meant was for the part
if not os.getComputerLabel() then
write 'Set a label for this computer: '
os.setComputerLabel(read())
reboot()
else
print(os.getComputerLabel())
end

term.clear()
term.setCursorPos(1,1)
to go before
term.setBackgroundColor( bgColour )
term.setTextColour( promptColour )
print( os.version() )
term.setTextColour( textColour )
, That way the terminal gets cleared before it prints CraftOS/TurtleOS, so that doesn't get cleared. Either way, the print(os.getComputerLabel()) wouldn't have an effect, because it gets cleared immediately after.



my fault, two different thought processes at same time, i'll rearrange the clear later

I left it after os version to show the computer is working, just stopped to do this

I guess if I have the reboot then I don't need the clear at all tho.


wait.... now that I think about it, i went in to test and it did show only the >_ terminal so it did work from the zip file. Ugh... it's too early for me. I'll do this later





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users