Most of the forum post about modules are from atleast 2 years ago. Do modules still function as the existing posts suggest?
I am assuming that after the require, everything inside the module should be immediately available inline
I am simply trying to do:
require("testModule");
var x = testFunction();
inside the module named testModule is a function
function testFunction() {
return 1;
}
I keep getting the reference error testFunction is not defined
Best Answer
T
Tech Support
said
about 4 years ago
Hi Jaayden,
You can't call a function inside a module from the main script because by the time the module finished processing it doesn't exist anymore. When the require function is called the module runs its script and will return any variables made/changed during its run. The module isn't a header/dependency included into the script but rather a piece of code agnostic to the main script.
You can't call a function inside a module from the main script because by the time the module finished processing it doesn't exist anymore. When the require function is called the module runs its script and will return any variables made/changed during its run. The module isn't a header/dependency included into the script but rather a piece of code agnostic to the main script.
Hope this sheds more light on the matter,
Omar
Tech Support
said
about 4 years ago
To be clear, the module shares the same data with the main script. So global variables made in the main script are identifiable by the module:
main script:
var example = "String"
module:
var foo = example;
Foo will have the same value as example because the main script and module share the data together. Think of it as a continuation.
J
James Eisenhower
said
almost 4 years ago
Could I add for example three.js or another physics engine to GameSparks as a module?
Jaayden Halko
Most of the forum post about modules are from atleast 2 years ago. Do modules still function as the existing posts suggest?
I am assuming that after the require, everything inside the module should be immediately available inline
I am simply trying to do:
require("testModule");
var x = testFunction();
inside the module named testModule is a function
function testFunction() {
return 1;
}
I keep getting the reference error testFunction is not defined
Hi Jaayden,
You can't call a function inside a module from the main script because by the time the module finished processing it doesn't exist anymore. When the require function is called the module runs its script and will return any variables made/changed during its run. The module isn't a header/dependency included into the script but rather a piece of code agnostic to the main script.
Hope this sheds more light on the matter,
Omar
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstTech Support
Hi Jaayden,
You can't call a function inside a module from the main script because by the time the module finished processing it doesn't exist anymore. When the require function is called the module runs its script and will return any variables made/changed during its run. The module isn't a header/dependency included into the script but rather a piece of code agnostic to the main script.
Hope this sheds more light on the matter,
Omar
Tech Support
To be clear, the module shares the same data with the main script. So global variables made in the main script are identifiable by the module:
main script:
var example = "String"
module:
var foo = example;
Foo will have the same value as example because the main script and module share the data together. Think of it as a continuation.
James Eisenhower
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2485 topics