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 castor · Jul 16, 2013 at 02:41 AM · javascriptvariablepassing

Passing a variable by reference in javascript (using a C# script)

So I need to pass a variable by reference and I'm using Javascript. From this answer I learned that I need to do it in C# if I want it to work in Javascript.

Now the tricky part for me is that I never used C#.

So my attempt was to write the following function in C#:

 public bool SelectedBoolean (ref bool selectedVariable){
     return selectedVariable;
 }

And I would like to use it in this Javascript function:

 function AddStep (currentScript : List.<ScriptStep>, selectedBoolean : boolean, result : boolean){
     var step = new ScriptStep (currentScript, allScriptsList);
         step.stepType = StepType.BooleanChange;
         step.stepSelectedBoolean = addBoolean.SelectedBoolean (out selectedBoolean : boolean);
         step.stepSelectedBooleanResult = result;
     currentScript.Add(step);    
 }

Trying to use the out is just giving me errors and no idea how I could fix it. Also I realized that since the "selectedBoolean" is going through a Javascript function I guess it becomes a value automatically? Does that mean I need to write the final function in C#?

How would I go about solving this?

Thanks in advance!

Comment
Add comment · Show 1
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 tw1st3d · Jul 16, 2013 at 04:23 AM 0
Share

Please post your errors.

1 Reply

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

Answer by Eric5h5 · Jul 16, 2013 at 04:35 AM

You don't use the "ref" or "out" keywords in Unityscript; they are implied. However, classes are always passed by reference, so instead of messing with C# stuff it's often easier if you just make a custom class for the variable type. e.g.:

 class RefBool {
     var b : boolean;
     function RefBool (b : boolean) {
         this.b = b;
     }
 }
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 castor · Jul 18, 2013 at 04:13 AM 0
Share

thanks Eric, I think I got 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

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

Related Questions

Variable Not Changing. 0 Answers

InputField in a different scene to Text 1 Answer

Changing Variable OnMouseClick? Help! 1 Answer

Change variable value of a script from another script. both in different Game object 1 Answer

Trivial question for Javascript/Unityscript experts: static variables? 4 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