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 /
avatar image
0
Question by Bincredible · Jan 28, 2017 at 05:56 PM · datadata storagebinaryformatterfilestreamdatapath

Loading player data using data persistence

Hi, I am learning to how to save player data using data persistence and I have encountered an error which has me confused. In the tutorial I am watch it is in C# however I am using UnityScript. The following screenshot is the tutorial and the code snippet is what I have wrote. alt text

 if(File.Exists(Application.persistentDataPath + "/gameInfo.dat")){
         var binForm : BinaryFormatter = new BinaryFormatter();
         var file : FileStream = File.Open(Application.persistentDataPath + "/gameInfo.dat", FileMode.Open);
         var data : playerData = (playerData)binForm.Deserialize(file);
         file.Close();

I thought I had translated it correctly however line 4 of my code snippet where I am deserialising the file, I get an error which is expecting a semicolon at the end of that line. Any idea why this might be happening? thanks

screen-shot-2017-01-28-at-175124.png (52.5 kB)
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 JaredHD · Jan 28, 2017 at 06:23 PM 0
Share

I'm not 100% sure but shouldn't the (playerData) be (PlayerData) Caps`var data : playerData = (PlayerData)binForm.Deserialize(file);`

avatar image Bincredible JaredHD · Jan 28, 2017 at 08:32 PM 0
Share

I am referencing the class I made below which is called "playerData", I did have it called "PlayerData" in which case I wrote what you suggested. Below is the class I am using.

 class playerData{
         var bloxAmount : int;
         var currentSkin : Sprite;
         var currentColor : Color;
 }

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by AurimasBlazulionis · Jan 28, 2017 at 08:52 PM

The syntax problem is with typecasting. Instead of (playerData)binForm.Deserialize(file), type binForm.Deserialize(file) as playerData.

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

62 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

Related Questions

Do u need to learn Swift in order to transfer ur data (strings, int, etc.) to Xcode? 0 Answers

build file with one game and two game can access it 0 Answers

"IOException: Sharing violation on path" when Loading Data to Overwrite Save 1 Answer

Data Management Issue - How to manage retrieved data from mysql? 0 Answers

[Quiz game] How do I make players contribute with questions? 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