#Scripts cannot be found

19 messages · Page 1 of 1 (latest)

vague schooner
#

Hello, I'm trying to figure out why some scripts cannot be found. On the left of the screenshots, you can see the file layout. The file "recipeManager.js" should function as the entrypoint, from which I call all other functions. Ingame, I get an error, that "materiallines" is not defined.

serene frigateBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

plucky scarab
#

The script with // priority: 11 runs BEFORE script with // priority: 10

vague schooner
#

I tried reverse prios already xD

plucky scarab
#

That means, that in the first script, definition for init function is not there yet.

#

Also, it seems like you miss the conception of how the scripts load in the first place

#

Simplified: The scripts of the same type are "joined together" in order of their priority, from highest to lowest

#

Looking at the example script in the folder, it seems you think that's a "module". Nope, it's not

vague schooner
#

well, then I certainly missed the conception 😂

plucky scarab
#

I'll show you how it's supposed to be done in a second

#

One way is to have an object in global scope (a "module") containing functions:

// priority: 100
const MaterialLines = {
  initCopperLine(event) {
    // stuff for the copper line
  },
  initIronLine(event) {
    // stuff for the iron line
  },
  initTinLine(event) {
    // stuff for the tin line
  },
  initNickelLine(event) {
    // stuff for the nickel line
  },
}
#

But then you have all lines in one file

vague schooner
#

exactly :3

plucky scarab
#

So, you want them in separate files?

vague schooner
#

yes

plucky scarab
#

Then:

  • Have one file with highest priority, that will initialize the object in the global scope as a "namespace":
// file: materiallines.js

// priority: 100
// Init the object, which is the main module
const MaterialLines = {}

Then create scripts for your lines, with priority lower than the object initialization, but higher than the rest of your script that will initialize the inner objects ("namespaces"):

// file: materiallines/copper.js

// priority: 99
MaterialLines.copper = {
  init(event) {
    // stuff for copper line
  }
}

Do this for every line, and then your example should work if you call:

// No priority header, so "0" by default

ServerEvents.recipes(event => {
  MaterialLines.copper.init(event)
})
vague schooner
#

alright, so I wasn't too far off 😂

#

thank you, I'll adapt and test :3

vague schooner
#

seems to work. tysm :3