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 Iceblitzyt · Apr 21, 2013 at 07:47 PM · c#to

can someone help me with my js to c# conversion error

Hey there,

I'm converting this script to c# from js : http://wiki.unity3d.com/index.php?title=Creating_a_Drag_and_Drop_Spell_Bar

The original Js version is:

 function checkReq(item, list){
     var result = false;
     for(i=0; i<list.length; i++){
         if(item == list[i]){
             result = true;
             break;
         }
     }
     return result;
 }
  

I converted it to this:

 void checkReq(item, list){
     var result = false;
     for(i=0; i<list.length; i++){
         if(item == list[i]){
             result = true;
             break;
         }
     }
     return result;
 }

I think I've done it right, but i keep getting this error: (212,18): error CS1041: Identifier expected Can someone help me?

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

4 Replies

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

Answer by Nidre · Apr 21, 2013 at 09:42 PM

you should add the identifiers of the paramters for example

 bool checkReq(GameObject item,GameObject[] list){
     bool result = false;
     for(i=0; i<list.length; i++){
     if(item == list[i]){
     result = true;
     break;
     }
     }
     return result;
 }

Change "GameObject" with the type you want to use as parameter

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 Iceblitzyt · Apr 21, 2013 at 09:52 PM 0
Share

Wonderful thanks. I was also wondering, With conversion is this proper from js to c# private var clickInfo = new Array(); To public var clickInfo = new List(); I'm sorry I'm horrible at exchanging js to c#

avatar image
2

Answer by Bunny83 · Apr 21, 2013 at 10:20 PM

Sorry to say it that way, but this is one of the worst UnityScript scripts i've seen. He's abusing an untyped ArrayList as a kind of "class" by pushing all different kind of information into one list. If you would translate this 1:1 to C# it would be a casting hell beside that it's kinda slow. If you want to know how it would look like, just do this:

  • Create a new Unity project

  • Copy all UnityScript files you want to "convert" into this project.

  • Build the project as standalone application

  • Locate the "Assembly-UnityScript.dll" inside the data folder of the build

  • Download ILSpy and open the above mentioned DLL with it by dragging it into the window

  • Make sure you have set the language to C#

  • Locate the class you're after and copy the code.

Again i wouldn't even try to convert this mess to C#. You should use a class for your items and use meaningful names.

Btw the generic list already has a function that checks if a given item is in the list, so the function "checkReq" is quite useless / redundant.

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 Iceblitzyt · Apr 21, 2013 at 10:27 PM 0
Share

Well I was going to have the spells, in a class ect. It's just this is the only resource i could find at all on making a working spell action bar mmo style with drag and drop icons.

avatar image
-1

Answer by ExpiredIndexCard · Apr 21, 2013 at 09:35 PM

 bool checkReq(item, list){
     bool result = false;
     for(i=0; i<list.length; i++){
        if(item == list[i]){
          result = true;
          break;
        }
     }
     return result;
 }

Also, what does the error say?

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 Iceblitzyt · Apr 21, 2013 at 09:42 PM 0
Share

it says Abartest.cs(225,15): error CS1041: Identifier expected would you like me to pm you the entire script? I compiled it into a small one?

avatar image
0

Answer by DESTRUKTORR · Apr 21, 2013 at 09:00 PM

Firstly, change var to bool. var is a proper keyword in C#, but it's not as efficient as just declaring it as the proper type. Secondly, you can't return a value from a void method. Change the method's return type to bool.

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 Iceblitzyt · Apr 21, 2013 at 09:21 PM 0
Share

So i changed void checkReq(item, list){ To bool checkReq(item, list){.. I still have errors, with that?

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

14 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 avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

can't get this right... help please... 1 Answer

Spawning portal 1 Answer

Temporarily disable gamepad button 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