Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 JoshMBeyer · Jun 10, 2013 at 05:29 AM · textfiledataphpstorage

Is this possible to work as a temporary storage?

I am about to make a game as a test for my friend. I was wondering if it is possible to create a file rather it be PHP, xml, or even just a text file and load it into the assets inside the unity project to store data. For example, something simple like "Cash: $100" Then write a script to where if the player picks up a gameobject "Cash +20" it will access that created file in the assets and edit the value, then when the game is closed or restarted the cash value in the file will still be $120. Is that possible to do as a temporary way to store data?

Comment
Add comment
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

2 Replies

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

Answer by phxvyper · Jun 10, 2013 at 05:58 AM

This is actually really easy, and you don't need to load it into asssets as there is no point to do so. The basics behind it is just this:

 File.WriteAllLines(@"ThePathToYourFileHere", "TheTextHere");

Pretty simple! There is some other stuff you might want to do... But you might want to learn that stuff on your own!

Just use that method, and what your saying will work fine :)

Edit: (According to the askee's requests, i have made these edits)

According to your example, which is: When cutting down a tree, the player will recieve 25xp. Save this to a file and whenever the game loads up the player should be able to load that data from that file.

In order to save to a file with organization, you'll want to use one of several methods: HashTable, Dictionary, WAD (Where's All that Data?), CCC (Comma Content Control) or GCF (Game Cache File/Game Content File).

CCC is quite common so i will be showing this, you'll have to do research on the other methods if you want to use them.

  1. Create a Dictionary with a key of string and a value of string[].

  2. Create an index within the Dictionary with a key of "PlayerXP" and assign it to a null value.

  3. Create a string[] that contains all of the data for any XP given to the player and organize it respectively. (e.g. Tree Cutting XP, Fighting XP, whatever you want for the PlayerXP Label)

  4. Every once in a while (possibly every 30 seconds) and/or when the player quits the game, assign the Dictionary Value to the string[] you created, then save the dictionary to a file using the format of "[key]:[value1],[value2],[value3],[val..." using some Regex methods and the File.WriteAllLines() method that i showed you.

  5. Create a Start method that will load all data from the file into the Dictionary and String[] that you created earlier. Using the File.ReadAllLines() method, you will have to use some Regex for this.

If you don't understand this then i suggest that you go and research the topics of which you might not understand fully:

  • Regular Expression (Regex)

  • File IO

  • Array/List/Dictionary Separation

Comment
Add comment · Show 2 · 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
avatar image JoshMBeyer · Jun 15, 2013 at 01:14 AM 1
Share

I don't understand how to use it exactly. From what it looks like, I understand its getting the provided path of the file, then saving the written text. But, lets say what I am trying to do is save experience. I cut a tree, now I want it to go to the txt file and add +25XP. to the "WoodCuttingXP:" line of text. Then when I load the game up next time, It should say under my woodcutting skill that i have 25xp. So how would I do this? Cause I have looked and I can't figure that out

avatar image phxvyper · Jun 16, 2013 at 04:20 AM 0
Share

@Josh$$anonymous$$Beyer this is pretty simple... I'll edit my answer appropriately to your needs in a moment, check back later and the answer will explain the entire process including how to make it efficient.

avatar image
0

Answer by JoshMBeyer · Jun 16, 2013 at 05:35 AM

Thank you, that was very helpful and informative.

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

15 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

Related Questions

How can I read data from a text file, putting a large amount of data into structures 2 Answers

[Closed] Place to store user data 1 Answer

Data Storage Access 0 Answers

How does a TextAsset work? 1 Answer

Best way to manage stats in a text file 2 Answers


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