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 fwentz · Oct 11, 2012 at 09:01 AM · objectintoperator

Operator + cannot be used to combine Object and Int

Hi there, I'm just watching this video: http://vimeo.com/channels/151501/17058866

The series is very good so far, but I've come to a point, where the maker of the video does something, which doesn't work at my unity:

 var box;                
     box = "small box ";        
     boxNumber = 3;
     
     print (box + boxNumber);

It should print "small box 3"but I get the error: "Operator '+' cannot be used with a left hand side of type 'Object' and a right hand side of type 'int'."

Which I totally understand as I come from php, where variables are "connected" via "." ($first.$last)

Why doesn't it work?

Comment
Add comment · Show 2
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 Fattie · Oct 11, 2012 at 09:04 AM 1
Share

explicitly type the variable in line one

var box:String;

avatar image rutter · Oct 11, 2012 at 09:29 AM 0
Share

In particular, it's not working because the compiler isn't able to infer the type of `box` (you can fix this by specifying the type, or assigning a value while declaring it).

UnityScript enforces strict typing if your script contains `pragma strict;`, which has been the default for the past few releases. The tutorial you're following might have been using dynamic typing, which is sometimes easier to work with but has a few drawbacks (sometimes hurts performance, doesn't catch some problems until code is run).

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by fwentz · Oct 11, 2012 at 09:47 AM

Thanks a lot both of you =)

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

12 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

Related Questions

Array - Convert Object into Int 5 Answers

pragma strict issues with iOS 1 Answer

I need to make a door open only when the player's essence has reached a certain level 0 Answers

Operator '+' cannot be used 1 Answer

How to pass a int from a object to another 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