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 Kiloblargh · Mar 18, 2013 at 06:40 PM · javascriptescapechar

Is it possible to declare a null or escaped char in Unityscript

Cannot convert string to char. That's my problem right now. I don't know why it can't, it isn't like it is a terribly difficult to do... but anyway, all I want is this:

 var nothin : char = '\0';

That should work but doesn't. My usual workaround for declaring chars is to say

 var charX : char = "X"[0];

which will obviously not work in this case. So what will?

Comment
Add comment · Show 9
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 hoy_smallfry · Mar 18, 2013 at 07:08 PM 1
Share

Are you using a literal value like in your example? I'm not understanding why the second method won't work for you.

avatar image Kiloblargh · Mar 18, 2013 at 11:34 PM 0
Share

I don't want '0,' I want backslash-zero, which is a null character. I'm trying to filter textfield input so that all special characters are ignored. In the second example, that's picking the first character out of a string; if I tried to say "\0"[0] I would just get the character "\".

avatar image hoy_smallfry · Mar 18, 2013 at 11:40 PM 1
Share

I don't think you understand - char values can be represented by interger values. According to this table the value you want is represented by the number 0.

Here's an experiment for you to try out. Look at the table. According to it, decimal value 65 = 'A'. Let's do this:

 var c : char = 65;
 Debug.Log(c);

What do you get?

avatar image Eric5h5 · Mar 18, 2013 at 11:42 PM 0
Share

Guys, "\0" is a null character. This isn't about literal backslashes or zeroes.

avatar image hoy_smallfry · Mar 18, 2013 at 11:49 PM 1
Share

@Eric5h5, did you even read what I said? I said 0 is the integer value for the null character; they are the same. Look at the link I posted. I'm very aware of what the null character is. Loius' answer was just as correct as yours; arguably more correct because it's cleaner.

If neither of you understand, then try the snippet I posted.

Show more comments

2 Replies

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

Answer by Eric5h5 · Mar 18, 2013 at 11:37 PM

"\0" is a single character, even though it looks like two characters. So

 var nada = "\0"[0];

is correct. You can't type "\" by itself and get a backslash character, since the backslash is an escape character. In order to actually use "\" as a char, you'd need to do

 var backslashChar = "\\"[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 Loius · Mar 18, 2013 at 07:23 PM

What's your use case?

How about "var c : char = 0"?

Comment
Add comment · Show 1 · 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 hoy_smallfry · Mar 18, 2013 at 07:25 PM 0
Share

I agree, I've just been confused about what is difficult about what he wants.

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

13 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Setting Scroll View Width GUILayout 1 Answer

Migrating data from C# to UnityScript 2 Answers

Where can I start to learn more about coding? 2 Answers

Can someone help me fix my Javascript for Flickering Light? 6 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