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

Program for Loading a "Game Cartridge" off of a Disk Drive

Started by Mr. Fang, 20 September 2012 - 01:48 PM
Mr. Fang #1
Posted 20 September 2012 - 03:48 PM
The following is a code I designed for my FangCo. Computer Company. My "company" on the server I play on sells Home Computers with multiple abilities and applications. That said, I decided to make up some games that could be popped in and played.
*Notice*
I named the File "Disk" because the user will type Disk in the Computer's Menu and that will load the startup from the disk.(Not Restarting the computer!)
I understand that restarting the computer will load the startup from the disk anyways, but I don't want my disks to be accessible to every computer… only the people who have knowledge of Computecraft could possibly figure out how to hack into a game…
That said, here's the coding:

term.clear()	--Clears the Screen
term.setCursorPos(1,1) --Sets the Cursor at the Beginning
print("Is there a disk in the Disk Drive?") -- Asks whether there is a disk in the drive
print("Yes/No")
local pass = "Yes"
local stop = "No"
read()
if input == pass then
term.clear()
term.setCursorPos(1,1)
print("Starting Disk Drive") --aesthetics/progress (Has to look pleasing for a user/consumer of my fangco. computer
sleep(1)
print("Loading Disk") --Same as above
sleep(1)
print("Starting Application") --Same as above
sleep(1)
shell.run("disk/diskmenu") --starts up the Menu file on the disk (make one with the game on the disk)
end
if input == stop then
shell.run("Exit") -- A program that just sends the user back to the Computer Menu (A program that I made)
end


Please keep in mind that this is untested and made in less than 15 minutes.(Any problems? Put it in the comments!) It contains 2 files you may not have on your game and also contains some pleasing aesthetic features meant only to notify/please the user of this program.

I'm fairly new to coding the "if then" stuff so i just based mine off of a Door Lock that had passcodes and usernames :)/>/>
Enjoy the Free Code!
Mtdj2 #2
Posted 20 September 2012 - 04:08 PM
Well, the code works. I am certain. You could shorten it here:

shell.run("disk/diskmenu")
end
if input == stop then
edited piece:

shell.run("disk/diskmenu")
elseif input == stop then
Would look better to people who knows to lua.
And, dont say "local pass = 'Yes'", just make "if input == 'Yes' then".
Finally, define input: "local input = read()". I dont know if input just automatically appears, im not sure.

Hope i helped.
Mr. Fang #3
Posted 20 September 2012 - 04:31 PM
Thank you for your help, I already informed you in this thread that I know most of my knowledge from Door Locks, and the idea that this was a "passcode" was much easier to work with.

Thanx again for your helping, I'm not likely to fix the code unless anything damages the program's ability to work.
Cranium #4
Posted 20 September 2012 - 04:49 PM
If you are concerned about aesthetics, you might want to look into Liraal's Quick Guide to Menu Making. It really helps. I use much of his advice in many of my menu systems. Other than that, it looks really good.
Mr. Fang #5
Posted 20 September 2012 - 04:51 PM
Thank You, I'll be sure to check that out, I'm really into making an awesome interface for my CPU
MysticT #6
Posted 20 September 2012 - 05:39 PM
I'm not likely to fix the code unless anything damages the program's ability to work.
Well, it won't work like that. If you don't define the "input" variable it doesn't just magically apear, so instead of:

read()
use (as Mtdj2 said):

local input = read()
Mr. Fang #7
Posted 20 September 2012 - 10:54 PM
Oh I didn't know that affected it sorry. He didn't seem very convincing lol.
Mtdj2 #8
Posted 25 September 2012 - 04:41 PM
:P/>/>
Mr. Fang #9
Posted 27 September 2012 - 03:48 PM
Well you did say that I "could" not that I "should" shorten it there.
djm1999 #10
Posted 02 November 2012 - 08:28 AM
im confused, it not want to work for me
BigSHinyToys #11
Posted 02 November 2012 - 08:58 AM
you could use a for i,v in pairs on rs.getSides() and test peripheral.isPresent() and then peripherial.getType() after that check for a disk with disk.isPresent() and disk.hasData() then use fs.exists("startup") and print disk on "left" side run program Y/N

would be a bit more complex but would make user operation simpler.