Sign In Register

How can we help you today?

Start a new topic
Answered

How can I make Visual Studio Code to work with require("moduleName")

I would like to try working on the cloud code on VSC and take advantage of the abilities it has.

But it won't recognize the require("moduleName").

Is there a way to fix that?


Best Answer

Hey Baris, 


You can do the following inside of an Atom Text Editor for AutoComplete: 

In Atom install the 'atom-ternjs' plugin. You can then go to Packages -> Atom TernJS -> Configure Project. When that config is saved it will create a '.tern-project' file. I have attached the tern definitions,  save them into the same location. Edit the .tern-project to add 'autocomplete.gs.json' to the libs section. Then Packages -> Atom TernJS -> Restart server

This allow you to write cloud code with AutoComplete locally. 

@Daniel, yes cloud code can use that setting, it is currently undocumented whilst it is mentioned here in relation to real time scripts and modules.. 

Best Regards, Patrick. 

json

How do I make the autocomplete work with modules?...


Patrick?

Thanks, The GameSparks API autocomplete works, But I can't get autocomplete for modules by using the require("moduleName").

I've added the plugins SpectateModeManager commonjs and requirejs and modules and still nothing, I guess I need to set some .tern-project settings for it right? what exactly do I need to do now?

Answer

Hey Baris, 


You can do the following inside of an Atom Text Editor for AutoComplete: 

In Atom install the 'atom-ternjs' plugin. You can then go to Packages -> Atom TernJS -> Configure Project. When that config is saved it will create a '.tern-project' file. I have attached the tern definitions,  save them into the same location. Edit the .tern-project to add 'autocomplete.gs.json' to the libs section. Then Packages -> Atom TernJS -> Restart server

This allow you to write cloud code with AutoComplete locally. 

@Daniel, yes cloud code can use that setting, it is currently undocumented whilst it is mentioned here in relation to real time scripts and modules.. 

Best Regards, Patrick. 

json

Patrick, does this mean Cloud Code supports CommonJS style require with that option set? Is this documented somewhere?

This is probably a very long shot, but is there a way to have Visual Studio recognise/auto-complete GameSparks Cloud Code API classes and functions?

Hi Eyal, 


Could you try using the commonjs style require here? 


To change the require setting (this is the only current setting) you can place require = commonjs; at the top of your script and then use that style of module acquisition. 


To call the module itself as well as inherent functions you will do the following: 

var theFirstModule = require("ModuleShortCode");

theFirstModule.HelloWorld(); 


We call functions via dot notation. 


Hope this helps, Patrick. 

Login to post a comment