Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

[HELP] Cross-script global variables?

1531408767

Edited 1531408890
Missingquery
Pro
Sheet Author
API Scripter
In my Fire Emblem Tabletop Script , for convenience' sake when testing it on my own, I have all the functions divided up separately into different files. Let's say I declare a global variable in one file. var queue = []; Can this variable be accessed from another separate script in some way, or are all scripts sandboxed separately, making that impossible? My goal is to make a global queue that can be accessed from all scripts, though I don't know if that's possible.
Technically all of the API scripts are concatenated with each other. So that Roll20 only sees one javascript file like apiscripts.js . So you could create this global variable in one script and use it in others. I would just recommend that you put this variable in the very first API script in the list to ensure that it is created first and usable in each later script.
1531423202
Missingquery
Pro
Sheet Author
API Scripter
That's weird, though, since if I declare queue on the first line of the first script and try to log it on the first line of the second script, it immediately throws a reference error.
1531425159
The Aaron
Pro
API Scripter
When you say you get an immediate reference error, are you talking about when you put the scripts in roll20, or in something else like a local sandbox for testing or the like?
1531426057
Missingquery
Pro
Sheet Author
API Scripter
In Roll20, that is. It automatically gives me ReferenceError: queue is not defined when I attempt to save, presumably because the scope for error scanning is only limited to the current API script?
How are you defining the variable? Can we see it's code?
1531426220
Missingquery
Pro
Sheet Author
API Scripter
It's literally just Script 1: var queue = []; Script 2: log(queue); That's it.
1531426847

Edited 1531426942
Missingquery
Pro
Sheet Author
API Scripter
Okay, so it seems to have a problem with this when I use a pre-existing game, but I get no such error when I make a new game and type up the exact same thing, which is weird. Edit: Nevermind, the problem solved itself?
Is it possible that the problem occurred because you didn't save the first script before writing the second script?
1531429753
Missingquery
Pro
Sheet Author
API Scripter
That's probably it, yeah. ^^