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 Punkjim420 · Jan 21, 2013 at 11:40 AM · stringsplitcomma

converted array item to string returns "s,tri,ng" with commas?

Im trying to make an inventory. Everything works perfectly except for one thing, when scrolling between items i noticed all "strings" listed are seperated like this: (m,e,yo,u,h,er,hi,m). I dont want commas at all.. can anyone see why this random comma appears to be seperating my strings? i use Unityscript / Javascript.

 var itembagCursor : int = 0;
 var itembagCursorMax : int = 0;
 var selectedItem;
 var selecteditemname;
 
 function Start(){
 
     Master.itembag.AddRange(Array("potion","shard","antidote")); //add item to inventory
     itembagCursorMax = itembagCursorMax + 2;
     Master.inventory.AddRange(Array("key","key","ammo","ammo")); //add multiple items
 
     Master.inventory.Sort(); //sort inventory
 
     Master.inventory.Remove("ammo"); //remove first instance of item
 
 }
 
 function Update(){
 selectedItem = Array(Master.itembag[itembagCursor]).ToString();
     if(Input.GetKeyDown(KeyCode.LeftArrow)){
         itembagCursor = itembagCursor - 1;
     }
     if(Input.GetKeyDown(KeyCode.RightArrow)){
         itembagCursor = itembagCursor + 1;
     }
     if(itembagCursor > itembagCursorMax){
         itembagCursor = 0;
     }
     if(itembagCursor < 0){
         itembagCursor = itembagCursorMax;
     }
 }
 
 function OnGUI(){
     GUI.Label(Rect(0,0,400,50), "Inventory: " + Array(Master.inventory)); //display inventory by converting it to an array
     GUI.Label(Rect(Screen.width/2 - 200,Screen.height - 50,400,50),selectedItem);
 }
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 Bunny83 · Jan 21, 2013 at 12:15 PM

This makes no sense:

 selectedItem = Array(Master.itembag[itembagCursor]).ToString();

Your items are strings, you create a new array from your selected string which will split the string into characters.

 selectedItem = Master.itembag[itembagCursor];

btw you use a lot untyped variables as well as the slow Array class. You should specify a type for each variable and better use a generic List. Can't go more in detail at the moment.

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 Punkjim420 · Jan 22, 2013 at 01:33 AM 0
Share

ok, thank you for your reply, so what are you saying in short? i need to remove the "ToString();" in the first line you pasted because its converting a string to a string?

avatar image Punkjim420 · Jan 22, 2013 at 01:41 AM 0
Share

never$$anonymous$$d my last comment. i figured out what you ment. i feel silly. thank you very much @Bunny83.

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

10 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

Related Questions

How to split alphanumeric string into array of strings based from their type : alpha or numeric ? 1 Answer

Splitting String only on a "space". Using my method --- FIXED 2 Answers

if statement not returning true 1 Answer

disperse string by letter 1 Answer

How to add more commands in the ToString(); 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