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 sandeshj · May 19, 2012 at 01:08 PM · arraystringintindexing-array

How to convert String array to int array

Hi friends, I'm asking this question after searching this forum for similar problems but they are not helpful for me. I am creating a card game. I've created string array of cards player has >

 var playerCards : Array = ["playerCard1", "playerCard2", "playerCard3", "playerCard4", "playerCard5", "playerCard6", "playerCard7", "playerCard8", "playerCard9", "playerCard10"];

While playing game, the player will select one of these cards. I want that card to give/ display its index in array, so that I can compare it with another card and see whether they match or not like this >

 if (playerCardID == enemyCardID)
 {
     Debug.Log ("CARDS MATCHED!!!");
 }

I need indexes of playerCardID only, those of enemyCardID will be generated randomly. SO what is the solution for this one. can you help plz. Thanx

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

1 Reply

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

Answer by Berenger · May 19, 2012 at 02:21 PM

You can create a function that find the index of a string in the array by comparing it with each members. Might not be very optimized, not to the point to slow down your game but still. You could use a dictionary as well, but I suppose it would be the same.

You could create a class containing the name and the index, then do an array of that instead.

Comment
Add comment · Show 3 · 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 sandeshj · Jun 10, 2012 at 12:43 PM 0
Share

as a beginner I'm looking to complete this game. I will see about optimization later. BTW Didn't get the answer (I mean I am too noob to understand this stuff) but appreciate your effort. thanks

avatar image Setzer22 · Jun 10, 2012 at 01:20 PM 0
Share

Well, what he's telling you, is to create a class, like a custom type of variable, wich can hold, both, the name of the card (in a string) and the index of the card (you can add more data as well).

Let's say you create the card class, and that class has the properties ID and name, ID being an integer, and name being a string, so then, you could create your array of "card type" ins$$anonymous$$d of strings, so then you could easily access to both the name or the index of any particular card just doing this:

playerCards[0].ID -> this holds the ID from the player's first card

playerCards[0].name -> this holds the string containing the player's first card name

avatar image Berenger · Jun 18, 2012 at 03:21 PM 0
Share

sandeshj1990 : thanks, that was very simplified.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Array - Convert Object into Int 5 Answers

Converting a string to an int 2 Answers

Convert Array to String 3 Answers

Extracting Numbers from String Place JS 1 Answer

Why Won't This Work? 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