-
Notifications
You must be signed in to change notification settings - Fork 251
Document how to use startup files #1069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Lupus590
wants to merge
16
commits into
cc-tweaked:mc-1.20.x
Choose a base branch
from
Lupus590-CC:docs/startup_files
base: mc-1.20.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
190c7c0
document how to use startup files
Lupus590 89899f0
fix typo
Lupus590 f393528
fix typos
Lupus590 cd6fd8e
fix another typo
Lupus590 ae48f5d
Changes suggested by grammerly
Lupus590 3823202
turns on instead of boots
Lupus590 71409fa
Merge branch 'mc-1.16.x' of https://github.com/SquidDev-CC/CC-Tweaked…
Lupus590 48fcd70
Merge branch 'mc-1.16.x' of https://github.com/SquidDev-CC/CC-Tweaked…
Lupus590 8eb463b
Merge branch 'mc-1.16.x' of https://github.com/SquidDev-CC/CC-Tweaked…
Lupus590 19e2afc
Move case sensitivity to fs api page
Lupus590 f583df3
add missing note header
Lupus590 f835bb7
Move persistence stuff
Lupus590 67706cf
reword a bit
Lupus590 e43314d
move mass config to top
Lupus590 1d5463d
Merge branch 'mc-1.16.x' of https://github.com/SquidDev-CC/CC-Tweaked…
Lupus590 8d3e1c5
Merge branch 'mc-1.20.x' into docs/startup_files
Lupus590 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| --- | ||
| module: [kind=guide] startup_files | ||
| --- | ||
|
|
||
| # Running code when a computer boots | ||
|
|
||
| :::note Use case | ||
| You might be aware that CC computers restart when the chunk they are in reloads, one of the uses of startup files provides a way to have the CC computer run arbitrary code after it has finished turning on. Currently, this is the closest that CC has to persistence built-in. | ||
| ::: | ||
|
|
||
| CC computers will look for a file or folder with a special name when it finishes loading. Also, CC has a fixed order in which it looks for these files and uses them. | ||
Lupus590 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## The magic names | ||
| All startup *files* have to be at the root of their drive, this drive is commonly the computer's internal storage, but can be a disk too. | ||
| ``` | ||
| startup | ||
| startup.lua | ||
| ``` | ||
| `startup` may be a file or a folder, the behaviour of it changes depending on which it is but we'll cover that in a bit. `startup.lua` has to be a file. | ||
Lupus590 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| :::note Case sensitivity | ||
| Startup file names are all lowercase. | ||
|
|
||
| CC inherits the case sensitivity of the real world OS that the Minecraft server is running on, so if you are used to Microsoft Windows' case insensitivity (e.g. `startup.lua` and `StartUp.Lua` are considered the same when used as file names) and play on a server (which will likely be running Linux which is case sensitive) then you should keep in mind that programs which work on your machine in singleplayer may not work correctly on the server if you are inconsistent with the case that you use for file names. | ||
|
|
||
| To reiterate, startup file names are all lowercase. CC is looking for `startup` and `startup.lua` not `Startup` or any other capitalisations. | ||
| ::: | ||
Lupus590 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Searching drives for startup files | ||
| If `shell.allow_disk_startup` is true (which it is by default), then the CC computer will look for disk drives that have at least one startup file, it only uses the first disk that fulfils these criteria. Disk drives are searched in the order they are found via `peripheral.getNames()`. It then runs the found startup files as described below. | ||
|
|
||
| If `shell.allow_startup` is true (which it is by default) and no disk startup file was used, then the computer will look for startup files in its internal storage. Valid files are run as described below. | ||
|
|
||
| ### Running the startup files | ||
| If `startup` is a file then this file and *only* this file is run, even if a `startup.lua` exists on the same device. | ||
|
|
||
| If `startup` is not a file (either it's a folder or it doesn't exist) then `startup.lua` is run, assuming it exists. After running `startup.lua` (or not if it didn't exist), the CC computer then runs each file in the `startup` folder one after the other in the order that @{fs.list} returns them. | ||
|
|
||
| :::note Example | ||
| Let's say that I have a computer with a startup file on its internal storage, and is connected to six disk drives. Two of these drives have disks that have startup files, one has a disk with no files, one with files but none of them are startup files, one has a music disk (the kind that you can place in a jukebox), the remaining drive has no disk in it. | ||
|
|
||
| Both of the settings that affect startup are set to allow their respective startup modes. | ||
|
|
||
| I turn on my computer, it looks for disk drives. It so happens that the first one it finds is the empty one, since this drive has no disk it goes to the next drive it found. The second drive that it searches for startup files is the jukebox music disk, this one is also skipped as music disks don't have startup files. Third, it finds the disk drive containing the disk without files, it goes to the next drive. Forth is the disk with files but without startup files, it tries the next disk. | ||
|
|
||
| We are down to the two disks both with startup files, the computer finds one of them and searches it for startup files, it finds the files and runs them in the order above. When/if these startup files exit without shutting down the computer then the CC computer drops into the interactive prompt. The computer *didn't* look at the last disk drive and *didn't* use the startup files on its internal storage. | ||
| ::: | ||
|
|
||
| :::note Mass configuration | ||
| Unless disabled in the server config, CC computers will look for startup files on disks in attached disk drives. This means that a freshly crafted computer can automatically load a program from that disk startup file. | ||
|
|
||
| Apply this to turtles with a nearby chest containing fuel and you can have a turtle factory that automatically programs the turtles after creating them. | ||
| ::: | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.