so after much searching im a bit confused on how to make a dictionary in java. And also not sure if it would accept a <int, array>. basically im trying to create arrays that hold rows of units, created all at runtime, cause the amount of rows can change.
If anyone could shed some light on my ignorance, or point me in the right direction, I’d be much obliged…
Dictionary isn’t declarable in jacascript syntax. You will have to use an alternative such as a Hashtable.
Not actually true:
import System.Collections.Generic;
var myDictionary : Dictionary.<int, String>;
By the way, Unity doesn’t use Java. It uses Unityscript, sometimes called Javascript. Java is a different language, and it’s not an abbreviation for Javascript.
As for <int, array>, what do you mean by array? The Array class is obsolete and shouldn’t be used, but you can use a List or built-in array (i.e., int[ ], float[ ], etc.).
–Eric
Eek sorry, I thought I read that it wasn’t supported somewhere official, I guess I should do my research properly! Pretty silly given that I am well aware of the . syntax :s
thanks for the replies! an ya i know that unityscript is not really java, but more of a .net wrapper or somesuch?
but back to the question at hand: if i use hashtable what is the syntax for javascript? cant seem to find it.
@eric, i use builtin arrays an lists most of the time but for this i want to use like a nested list. so that listA[0] = listB, listA[1] = listC etc… if that makes sense… hope it does, typing on a phone thats about dead so kinda rushed it
The point is actually that Javascript and Java are two different things.
You don’t need to use Hashtable; you can use Dictionary, which is much better.
You can have a List of Lists, if that’s what you mean. Note that the JS compiler has a weird bug where you can’t write something like “var foo = new List.<List.>();”, you have to write “var foo = new List.<List. >();” (note the space).
–Eric
ahh thanks, the page i pulled up when i was lookin for stuff said
using System.Collections.Generic
explains why it didnt work…
thanks everyone! always enjoy learnin from your posts eric.