Trouble managing display objects across scripts

So, I’ve written a script that takes in a string, breaks it down into individual characters, queues up frame-by-frame animation of the writing of said characters, and then makes the first item in the animationQueue display group visible every 7 frames. After making the item visible, it transfers the item into a second display group named visibleLetters (thus shifting everything in the animationQueue group down 1 position). After the entire string has been animated, it returns the visibleLetters group. I can’t seem to find a way to remove an element that has been drawn, however. I’ve tried two ways of assigning the returned group:

[lua]myNewGroup = display.newGroup();
myNewGroup:insert(wordAnim.animateString(parameters));[/lua]

[lua]myNewPointer;
myNewPointer = wordAnim.animateString(parameters);[/lua]

In either case, when I attempt to remove the images drawn, it doesn’t seem to work. After reading up a bit I’m thinking that the images may still have a reference somewhere that is preventing them from removing, but i can’t seem to find where. Is it the visibleLetters group? I assumed that once the program left the wordAnimation script, the visibleLetters group would cease to exist in memory until the next time the program entered it, but I’m not really sure on that.

Ways i’ve tried removing:
[lua]for i = myNewGroup.numChildren, 1, -1 do
local child = myNewGroup[i];
child.parent:remove(child);
child = nil;
end[/lua]

[lua]myNewPointer = nil;[/lua]

I’ve tried several variations of each, to no avail. If someone has a guess as to what may be going on I would greatly appreciate it :). [import]uid: 117794 topic_id: 24546 reply_id: 324546[/import]

Just to check that the visibleLetters group really is empty could you please try doing a print statement? Eg;
print(visibleLetters.numChildren) [import]uid: 52491 topic_id: 24546 reply_id: 99457[/import]

Since visibleLetters is local to the worldAnimation.lua script file, I can’t print it’s numChildren from the main.lua file that way (it thinks I’m trying to access a nil, undeclared global when I do). I also can’t print it at the right time from the wordAnimation.lua script file, because lua gets mad if you try to do something right after a return statement. I did try this way, though, right after some string animations:

[lua]print(wordAnim.getVisibleLetters().numChildren);[/lua]

Which printed 0. [import]uid: 117794 topic_id: 24546 reply_id: 99505[/import]

Okay I think I’ve narrowed down what is happening. I’m still brainstorming on a solution, though. Using some print statements in my wordAnimation script, I found that the visibleLetters group didn’t contain any children when it was being returned. That led me to suspect that the function was returning visibleLetters before the update function had actually gone through and animated all the frames from the animationQueue, and thus added them to the visibleLetters group. Sure enough, a print of visibleLetters.numChildren within the update function counted up to quite a few. Any ideas on how to add a delay before the group gets returned? [import]uid: 117794 topic_id: 24546 reply_id: 99660[/import]

The only thing to spring to mind is to handle it manually with timer.performWithDelay, although admittedly it’s hard to picture everything working together in my head. (I have an idea of what you are doing but imaging others projects isn’t always easy ;)) [import]uid: 52491 topic_id: 24546 reply_id: 99710[/import]

Yeah my first thought was to use timer.performWithDelay, but I’ve been trying to think of a better solution, because determining exactly how much time each animation needs seems sketchy at best. I appreciate all your input so far peach :slight_smile: I know it’s difficult to visualize the implemenation of other people’s projects :). I’m probably just going to have to come up with a good equation that gives me the required time for each call so that I can time the returns right. [import]uid: 117794 topic_id: 24546 reply_id: 99786[/import]