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 oliver-jones · Jun 29, 2013 at 06:55 PM · c#javascript

Convert C# Into UnityScript - Events in Unityscript

Hello,

I'm trying to convert a piece of C# into JavaScript, but I came across some C# that I've never seen before, doesn't even look syntax valid:

 StoreKitManager.productListReceivedEvent += allProducts =>
         {
             Debug.Log( "received total products: " + allProducts.Count );
             _products = allProducts;
         };

What the heck does the 'allProducts => {' mean? It doesn't even have a variable called 'allProducts', unless its referring to something within the StoreKitManager?

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 clunk47 · Jun 29, 2013 at 06:58 PM 0
Share

Did you try removing the invalid syntax? (=>) means equal or greater than, which is usually for an if() statement.

avatar image oliver-jones · Jun 29, 2013 at 07:02 PM 0
Share

It's not invalid though - the C# script runs fine, it just looks invalid to me, but I don't know much about C#

avatar image Jamora · Jun 30, 2013 at 12:28 PM 0
Share

The => notation is called a lambda expression. It is one way of creating anonymous methods. Read more about anonymous methods at http://msdn.microsoft.com/en-us/library/bb882516.aspx . What the code seems to do, on a first glance, is to print out how many subscribers there are to the event, then store a local instance of all subscribers.

2 Replies

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

Answer by oliver-jones · Jun 29, 2013 at 10:41 PM

Figured it out:

 import System.Collections.Generic;
 
 var  _products = List.<StoreKitProduct>();
 
 function Start(){
 
     StoreKitManager.productListReceivedEvent += RecicedProductList;
     StoreKitBinding.requestProductData( productIdentifiers );
 }
 
 function RecicedProductList( allProducts : List.<StoreKitProduct> ){
     
    Debug.Log( "received total products: " + allProducts.Count );
    _products = allProducts;
  
 }

I simply missed the brackets off at the end of the _products List.

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

Answer by flamy · Jun 29, 2013 at 07:39 PM

 function Start()
 {
     StoreKitManager.productListReceivedEvent += RecicedProductList;
 }
 
 
 function RecicedProductList( List<StoreKitProduct> allProducts/* add parameter according to the "productListReceivedEvent"'s delegate)
 {
    Debug.Log( "received total products: " + allProducts.Count );
    _products = allProducts;
   
 }


I havent tested this code but 99% it should work. Also i added parameter thinking that it is Prime31 plugin.. hope im right!!

Comment
Add comment · Show 5 · 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 oliver-jones · Jun 29, 2013 at 09:51 PM 0
Share

I've done this:

 function RecicedProductList( allProducts : List.<Store$$anonymous$$itProduct> )
 {
    Debug.Log( "received total products: " + allProducts.Count );
    _products = allProducts;
  
 }

I get this error: Cannot convert SystemCollectionsGenericList to System.Type?

avatar image oliver-jones · Jun 29, 2013 at 09:52 PM 0
Share

Which is weird because both _products and allProducts are 'List.'

avatar image clunk47 · Jun 30, 2013 at 03:48 AM 0
Share

Was going to say remove the dot from list, but that's me thinking C#... Don't know list in javascript lol

avatar image flamy · Jun 30, 2013 at 04:12 AM 1
Share

same thing... i even typed and deleted lol

avatar image clunk47 · Jun 30, 2013 at 04:56 AM 0
Share

haha nice

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

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

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Animated camera problems 0 Answers

The best place to learn Javascript/C# 1 Answer

Translating js to c#, getting NULLReferenceExeption 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