First of all I want to give my appreciation to what you've done. Having written a backend in node.js myself, I can definitely appreciate gamesparks! This truly is awesome! On the bad side, the documentation lacks. A lot of what I understand I had to get through with help of deduction. I found a tab in cloud code called "modules", which I "feel" can be very helpful to organizing code (similarly to what I used to do in node.js). But I can't find any documentation, I don't really know where to start and how to use. I would assume that it should be different from node.js modules, but I wish there was a documentation there.
I also can't find how can I execute functions during creation of a new player (registration process), I need to get info for the newly registered player and update world data and then send it back.
Best Answer
T
Tech Support
said
over 5 years ago
Hi Dennis
Thanks for the feedback!
We are just in the final stages of our new documentation site, we plan to release this on June 1. This has been driven by customer feedback and we feel the new dos site will go a long way to address what can be done with the platform.
Here is the coy from the new docs site about modules:
Modules allow you to create your own libraries of JavaScript that can be included within other scripts.
This allows you to separate common functionality that needs to be shared between scripts into a single module that can be included.
To include a module within your script use the global require function as follow :
require("MODULE_SHORT_CODE");
Using require, you can load a module into the current execution context. This is not common.js require, but a more basic inclusion pattern, where the loaded module is inlined within the current script.
If you have circular reference between modules, the require method will only load a single module once per require invocation. This is to protect from infinite loops and stack overflows.
You can conditionally require modules based on input parameters etc to have a single script that can perform multiple tasks without having a large script
We are just in the final stages of our new documentation site, we plan to release this on June 1. This has been driven by customer feedback and we feel the new dos site will go a long way to address what can be done with the platform.
Here is the coy from the new docs site about modules:
Modules allow you to create your own libraries of JavaScript that can be included within other scripts.
This allows you to separate common functionality that needs to be shared between scripts into a single module that can be included.
To include a module within your script use the global require function as follow :
require("MODULE_SHORT_CODE");
Using require, you can load a module into the current execution context. This is not common.js require, but a more basic inclusion pattern, where the loaded module is inlined within the current script.
If you have circular reference between modules, the require method will only load a single module once per require invocation. This is to protect from infinite loops and stack overflows.
You can conditionally require modules based on input parameters etc to have a single script that can perform multiple tasks without having a large script
As for getting scripts to execute on player registration, you can bind your script to either RegistrationRequest or RegistrationResponse.
Gabriel
s
some 001
said
about 3 years ago
I tried using exports.functionName = function().. for when there multiple functions in a module, but it keeps saying exports is undefined.
I also tried module.exports, same result.. is there a way we can achieve this ?
Customer Support
said
about 3 years ago
Hi some 001,
I take in the this scenario you're using a module (exports), and wanting to setup and use functions within this module? You can create a function within your module using:
var myFunctionName = function(){}
or
function myFunctionName(){}
You can then invoke these functions in a cloud code script by first requiring the module:
require("exports");
then calling the calling the function as you would if it were local:
myFunctionname();
I hope this helps clarify things for you. If you have any further questions please let us know.
Regards,
Vinnie
1 person likes this
s
some 001
said
about 3 years ago
While this's another way to do it, it is not what I expected from modules.
With this, modules in GS are simply a special type of folded code/code region and cannot be used for exporting functions.
I'm not sure whether require() is pure JavaScript or if it's just a NodeJS thing.
Anyway, thanks Vinnie.
Y
Yehor Novakov
said
about 1 year ago
Hi Vinnie!
I have some troubles with modules. I've created a module "CC_UsersHelpers" and used require("CC_UsersHelpers") is registration request. After that I call a function from module. Though debugger in test harness keep saying that the function is not defined
H
Henrik Larsson
said
10 months ago
"Hi some 001,
I take in the this scenario you're using a module (exports), and
wanting to setup and use functions within this module? You can create a
function within your module using:
var myFunctionName = function(){}
or
function myFunctionName(){}
You can then invoke these functions in a cloud code script by first requiring the module:
require("exports");
then calling the calling the function as you would if it were local:
myFunctionname();
I hope this helps clarify things for you. If you have any further questions please let us know"
Please add this information to the documentation on modules. It doesn't seem to conform to any of the standard ways of exporting and using modules, and it took me a long time to find this thread so I could get my module to work. Thanks!
Dennis Sedov
First of all I want to give my appreciation to what you've done. Having written a backend in node.js myself, I can definitely appreciate gamesparks! This truly is awesome! On the bad side, the documentation lacks. A lot of what I understand I had to get through with help of deduction. I found a tab in cloud code called "modules", which I "feel" can be very helpful to organizing code (similarly to what I used to do in node.js). But I can't find any documentation, I don't really know where to start and how to use. I would assume that it should be different from node.js modules, but I wish there was a documentation there.
I also can't find how can I execute functions during creation of a new player (registration process), I need to get info for the newly registered player and update world data and then send it back.
Hi Dennis
Thanks for the feedback!
We are just in the final stages of our new documentation site, we plan to release this on June 1. This has been driven by customer feedback and we feel the new dos site will go a long way to address what can be done with the platform.
Here is the coy from the new docs site about modules:
Modules allow you to create your own libraries of JavaScript that can be included within other scripts.
This allows you to separate common functionality that needs to be shared between scripts into a single module that can be included.
To include a module within your script use the global require function as follow :
Using require, you can load a module into the current execution context. This is not common.js require, but a more basic inclusion pattern, where the loaded module is inlined within the current script.
If you have circular reference between modules, the require method will only load a single module once per require invocation. This is to protect from infinite loops and stack overflows.
You can conditionally require modules based on input parameters etc to have a single script that can perform multiple tasks without having a large script
As for getting scripts to execute on player registration, you can bind your script to either RegistrationRequest or RegistrationResponse.
Gabriel
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstTech Support
Hi Dennis
Thanks for the feedback!
We are just in the final stages of our new documentation site, we plan to release this on June 1. This has been driven by customer feedback and we feel the new dos site will go a long way to address what can be done with the platform.
Here is the coy from the new docs site about modules:
Modules allow you to create your own libraries of JavaScript that can be included within other scripts.
This allows you to separate common functionality that needs to be shared between scripts into a single module that can be included.
To include a module within your script use the global require function as follow :
Using require, you can load a module into the current execution context. This is not common.js require, but a more basic inclusion pattern, where the loaded module is inlined within the current script.
If you have circular reference between modules, the require method will only load a single module once per require invocation. This is to protect from infinite loops and stack overflows.
You can conditionally require modules based on input parameters etc to have a single script that can perform multiple tasks without having a large script
As for getting scripts to execute on player registration, you can bind your script to either RegistrationRequest or RegistrationResponse.
Gabriel
some 001
I tried using exports.functionName = function().. for when there multiple functions in a module, but it keeps saying exports is undefined.
I also tried module.exports, same result.. is there a way we can achieve this ?
Customer Support
Hi some 001,
I take in the this scenario you're using a module (exports), and wanting to setup and use functions within this module? You can create a function within your module using:
var myFunctionName = function(){}
or
function myFunctionName(){}
You can then invoke these functions in a cloud code script by first requiring the module:
require("exports");
then calling the calling the function as you would if it were local:
myFunctionname();
I hope this helps clarify things for you. If you have any further questions please let us know.
Regards,
Vinnie
1 person likes this
some 001
While this's another way to do it, it is not what I expected from modules.
With this, modules in GS are simply a special type of folded code/code region and cannot be used for exporting functions.
I'm not sure whether require() is pure JavaScript or if it's just a NodeJS thing.
Anyway, thanks Vinnie.
Yehor Novakov
Hi Vinnie!
I have some troubles with modules. I've created a module "CC_UsersHelpers" and used require("CC_UsersHelpers") is registration request. After that I call a function from module. Though debugger in test harness keep saying that the function is not defined
Henrik Larsson
"Hi some 001,
I take in the this scenario you're using a module (exports), and wanting to setup and use functions within this module? You can create a function within your module using:
var myFunctionName = function(){}
or
function myFunctionName(){}
You can then invoke these functions in a cloud code script by first requiring the module:
require("exports");
then calling the calling the function as you would if it were local:
myFunctionname();
I hope this helps clarify things for you. If you have any further questions please let us know"
Please add this information to the documentation on modules. It doesn't seem to conform to any of the standard ways of exporting and using modules, and it took me a long time to find this thread so I could get my module to work. Thanks!
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2476 topics