Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 superluigi · Aug 31, 2015 at 01:11 AM · hashtablec# to javascript

Help converting this C# line to UnityScript

 score= (int)PhotonNetwork.room.customProperties[Score];

customProperties[Score] is referring to a key in a hashtable with an int as its value. What this line is doing is making the variable int score equal the int value of the key Score in a hashtable. I have never seen = (int) before but it kinda explains itself. Anyway how can I convert this to UnityScript, or better yet how can I retrieve the value of a key from within a hashtable because I've been trying to achieve this for the past 2 days.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Sep 01, 2015 at 12:36 AM

The "(int)" is an explicit cast in C#. In C# such a cast is required if the value type you want to assign is of a more general type as the variable. For value types like int and float there is only one base-type: object.

So i guess that "customProperties" is an untyped Hashtable which contains "object" values. In UnityScript there is no explicit cast for value types. The compiler does this automatically for you. So if your target variable is of type "int" you can simply assign your value to it and the compiler will cast the value automatically:

 var score : int;
 
 // [...]
 score = PhotonNetwork.room.customProperties[Score];

Since we declared the score variable as an int, the compiler will automatically try to cast the value into an int.

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 IHackedDeath · Aug 31, 2015 at 04:35 AM

Hello superLuigi,

I am assuming you already use unity and this is a script that comes with Photon Network.

There are 2 ways you could do this.

Have your score become a public variable and you can change it in the editor or, Create a new public Int and then have score equal that new Int.

There are a lot of ways things like this can be done.

If you could provide some more details like what its for, or other scripting or even if this is from another platform or engine then I could provide some more assistance.

Kind Regards,

IHackedDeath.

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 superluigi · Aug 31, 2015 at 07:42 PM 0
Share

This script actually comes with a tutorial called Sky Arena that uses Photon. What I'm trying to achieve is have all 4 players associate the correct client(player) with the correct player#. If I create the room I have a photon ID of 1, the next person ID 2, etc. However, if player two leaves and rejoins he is now ID 3, photon doesn't reuse ID's. When you create a room in Photon you can store customProperties that all clients in the room can see. These customProperties have to be a hashtable, so I have a hashtale with p1, p2, p3, & p4 as keys and int's as values. The int will equal a player's ID. I want to use something like

player2 : PhotonPlayer;

p2int = (int)PhotonNetwork.room.customProperties[p2];// I want the int value of p2's key player2 = PhotonNetwork.room.Find(p2int);

avatar image
0

Answer by Scribe · Aug 31, 2015 at 05:23 PM

You can create a hashtable in js. then read from that, so assuming youhave got the Dictionary 'PhotonNetwork.room.customProperties', the following should work:

 var hash : Hashtable = new Hashtable(PhotonNetwork.room.customProperties);
 score = parseInt(hash[Score]);

I would suggest only setting that variable at the start and then if the values change, as it would prompt GC.

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 superluigi · Aug 31, 2015 at 07:43 PM 0
Share

I get the error: "Ambiguous reference 'parseInt':". I don't think Unity recognizes parseInt. Also, parseInt seems like it turns a string into an int. I'm not 100% sure of this since I've never come across parseInt before, but if that's what it's doing then it won't really help my problem. What i want is to get the value of a key in a hashtable

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

30 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 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

Custom class and hashtable 1 Answer

Dictionary vs Hashtable 1 Answer

How to call value by key when key is an object? 1 Answer

Can you Help me about how to get the variable of Java Script to C# script? 2 Answers

From Java to C# help 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