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 SlyRipper · May 09, 2013 at 08:40 PM · savedatabaseinventorymysqlitem

Good way to store Items in a mySQL database?

Hello all,

I'm just wrecking my head how to add my generated Items to a database to load it each time the webplayer is used.

I've created a simple Item class and several Weapons, Armor, etc that inherit from that Item Class. The Inventory is working well, I store generated Items with random values into my Item-List and show them via GUI Buttons.

The problem here is I can't think of a way to store them into a database (along with other players) to load them when the player comes back. I thought about auto_increment the database so every added item will have a unique ID, but how can I assign that ID to the Item in Unity to prevent adding the same Item again?

I have a userID, atm 25 Inventoryslots (i think they wont change in future), ItemTypes (Weapon, Torso, etc) and the Itemvalues (price, dmg, several boni stats, etc).

I tried creating an Inventory database with userID, itemType and itemValue to store them and receive them by getting the userID. The problem here is how to select the right item when I want to delete it? Let's say the player sells the item and I have to remove it from the database, too. How should i select it? I could possibly select it by it's values, but there could be another item with the exact same values (also if it would be very lucky ^^). So I need a unique value (primary key) to select items from my db, but how to create such a unique value without the danger to insert a duplicate into the db?

I'm no good programmer or database creator ^^ But I really stuck here, can't figure a way out to correctly store and retrieve or delete the correct items for my Inventory.

Hope you could understand at least a little bit, sry for bad english. Thanks in advance!

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

Answer by SlyRipper · May 11, 2013 at 09:03 PM

I've found a decent way I guess.

I created a database called "inventory" and added these columns: ID, itemID, itemType, itemName, itemStats

ID -> playerID itemID -> primary key (auto_increment) itemType -> example: Weapon, Torso, etc. itemName -> Helm, Sword, etc. itemStats -> 1,2,3,4,5, (the length varies depending on the item, I save all values the item have like damage, buffs, etc in a single varchar column)

Now I simply added the itemInfo from Unity via WWWForm into the database like usual and used an mysql command to retrieve the last inserted itemID, send it back to unity and assigned it to the item in Unity. Now I have a unique connection and be able to surely delete the correct items from the database..

The only concerns I have is the auto_increment. For example if thousands of people play the game and items will continously be created, the numbers from auto_increment will increase a lot, therefore the lines send back to unity get longer and longer (also there could be a limit or a too high number to store?)

What's a solution for that? filling the gaps from deleted items? Resetting the table from time to time to new auto_increment values that start again at 0?

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
avatar image
0

Answer by peatanderson49 · Jun 12, 2013 at 08:46 PM

Work with mysql databases by using of how to fix mysql error 1046

Read item http://www.mysql.fixtoolboxx.com it would allow you to work with mysql databases

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

14 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

Related Questions

Saving Database from server to local and read from there (android) 0 Answers

Custom Editor Window to Create and Store Item Data 1 Answer

Item Database 3 Answers

How do I retrieve an item from a list? 1 Answer

Making an Inventory (Basics) 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