- Home /
Accessing variables from scripts issues
I am having an issue of accessing a script using the examples I found all over but no matter what I do it will either tell me it doesn't exist or the unity editor complains about it while not complaining in monodevelop. Now my main issue is because I need to write a program for I/O I need c# and I have variables I need from javascript to save variables. Now in my javascript I am trying to access another script by using this code;
public var otherscript:FileScript;
function Awake()
{
otherscript = this.GetComponent(FileScript);
}
so FileScript is in C# now I keep getting an error message from the public var line saying "The name "FileScript" does not denote a valid type ('not found').BCE0018. Any suggestions of what to do would be appreciated?
Now my main issue is because I need to write a program for I/O I need c#
That's not correct at all. Just write everything in JS; don't mess around with trying to get different languages to interact when you don't need to.
trying to understand system IO but not much on system IO in javascript cause its all displayed in c# on msdn. So if I had several variables for example username, password, fname,lname to write into a text file, if I wanted to read the file I want it to look at it in a certain order. The idea is i can load all my variables back when I load the program.
File IO works exactly the same way as it does in C#, just with JS syntax. http://forum.unity3d.com/threads/5084-Can-I-read-and-write-text-files-using-Javascript
Answer by GamingNewBie · Apr 17, 2013 at 05:26 AM
Javascript files are compiled before c#, so i think that is why you are getting the error. To get C# compiled before javascript place the script file inside the Standard assets folder. take a look at the following link http://docs.unity3d.com/Documentation/ScriptReference/index.Script_compilation_28Advanced29.html I hope this help.
I have never heard that Js scripts were compiled first. What I ave heard is that there are two compilers in Unity (Boo for Boo and Js and a C# compiler for C#). The compilers are able to see what one language is having, meaning that two scripts in Js can see each other because the one compiler understands both (I am not aware if Boo can see JS as they use the same compiler).
Problem is the C# compiler does not see the Boo compiler, but the solution as you said is to make thing happen ahead but a compiler is able to read IL.
Putting scripts in the std Asset folder they get compiled into IL, once in IL first meaning that now our compilers already scripts they can understand.
So if you need Js members in a C# scripts, place your Js script in the Std Asset. Note that your Js script will not be able to see the other C#, he is somehow above it.
So even if I wanted to be able to create a link between them both it sounds impossible. Wanted to create the link to read variables from both scripts
Considering you have the C# in Std Asset and Js somewhere else, the C# will not see the Js but the Js will see the C#. Now if you want the Js to connect with the C#, you can use Send$$anonymous$$essage, it is slower but it does the trick (and is probably the only way).
is it possible to make a variable from javascript equal the variable in c# using sendmessage. if not is there any information of running system I.O in javascript so I can create a data file and read it.
Your answer
Follow this Question
Related Questions
Connection between 2 scripts 1 Answer
Swipe Patterns to unlock efects 2 Answers
Help, How can I get variables? 1 Answer
Some Basic Conversions from JavaScript to C# 1 Answer
Convert from javascript to c# 2 Answers