question

zomb avatar image
zomb asked

Cloudscript and Visual studio intellisense

Is there any way to get context help intellisense about server API methods in Visual studio while editing javascript of cloudscript? I edited cloudscript in same c# unity project as client. Is any better, more comfortable way?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Joshua Strunk avatar image
Joshua Strunk answered

Is there any way to get context help intellisense about server API methods in Visual studio while editing javascript of cloudscript?

Yes

I edited cloudscript in same c# unity project as client. Is any better, more comfortable way?

I would certainly consider moving you Cloud Script source out into a separate project or folder. This would provide better separation of concerns when working on your project.

-----

Good news, there are tools and methods available that get you powerful tooling features when authoring Cloud Script. The method I am most familiar with and that has the most support from PlayFab is to author your Cloud Script source using TypeScript and then transpile it into JavaScript using the TypeScript compiler.

I am not familiar with getting a TypeScript development environment setup for Visual Studio, so I will post some helpful links and a process for getting started in Visual Studio Code.

-----

A mostly raw Copy/Paste of process I gave on the community slack today. It is a massive, poorly written dump of words, if you are confused on any part of it, feel free to post questions here or message me on the community slack.


Making the switch to TypeScript is not a hard process(certainly not harder than debugging untyped code). The hardest part of the switch is getting setup and fixing all the errors TypeScript catches when you start using it.

First off I recommend using Visual Studio Code. It is developed in TypeScript, backed by Microsoft, and has TS support built in.


Atom is a great editor but the primary TS plugin for it has been pretty much abandoned by its primary maintainer.

Unlike the atom plugin VSCode stops short of letting you use its built in TSC compiler, so you are going to need get a copy.

You will need node/npm for this, so if you already have them great if not, https://nodejs.org/en/

Now you ready to get the compiler.
http://www.typescriptlang.org/docs/tutorial.html


I recommend you just mess around with the compiler first before worrying about compiling your Cloud Script project.

Once your comfortable with just the compiler, if you have not gotten VSCode yet go ahead and get it. https://code.visualstudio.com/

You can then follow the instructions here https://code.visualstudio.com/Docs/languages/typescript to see some of the features VSCode offers as well as to setup the taskrunner.

If your feeling comfortable with all of the above, it is time to move onto porting your project. The first step to this is *not* changing all your .js -> .ts or getting the cloudscript.d.ts file. Instead first try and just get all your .js files running through TSC and compiling into a single main.js file

To do this your going to need to change outDir to outFile in your tsconfig.json. `"outFile": "../distr/main.js",` for example


Go ahead and look over that outFile to make sure you don't notice any major issues.

If all of the above is working, it is now time to "port your project"

Change all your files from .js => .ts and grab the cloudscript.d.ts from https://github.com/PlayFab/SdkTestingCloudScript/blob/master/src/typings/CloudScript.d.ts

Now try compiling the project, check out any of the type errors you will most likely start seeing. Once they are all cleaned up your read to keep on working as you were before the migration, however I highly recommend you start making some basic TS changes to your project as you continue to work on it.

  1. Dump var in exchange for let. let is blocked scope, var is not, if you have used any other language let behaves how you would have expected var to. https://basarat.gitbooks.io/typescript/content/docs/let.html
  2. Type your function variables. (This includes your args that get passed into your handlers, I find interfaces the easiest way to type these)
  3. Type the key/values you parse from UserData, CharacterData,ItemData, etc.. `let characterBaseInfo:IBaseCharInfo = JSON.string(CharacterRead["baseInfo"].value)` *sorry that does not line up to the actual CharRead value type just trying to make the point.
  4. Just as you can type the key/values you parse from PlayFab you can type the key/values you are going to update, start doing it.
  5. I tend to favor interfaces > classes, your mileage may vary.
3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1807605288 avatar image 1807605288 ♦ commented ·

This guide is awesome.

If you want a PlayFab Visual Studio CloudScript+TypeScript example project, look here:

https://github.com/PlayFab/SdkTestingCloudScript

We'll be improving it over the next week as well (Jan 30-Feb 3)

1 Like 1 ·
zomb avatar image zomb commented ·

Wow, thank you. I will try it.

0 Likes 0 ·
Wu avatar image Wu commented ·

Awesome dude, thank you very much

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.