Hi. I have more experience with PHP than javascript and I’m trying to wrestle javascript into doing what I want.
What I’m doing is reading a text file with each line formatted like this : “name@description”. Now I want to have the first part before the “@” as a “key” and the second part as the value, but I just can’t get it to work. What I want is an array that looks lite this:
myArray[“bob”] == “value1”
myArray[“frank”] == “value2”
myArray[“pete”] == “value3”
myArray[“abaddon”] == “value4”
… so that I can access the value for for examle “bob” by doing this : pickedName = myArray[“bob”] and get ‘pickedName = “value1”’.
I realize that this is a noob question, which makes it even more frustrating. How would I do this? Here’s my code so far:
var objectdescriptions : TextAsset;
internal var lines : String[];
internal var splitthoughts;
var CleanDescriptions = {};
function Start()
{
lines = objectdescriptions.text.Split("\n"[0]);
for (line in lines)
{
splitthoughts = line.Split("@"[0]);
if (splitthoughts[0] != '')
{
CleanDescriptions[splitthoughts[1]] = splitthoughts[0];
print(CleanDescriptions[splitthoughts[0]]);
}
}
}
Thanks!