# What order are custom files run in javascript?

**URL:** https://forum.makecode.com/t/what-order-are-custom-files-run-in-javascript/45680
**Category:** Help
**Created:** [September 2, 2026, 12:52am UTC](https://forum.makecode.com/t/what-order-are-custom-files-run-in-javascript/45680 "2026-09-02T00:52:02Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![ScriptScraper](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/scriptscraper/32/35438_2.png) [@ScriptScraper](https://forum.makecode.com/u/ScriptScraper)
#### Post date: [September 2, 2026, 12:52am UTC](https://forum.makecode.com/t/what-order-are-custom-files-run-in-javascript/45680/1 "2026-09-02T00:52:03Z")

</div>

I recently figured out that you can make custom files in javascript, meaning you can organize your code! However, I don’t really know what the order they’re run in, is it main.ts first, last, or all at the same time? When I define functions in either main.ts or a custom file, they can be used anywhere, so I’m kinda confused. @richard

---

<div class="post-metadata">

### Author: ![VoxelMaster64](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/voxelmaster64/32/32075_2.png) [@VoxelMaster64](https://forum.makecode.com/u/VoxelMaster64)
#### Post date: [September 2, 2026, 1:45am UTC](https://forum.makecode.com/t/what-order-are-custom-files-run-in-javascript/45680/2 "2026-09-02T01:45:05Z")

</div>

I think it’s the order you create them OR alphabeticaly, but you can check by opening “pxt.json” (is that what is called? It’s below assets.json), pressing “edit settings as text”, and the files shown somewhere are compiled top to bottom. (I wrote that from memory so it may not be accurate.) WARNING, create a duplicate of your project BEFORE opening pxt.json, incase it corrupts your project

NOTE: use an init function rather than changing pxt.json if its the compiling order your worrying about (my voxel engine has an init function, in main.ts I think it’s `initVar()`, the definition is in `vars.ts`)

---

<div class="post-metadata">

### Author: ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)
#### Post date: [September 2, 2026, 2:07am UTC](https://forum.makecode.com/t/what-order-are-custom-files-run-in-javascript/45680/3 "2026-09-02T02:07:21Z")

</div>

They’re run in alphabetical order except for `main.ts`, which always runs last.

---

<div class="post-metadata">

### Author: ![TheEarth](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/theearth/32/34579_2.png) [@TheEarth](https://forum.makecode.com/u/TheEarth)
#### Post date: [September 2, 2026, 2:07am UTC](https://forum.makecode.com/t/what-order-are-custom-files-run-in-javascript/45680/4 "2026-09-02T02:07:32Z")

</div>

I’m 75 percent sure it’s alphabetically expect for main .ts which run a last

---

<div class="post-metadata">

### Author: ![ScriptScraper](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/scriptscraper/32/35438_2.png) [@ScriptScraper](https://forum.makecode.com/u/ScriptScraper)
#### Post date: [September 2, 2026, 2:32am UTC](https://forum.makecode.com/t/what-order-are-custom-files-run-in-javascript/45680/5 "2026-09-02T02:32:23Z")

</div>

Then why is a function defined in main.ts able to be used in other custom files?

---

<div class="post-metadata">

### Author: ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)
#### Post date: [September 2, 2026, 5:10pm UTC](https://forum.makecode.com/t/what-order-are-custom-files-run-in-javascript/45680/6 "2026-09-02T17:10:51Z")

</div>

It depends on when the function is called. Typcally, the only time this would pose a problem is if a function in `main.ts` is called in the equivalent of an `on start` block in a different file. If the function is called within another function, then `main.ts` would be read and interpreted before the function is called.

---

<div class="post-metadata">

### Author: ![teaeat100](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/teaeat100/32/33097_2.png) [@teaeat100](https://forum.makecode.com/u/teaeat100)
#### Post date: [September 2, 2026, 6:48pm UTC](https://forum.makecode.com/t/what-order-are-custom-files-run-in-javascript/45680/7 "2026-09-02T18:48:54Z")

</div>

you can??? dang that’s useful, where did you see this???

---

<div class="post-metadata">

### Author: ![VoxelMaster64](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/voxelmaster64/32/32075_2.png) [@VoxelMaster64](https://forum.makecode.com/u/VoxelMaster64)
#### Post date: [September 2, 2026, 9:43pm UTC](https://forum.makecode.com/t/what-order-are-custom-files-run-in-javascript/45680/8 "2026-09-02T21:43:54Z")

</div>

do this:

```typescript
myFunc() // call BEFORE declaration bc why not

function myFunc() {
    console.log(":)")
}

```

It works, and that is basically what happens with 2 different files

---

<div class="post-metadata">

### Author: ![ScriptScraper](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/scriptscraper/32/35438_2.png) [@ScriptScraper](https://forum.makecode.com/u/ScriptScraper)
#### Post date: [September 3, 2026, 2:08am UTC](https://forum.makecode.com/t/what-order-are-custom-files-run-in-javascript/45680/9 "2026-09-03T02:08:22Z")

</div>

I was just curious what the “plus” button in the explorer did, so I pressed it, and it creates a new custom file

---

<div class="post-metadata">

### Author: ![teaeat100](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/teaeat100/32/33097_2.png) [@teaeat100](https://forum.makecode.com/u/teaeat100)
#### Post date: [September 3, 2026, 6:16pm UTC](https://forum.makecode.com/t/what-order-are-custom-files-run-in-javascript/45680/10 "2026-09-03T18:16:54Z")

</div>

So _that’s_ what it’s meant for!

---

<div class="post-metadata">

### Author: ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)
#### Post date: [September 3, 2026, 6:20pm UTC](https://forum.makecode.com/t/what-order-are-custom-files-run-in-javascript/45680/11 "2026-09-03T18:20:53Z")

</div>

@AlexK @ScriptScraper actually, they run based on the order of the entries of the files array in `pxt.json` (except for `main.ts` which always runs last). so not alphabetical order

---

<div class="post-metadata">

### Author: ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)
#### Post date: [September 3, 2026, 8:47pm UTC](https://forum.makecode.com/t/what-order-are-custom-files-run-in-javascript/45680/12 "2026-09-03T20:47:44Z")

</div>

Ooh … now _that’s_ an interesting prospect … and now I have questions. 😆

Here’s an example: The current state of the `files` array in my ever-evolving Monopoly project.

```json
{
    "files": [
        "main.ts",
        "README.md",
        "enums.ts",
        "attract.ts",
        "controller.ts",
        "images.g.jres",
        "images.g.ts",
        "settings.ts",
        "avatars.ts",
        "players.ts",
        "dice.ts",
        "firstroll.ts",
        "state.ts",
        "pausemenu.ts",
        "board.ts",
        "background.ts",
        "tests.ts",
        "properties.ts",
        "cards.ts",
        "taxes.ts",
        "strings.ts",
        "actionmenus.ts",
        "actionqueue.ts",
        "tutorial.ts"
    ],
}

```

It looks, more or less, like the order in which I created the files. Does the editor ever tinker with the order of the `files` array? If I needed to create a dependency where one file needs to load before another, would this be a “set it and forget it” scenario, or would I need to check `pxt.json` every time I added or deleted a file in the editor to make sure the ordering was “correct?”

---

<div class="post-metadata">

### Author: ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)
#### Post date: [September 3, 2026, 8:56pm UTC](https://forum.makecode.com/t/what-order-are-custom-files-run-in-javascript/45680/13 "2026-09-03T20:56:45Z")

</div>

i don’t think we ever re-order things. i’m guessing removing a file is just a filter operation

---

<div class="post-metadata">

### Author: ![ScriptScraper](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/scriptscraper/32/35438_2.png) [@ScriptScraper](https://forum.makecode.com/u/ScriptScraper)
#### Post date: [September 3, 2026, 9:20pm UTC](https://forum.makecode.com/t/what-order-are-custom-files-run-in-javascript/45680/14 "2026-09-03T21:20:38Z")

</div>

wdym? does this mean the order you created them?

---

<div class="post-metadata">

### Author: ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)
#### Post date: [September 3, 2026, 9:22pm UTC](https://forum.makecode.com/t/what-order-are-custom-files-run-in-javascript/45680/15 "2026-09-03T21:22:00Z")

</div>

yes, in general it will be the order you created them unless you manually change the order in pxt.json.

i think the only files that we ever insert outside of the normal order are the generated .g.ts and .g.jres files
