06-22-2014 07:51 PM
I am working on a Unity Script that uses key-value pairs. I wrote my logic using vb.net in Visual Studio and used a Collection, however when I tried the same thing in the Unity Script editor, it does not understand what a Collection is. I tried using a Dictionary instead and can only get it to work if I use: System.Collections.Generic. No matter what I use from there I can't get the Dictionary or any of the Collection options to work for me.
In Visual Studio, my code looked like this and allowed me to add key value pairs then loop through them to compare them to other values, none of which works in the Unity editor:
Dim things As Collection = New Collection things.Add("keyVal1", "something")
I also tried this in the Unity Editor after adding System.Collections.Generic:
Dim things as New Dictionary(Of String, String)
using this, the code editor is not giving me the option to use ".add" or ".Contains" again both of which worked for Collections in visual studio.If it is letting me use ".add" the script editor is not showing it when i type. ".Contains" throws an error.
Any help as to where I'm going wrong here would be much appreciated.
06-23-2014 05:15 AM
I haven't done VB in awhile (mainly c#) but there are usually 2 things I have to do in the Unity Script Editor.
I usually have to ensure that I add my references in the right side menu, as well as in the code.
06-23-2014 05:38 AM
It looks like the Collection class is in the Microsoft.VisualBasic namespace. In order to use it in your VBScript, add a reference to that assembly in your Unity Project and add an Imports statement for that namespace.
06-23-2014 09:28 AM
Thanks for the response guys, I'm sure what you posted would work.. I'm making the move to C# asap as it appears to be better for Unity Scripting in general or at least more people use it. Just not for this project.
Prior to your responses, I switched over to ListDictionary which appears to function like a collection. I'm testing it right now, but if you know any important differences, I'm all ears before I go too far along this path.
06-23-2014 09:58 AM
I've noticed the Unity Script editor is kind of lacking in terms of Intellisense. Most often if it doesn't show something in the list of properties and methods and you know it should be there, it will compile and run just fine. If it has a problem with what you are using, it will tell you when you attempt to build it.
I've had no issues using a Dictionary object's .Add() method even though it doesn't show up.
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.