I have a custom class called SaveData that is made up of four strings. I have an array of SaveData called loadEntries, and I want to iterate through each one and access the strings to compare them to something else. I’ve done a lot of reading about closure in unityscript the past few days (there’s obviously a lot of content around here), but I haven’t found a way to handle this. Most examples seem to only deal with printing out the value of each single entry, and don’t work for my purposes. Here’s what I have so far, which won’t compile (I understand why it won’t, but I don’t understand how to make it work):
function Update() {
for (var entry : SaveData in loadEntries) {
entry = extractData(entry);
//logic with "entry" members
}
}
function extractData(entry : SaveData) {
return function(entry : SaveData) { var myEntry = entry; };
}
Do I need to use closure with each member of SaveData instead of the whole entry? Is this method even possible?
Thanks to closure for the detailed answer, and he was correct in that it did not have any issues with scope. However, I came back to this problem, and found out it arose because my custom class “SaveData” was made up of static declared strings. Since they were static, only the final result was being saved. I’ll leave the question up in case anyone makes the same mistake I did.