- Home /
Custom variable declared in JS, that isn't in plugins.
Hey... I'm rewriting things to JavaScript, and I ran into a problem. How can I declare a custom variable like var myScript : MyScript, when the variable script isn't in plugins? Because I have a problem that when it is in plugins, and is compiled before another script there is a error.
David
Is this script in the same language as the one you´re writing in?
The $$anonymous$$yScript is C#, and the script I wanna declare the war in is JavaScript, and that's the problem...I can rewrite even that $$anonymous$$yScript...But if it's not needed...
Answer by Joshua · Jul 11, 2011 at 12:44 PM
The only way to reference a variable in a script in an other language, is if it is higher in the compilation order. It does not have to be in plugins, it can also be in standard assets, but that's it. Why can't you place this script in there?
http://unity3d.com/support/documentation/ScriptReference/index.Script_compilation_28Advanced29.html
I know about that compilation order, I can't place it there, because the $$anonymous$$yScript.cs gets a variable from another scipt, and shows and if it's in Plugins/SA I show that "The type or namespace name TQueue
1' could not be found. Are you missing a using directive or an assembly reference?"
The code for declaring is public TQueue[] FinishedChunks = new TQueue[](); without the []
That's why you shouldn't mix different languages. You can use single scripts (that work in itself) from other languages but crossreferences between languages is not a good idea. If it's a huge project it's just a mess.
If you do go cross language it's a one way stream, that's the main thing to remember.
A script stored in a non-standard folder (a folder created by you in Assets) will be compiled last, what enables it to "see" all scripts already compiled (scripts in standard folders). If the JS script is in a folder like this, it will be able to find $$anonymous$$yScript in a C# script stored in any standard folder. The problem, of course, is that nobody at the standard folders will know it. I use several static vars in a central script to exchange information between incompatible scripts, but it isn't enough sometimes.
That sounds like a real pain, aldonaletto. I ussually just go with rewriting it in the correct language.
Your answer
![](https://koobas.hobune.stream/wayback/20220612140917im_/https://answers.unity.com/themes/thub/images/avi.jpg)