# \[CLOSED\] Converting c# to javascript

**URL:** https://discussions.unity.com/t/closed-converting-c-to-javascript/801568
**Category:** C# & .NET
**Tags:** Scripting
**Created:** [July 24, 2020, 6:40pm UTC](https://discussions.unity.com/t/closed-converting-c-to-javascript/801568 "2020-07-24T18:40:03Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Yuzi1221](https://avatars.discourse-cdn.com/v4/letter/y/eb9ed0/32.png) [@Yuzi1221](https://discussions.unity.com/u/Yuzi1221)
#### Post date: [July 24, 2020, 6:40pm UTC](https://discussions.unity.com/t/closed-converting-c-to-javascript/801568/1 "2020-07-24T18:40:03Z")

</div>

how can I convert this to javascript Im getting errors like insert “;” and expecting “)” and unexpected token “)”

```javascript
#pragma strict

import System.IO;

var express = require("express");
var events = require("events");
var app = express();
var eventer = new events.EventEmmiter();
var comments = [];

function Start () {
   
}

function Update () {

        PlayerData playerdata = new PlayerData();
        playerdata.position = transform.position;

        var json = JsonUtility.ToJson (playerdata);

        Debug.Log (json);

        var path = "Assets/SaveFile.json";
        FileStream filestream = new FileStream (path, FileMode.Create);
        using (StreamWriter writer = new StreamWriter (filestream)) {
            writer.Write (json);
        }
}

```

---

<div class="post-metadata">

### Author: ![Joe-Censored](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/joe-censored/32/419943_2.png) [@Joe-Censored](https://discussions.unity.com/u/Joe-Censored)
#### Post date: [July 24, 2020, 6:40pm UTC](https://discussions.unity.com/t/closed-converting-c-to-javascript/801568/2 "2020-07-24T18:40:55Z")

</div>

That isn’t C# though. Looks like JS already, which Unity doesn’t actually support anymore unless you’re still using 2017.x or one of the early 2018.x versions.

---

<div class="post-metadata">

### Author: ![Yuzi1221](https://avatars.discourse-cdn.com/v4/letter/y/eb9ed0/32.png) [@Yuzi1221](https://discussions.unity.com/u/Yuzi1221)
#### Post date: [July 24, 2020, 6:58pm UTC](https://discussions.unity.com/t/closed-converting-c-to-javascript/801568/3 "2020-07-24T18:58:12Z")

</div>

> [@Joe-Censored](#):
>
> That isn’t C# though. Looks like JS already, which Unity doesn’t actually support anymore unless you’re still using 2017.x or one of the early 2018.x versions.

Yes Im using Unity 2017 and I already tried to convert it into javascript that is the code I came up with but it doesn’t work

---

<div class="post-metadata">

### Author: ![Vryken](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/vryken/32/201459_2.png) [@Vryken](https://discussions.unity.com/u/Vryken)
#### Post date: [July 24, 2020, 7:20pm UTC](https://discussions.unity.com/t/closed-converting-c-to-javascript/801568/4 "2020-07-24T19:20:59Z")

</div>

> [@Yuzi1221](#):
>
> Yes Im using Unity 2017 and I already tried to convert it into javascript that is the code I came up with but it doesn’t work

Again, the code you posted already is JavaScript. There’s no conversion needed, unless you mean you want to convert it to C#.

Are you maybe mixing up these two languages?

Edit:  
Nevermind, I just noticed the C# code syntax inside the Update function.

In JavaScript (more specifically, UnityScript), the types of variables/references are declared after the names. So you’d change this:

```csharp
PlayerData playerData =

```

To this:

```javascript
var playerData: PlayerData =

```

And do the same for the other declarations.

---

<div class="post-metadata">

### Author: ![Yuzi1221](https://avatars.discourse-cdn.com/v4/letter/y/eb9ed0/32.png) [@Yuzi1221](https://discussions.unity.com/u/Yuzi1221)
#### Post date: [July 24, 2020, 11:00pm UTC](https://discussions.unity.com/t/closed-converting-c-to-javascript/801568/5 "2020-07-24T23:00:15Z")

</div>

I fixed everything but this part of the code. It says its missing a semicolon on first line.

```javascript
        var StreamWriter: writer = new StreamWriter (filestream) {
        writer.Write (json);
        }

```

---

<div class="post-metadata">

### Author: ![Vryken](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/vryken/32/201459_2.png) [@Vryken](https://discussions.unity.com/u/Vryken)
#### Post date: [July 24, 2020, 11:20pm UTC](https://discussions.unity.com/t/closed-converting-c-to-javascript/801568/6 "2020-07-24T23:20:51Z")

</div>

> [@Yuzi1221](#):
>
> I fixed everything but this part of the code. It says its missing a semicolon on first line.
> 
> ```javascript
> var StreamWriter: writer = new StreamWriter (filestream) {
> writer.Write (json);
> }
> 
> ```

You can get rid of those curly braces, since the `using` statement is gone:

```javascript
var StreamWriter: writer = new StreamWriter(filestream);
writer.Write(json);

```

It’s worth mentioning though that the purpose of the C# `using` keyword in this context is to free up system resources after closing the file-stream.

I’ve never used UnityScript before, so I don’t know if it has an equivalent to this, or if it just isn’t needed here.
