Context Free Grammar for all. For all?

I have no business monkeying around with Javascript. And yet I am.

Can someone please explain to me, why my two .js files are not communicating?

My tracery script says ‘tracery is not defined’. It is defined in a separate .js file.

<!-- import the webpage's stylesheet -->
<link rel="stylesheet" href="/style.css" />

<!-- import jquery because tracery needs it -->
<script src=""></script>

<!-- import tracery -->
<script src="/tracery.js"></script>

<!-- import the webpage's javascript file -->
<script src="/script.js"></script>

it has to be defined before its called. try loading your scripts in a different order, or mabey tell us the project so we can take a look

1 Like

Try adding load listener in your .js files:

window.addEventListener('load', () => {
1 Like

Hey! I love Tracery! It’s awesome to hear about someone else using it.

I made this using Tracery:!/sims-patch-notes

It might help if you link your project?

If it’s just the linter (the red circles beside lines of code) that is complaining, you can do
“/* globals tracery */” at the top of the file that is complaining to tell it that it’s gonna be defined - the linter doesn’t really matter, though it is nice to be able to turn it off. The problem is that the linter only “sees” a single file, and so it doesn’t know about the definition of tracery in the other file that will flow down to the script.js file.

Hope this helps!


Thanks so much for your help people. :+1:
WilsontheWolf Yeah I thought it was the load order, but still not certain
@jarvis394 That looks very useful, I’ll try it out (presumably it is an envelope for all of the script in a file?)
@Johnicholas Glad to meet another tracery fan. I’m basically learning to code because I’m EXCITED about playing with proc gen text. I think you are probably right that this is just the linter and I will try the globals thing asap. I will also have a good look at your code to see if i can copy the important bits

I’ll let you all know how I get on.

Here is my project:

What a friendly community!

1 Like

Quick update for anyone who is interested.

I have tested and found that @Johnicholas is right, it is not the load order that is the problem, the function can be defined in one file and called in another, but Glitch still flags it as an undefined function.

Therefore, Tracery is not doing what I expect it to do because my script for writing and outputting a grammar is wrong, which is a subject for another thread.


1 Like

Thanks for the update!

1 Like

Yay it works! Here is my starter for a tracery project in glitch, thanks for all your help.