Sign In Register

How can we help you today?

Start a new topic

cloud code auto completion problem.

I'm used to C# so I'm trying to add typed objects feeling to my code just to make it more organized ( I know js don't have types... ).


so when I have an object that always has the same structure in the code, I'm declaring it like that in a module:


//object comment,.

function MyObject()

{

   //variable comment.,

    this.variable = 1;

}


so when I'm doing this:

var myObject = new MyObject();


I get autocomplete to all its variables and I also can see all of the comments.

This way I get less typo mistakes and more organized code.


the problem appears when passing the object into functions like so:


foo(myObject );


function foo(object)

{

    here I'm losing all the autocomplete and comments like it is some random object.

    even though when I hover with my mouse on the object parameter in the function it will say (type: MyObject).

}


I've tried the same thing with visual studio and it kept this functionality.


Is there any way to fix it in the cloud code editor too?


And I don't want to use external programs to edit and import back and forth this is a really bad solution since I dont have all the basic GameSparks system auto-completion and comments.


I'm only exporting the code to my computer so I can search for keywords all over the project and not only in one script. 

(Which would be  great if I could do it in the cloud code editor itself).


1 Comment

The current cloud code editor (Ace Editor) understands javascript type hinting, by using JSDoc syntax.

You do this in the following format:

 

 

Js

/**
 * Return the team of the given type, that is associated with the specified player
 * @param {SparkPlayer} player    The player to fetch the team from
 * @param {string} type                 The short code for the type of team to fetch
 * @returns {SparkTeam}               The relevant team object, or null if none is found
 */
function GetPlayerTeam(player, type){

  // ... implement logic here ...

 return team;
}


You can learn more about JSDoc here.

Login to post a comment