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 Guardian2300 · Apr 17, 2013 at 05:05 AM · c#javascriptvariablesissues

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?

Comment
Add comment · Show 3
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 Eric5h5 · Apr 17, 2013 at 07:24 AM 0
Share

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.

avatar image Guardian2300 · Apr 17, 2013 at 07:39 AM 0
Share

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.

avatar image Eric5h5 · Apr 17, 2013 at 07:44 AM 0
Share

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

1 Reply

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

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.

Comment
Add comment · Show 4 · 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 fafase · Apr 17, 2013 at 05:52 AM 0
Share

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.

avatar image Guardian2300 · Apr 17, 2013 at 06:42 AM 0
Share

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

avatar image fafase · Apr 17, 2013 at 07:15 AM 0
Share

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).

avatar image Guardian2300 · Apr 17, 2013 at 07:25 AM 0
Share

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

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

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


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