Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Kotauskas · Mar 31, 2017 at 12:50 PM · unity 5javascriptfiles

Unity 5 returns strange errors when compiling JavaScript code

Hello! Please help! I have successfully made a level with a Terrain, a Rigidbody FPS Controller from Standard Assets -> Characters and some other GameObjects. I needed a saving system - so I have started to google file implementations in JavaScript. I have found some examples - but it returns compiler errors!

OS is Windows 10 64-bit. Unity version is 5.5.1f1 64-bit. Code editor is Visual Studio 2015, line endings corrected to Windows line endings. Language is JavaScript (UnityScript). Code I have used:

 #pragma strict
 
 import System;
 import System.IO;
 
 var Filename : String = "save.ini";
 private var rwfile;
 
 var x;
 var y;
 var z;

 var Player : GameObject;

 private var startTime : int;
 private var timer1 : int;
 
 function TimerSet() {startTime = Time.time;}
 
 function TimerUpdate() {
     timer1 = Time.time;
     if(timer1 > 60) {
         Debug.Log("Saving");
         Write();
         TimerSet();}}

 function WriterSetup() {
     Debug.Log("File Writer setup...");
     if (!File.Exists(Filename)) {
         rwfile = File.CreateText(Filename);}
     rwfile = OpenText(Filename);
     Debug.Log("File Writer configured sucsessfully");}
 
 function Write() {
     rwfile.open("w");
     x = Player.transform.position.x;
     y = Player.transform.position.y;
     z = Player.transform.position.z;
     rwfile.WriteLine(x);
     rwfile.WriteLine(y);
     rwfile.WriteLine(z);
     rwfile.close();}
 
 function Start() {Debug.Log("Saver Script Setup");
     WriterSetup();
     TimerSet();}
 
 function Update () {TimerUpdate();}

Click here to see my compiling errors in a bigger size

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hexagonius · Mar 31, 2017 at 01:07 PM 1
Share

fixing just this won't get you anywhere because the next problem will come, trust me. just don't piggyback on some code and let others fix it for you. use working code, contact the creator, or write it yourself.

avatar image Kotauskas hexagonius · Mar 31, 2017 at 01:34 PM 0
Share

I have wrote it myself, I have just used some functions from examples. Also I didn't find some already working code.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Kotauskas · Apr 02, 2017 at 12:10 PM

I have already solved this on Stack Overflow, thanks CNuts! Full working code:

 #pragma strict
 
 import System;
 import System.IO;
 
 var Filename : String = "save.ini";
 private var rwfile : StreamWriter;
 var x;
 var y;
 var z;
 var Player : GameObject;
 
 private var startTime : int;
 private var timer1 : int;
 
 function TimerSet() {startTime = Time.time;}
 
 function TimerUpdate() {
     timer1 = Time.time;
     if(timer1 > 60) {
         Debug.Log("Saving");
         Write();
         TimerSet();}}
 
 function WriterSetup() {
     Debug.Log("File Writer setup...");
     if (!File.Exists(Filename)) {
         rwfile = File.CreateText(Filename);}
     Debug.Log("File Writer configured sucsessfully");}
 
 function Write() {
     rwfile = File.CreateText(Filename);
     x = Player.transform.position.x;
     y = Player.transform.position.y;
     z = Player.transform.position.z;
     rwfile.WriteLine(x);
     rwfile.WriteLine(y);
     rwfile.WriteLine(z);
     rwfile.Close();}
 
 function Start() {Debug.Log("Saver Script Setup");
     WriterSetup();
     TimerSet();}
 
 function Update() {TimerUpdate();}


Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

176 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

What's wrong with my script? 2 Answers

Pause Menu Not Going Away 1 Answer

Why cant I create a unity project if I have the newest version and have tried to install unity and unistall it over and over? 0 Answers

Forge-like in game editor 0 Answers

how do i put a PlayerPrefs into a conditional statement 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges