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 venhip · Nov 14, 2012 at 12:05 AM · errorvariablevaluetype

Expression denotes a 'type'

"Expression denotes a 'type' where a 'variable' 'value' or 'method group' was expected"

It seems that there are many of these posts but they all seem rather specific to the code, or rather I haven't seen a good explanation of it but anyway; Could someone please find out whats wrong with my code and if possible provide a link to or an explanation of this error.

   GameObject Arrow = Instantiate(projectile, bow.transform.position, bow.transform.rotation ) as GameObject;
             Arrow.GetComponent(ArrowFlight).currentTarget = target;


Many thanks.

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

2 Replies

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

Answer by liszto · Nov 14, 2012 at 12:16 AM

First of all if you code in C# you must do this :

  Arrow.GetComponent<ArrowFlight>().currentTarget = target;

Cause it's cleaner.

Second :

   ArrowFlight ArrowFlightObj = (ArrowFlight) Arrow.GetComponent<ArrowFlight>();
   ArrowFlightObj.currentTarget = target;

Or something like that ;)

Comment
Add comment · Show 9 · 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 venhip · Nov 14, 2012 at 01:20 AM 0
Share

Thanks for taking the time! However using your script yields an error: cant convert gameobject to transform. I have declared 'Arrow' at the top but I don't believe its that, any ideas? Thanks

avatar image liszto · Nov 14, 2012 at 06:27 AM 0
Share

Did you follow this example (in C#) to understand how works Instantiate function ?

http://docs.unity3d.com/Documentation/ScriptReference/Object.Instantiate.html

I think the answer to your mistake is here :) Look in the second example. And you'll probably need to cast your instantiate I think to anticipate another Unity Error ;)

avatar image venhip · Nov 14, 2012 at 07:24 AM 0
Share

$$anonymous$$y instantiating was fine, that has been working for a while, and I did think about the typecasting so I did try it. I type cast as a Transform (I tried GameObject and RigidBody too just in case) but it doesn't mitigate the error.

avatar image liszto · Nov 14, 2012 at 08:29 AM 0
Share

Sorry I forget you cast it :/ Probably too tired and I didn't see the end of your line :x. So for your error now : currentTarget and target get the same type ? Transform & Transform OR GameObject & GameObject ?

avatar image venhip · Nov 14, 2012 at 04:12 PM 0
Share

both currentTarget and Target are GameObject variables, the error message says the line thats wrong is this:

arrow = Instantiate(projectile, bow.transform.position, bow.transform.rotation) as GameObject;

The error is still the Unable to convert gameobject to transform message. Would it be helpful for me to send you the relevant scripts? thanks.

Show more comments
avatar image
1

Answer by Loius · Nov 14, 2012 at 07:43 PM

"Expression denotes a 'type' where a 'variable' 'value' or 'method group' was expected"

An "Expression" is, basically, anything that can be interpreted as a group. (x+1) is an expression, Arrow is an expression, Instantiate() is an expression.

One of your expressions is a type (meaning, when the compiler sees it, it gets an actual class back), but it should be a variable, a value, or a method group (function call).

Just noticed - it looks like you're mixing JS and C# syntax. C# declares variables as "Type name = (Type)InitializationFunction()"; JS declares them as "var name : Type = InitializationFunction() as Type". Pick the format that fits your file type :P

// this is valid but not in this case V

You can't name variables the same thing as classes. That's a minor reason why everyone will recommend that you use CamelCase for classes and functions, and camelCase for variable names.

Change your variable name from Arrow to something that isn't a class name.

Comment
Add comment · Show 6 · 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 venhip · Nov 14, 2012 at 08:13 PM 0
Share

Great thanks, I did end up changing it but I didn't have and classes, functions or scripts named 'Arrow' so in this instance it shouldn't have been affecting it

avatar image Loius · Nov 14, 2012 at 10:23 PM 0
Share

Just noticed - it looks like you're mixing JS and C# syntax. C# declares variables as "Type name = (Type)InitializationFunction()"; JS declares them as "var name : Type = InitializationFunction() as Type". Pick the format that fits your file type :P

avatar image venhip · Nov 14, 2012 at 10:32 PM 0
Share

you can put 'as Type' in C#, it works and I'm using it successfully in other scripts :)

avatar image liszto · Nov 14, 2012 at 11:40 PM 0
Share

He just wants to say it's a jJavascript(Unityscript) logic not a C# logic. It's just that.

avatar image Loius · Nov 15, 2012 at 06:24 PM 0
Share

Huh, I've never had luck using As in C#. I must be terrible at the typing. :)

I'm out of ideas, though - I hope the other answerer can get you to a solution.

Show more comments

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

11 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

Related Questions

HELP!!! Expression denotes a `type', where a `variable', `value' or `method group' was expected 1 Answer

What is typing a variable? Is it assigning the value? 3 Answers

Object not set to instance of an object 2 Answers

Getting error: Cannot modify a value type return value of `UnityEngine.Rigidbody.velocity'. Consider storing the value in a temporary variable 1 Answer

Passing a Script Name to a Function 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