Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by TheDemiurge · Oct 07, 2010 at 05:47 PM · functionjavascript-specificuce0001keyword

Javascript / Unityscript 'with' keyword

So I'm trying to take advantage of Unity3's new JS feature, function types. My code is basically trying to do something like this:

class MyClass {
var myVar:int;
var func: function();
}

what I want to do is be able to change myVar from inside whichever function I assign to func. I need it to act just like it would when using this.member from within a method, because my class has multiple such members and multiple such methods (function members, really).

I found this link which in the real JavaScript would likely work for this purpose.

But it doesn't work here though, the compiler keeps expecting colons and semicolons. Either the with keyword works differently here or it just doesn't really work yet. I think I can technically do this in C# with using, but I figure now that we have more JS functionality I would give it a try.

Hope I'm being clear enough in what I'm trying to do. I'll revise this if more info is needed.

Comment
Add comment · Show 2
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 · Oct 08, 2010 at 05:14 PM 0
Share

"using" in C# only imports namespaces. The equivalent in JS is "import", but neither have anything to do with this question.

avatar image TheDemiurge · Oct 09, 2010 at 09:26 AM 0
Share

Good point. I don't script in C# very often, yet. $$anonymous$$ost of my experience is from C++ and it has been a while. I'm used to being able to declare methods inside a class and only later define them with the :: operator, and I was hoping I could use anonymous functions to do something like that on a per-object (vs per class) basis. But I think I've got another way that will get this done.

1 Reply

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

Answer by TheDemiurge · Jan 02, 2011 at 06:21 AM

Sigh. nice response typed up and IE got all screwed up. Here goes: answering question now that I can and don't remember why I needed this in the first place, for the sake of it not being unanswered anymore.

Using C# instead of JS.

public delegate int MyDelegate(); public class MyClass { int m_myVar; public MyDelegate Del;

public void SetMyVar() { if (Del != null) m_myVar = Del(); else m_myVar = 0; }

}

// in another script: MyClass mc = new MyClass(); mc.Del += new MyDelegate(DoSomething); mc.SetMyVar();

public int DoSomething() { return 5; }

Comment
Add comment · 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

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

No one has followed this question yet.

Related Questions

passing a function as a parameter to another function 1 Answer

If statment based on a function not working 3 Answers

Calling function in a script based on raycast hit 1 Answer

Object wont object get destroyed 1 Answer

How to call a function from a script component on another object 1 Answer


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