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*){*
  •  	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*){_
    _
    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?

4 Answers

4

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.

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.

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.

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

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*){*

result = true;
break;
}
}
return result;
}
Change “GameObject” with the type you want to use as parameter

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#

No, i can't be sure. But ntdll.dll is a windows file. It could be a corrupt file, it could be an issue with a device driver...

@screenname_taken Ty for trying to help me . I have just found that there are 10 important updates for windows . Its fixed now .

bool checkReq(item, list){
bool result = false;
for(i=0; i<list.length; i++){
if(item == list*){*
result = true;
break;
}
}
return result;
}
Also, what does the error say?

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?