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 Atnas1010 · Oct 29, 2010 at 02:13 AM · pragmastrictbce0051

Why does one scipt give an error, when I have a script using #pragma strict?

I had a project that suddenly gave me errors when I started adding #pragma strict to my scripts

I removed the code not giving errors, and ended up with these two scripts:

1) PragmaScript: (yes, this is the entire script)

#pragma scrict

2) ScriptInFolder:

function Start ()
{
    var names : Array = new Array();
    names.Push("John");
    print(0 + names[0]);
}

ScriptInFolder must be in a folder and running on a gameobject. PragmaScript can be placed anywhere.

The runtime error is:

InvalidProgramException: Invalid IL code in ScriptInFolder:Start (): IL_001f: add

Why does this happen? Shouldn't javascript "fix" these things on the fly, even though I use #pragma strict in one script?

Comment
Add comment · Show 3
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 · Oct 29, 2010 at 02:26 AM 0
Share
@Ulrich: Please don't add tags that aren't relevant to the question.
avatar image zannghast · Oct 29, 2010 at 02:45 AM 0
Share

Can you elaborate on what you did when you played around before it suddenly got fixed?

avatar image Atnas1010 · Oct 29, 2010 at 02:51 AM 0
Share

I have just edited my post

3 Replies

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

Answer by Mike 3 · Nov 03, 2010 at 06:28 PM

BCE0051: Operator '+' cannot be used with a left hand side of type 'int' and a right hand side of type 'Object'.

That's the error you'd be getting if you had #pragma strict in your second script

change it to

print("0" + names[0]);

and it should work ok

What's happening is that since you're not using #pragma strict in the second script, it's looking at the two objects and can't work out what it should do until runtime. Unfortunately it guesses wrong, and screws up when it tries to do an integer addition

Making it string + object should call .ToString() implicitly on the second object, fixing it

Comment
Add comment · Show 7 · 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 Atnas1010 · Nov 03, 2010 at 06:34 PM 0
Share

Just as I thought things weren't going to get any stranger. The code you posted only works if I actually put #pragma strict in ScriptInFolder. If I don't do that, then I get a "IL_001e: add" error at runtime

avatar image Mike 3 · Nov 03, 2010 at 06:55 PM 0
Share

Heh. print("0" + names[0].ToString()); should work with both.

avatar image Atnas1010 · Nov 03, 2010 at 07:17 PM 0
Share

Yup it does :) But overall, with all the oddities involved I think I will report this as a bug. Also, would there be any way to declare the array to hold strings? (not builtin)

avatar image Mike 3 · Nov 03, 2010 at 08:40 PM 0
Share

List. names = new List.(); you'll need import System.Collections.Generic; at the top of your script

avatar image Mike 3 · Nov 03, 2010 at 09:49 PM 1
Share

Oh sorry - var names : List. = new List.(); my code before was half unityscript, half c# :P

Show more comments
avatar image
-1

Answer by Ulrich · Oct 29, 2010 at 02:14 AM

try with "function Start ()" 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 Atnas1010 · Oct 29, 2010 at 02:20 AM 0
Share

Is that not EXACTLY what I wrote?

avatar image Ulrich · Oct 29, 2010 at 02:23 AM 0
Share

Glad it works. Good luck with your game.

avatar image zannghast · Oct 29, 2010 at 02:44 AM 2
Share

Ulrich, I know you mean well. It's just that Atnas was pointing out that what you had suggested as an answer did not really help because what you had suggested for Atnas to use was, in fact, already being used in the script.

avatar image
0

Answer by soulburner · Feb 21, 2013 at 11:19 PM

Yeah, I've just had the same error while trying to perform the following:

 string + int + int + string

the error dissappeared when I've changed it to:

 string + int + "" + int + string
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

1 Person is following this question.

avatar image

Related Questions

#pragma strict exhaustive list of types 1 Answer

Invalid IL code exception when calling method 2 Answers

No appropriate version of 'UnityEngine.Object.Destroy' for the argument list '(Object)' was found. 1 Answer

BCE0051 Error 1 Answer

Pragma strict : GetComponent without knowing the name of the component 3 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