Functions are bad for picking. For the first problem area, you'll need to move the events up to the for each for it to refer to each isotile in turn, assuming that's what you want.
For the second problem area where it's in a function within a function, you can send the isotile UID through IsoSort as a parameter, and on IsoSort function reference IsoTile where IsoTile.UID = function.param(0). As it stands, it does not refer to any particular IsoTile.
And just as final clarification, it runs everything in the for each loop first, so runs through those isotile creations, then moves down to event 24 and beyond without any specific isotile picked. Not sure on what the logic is doing, specifically the meaning of the perspective variable but that should hopefully give you some idea.