adding function to groups

im using storyboard and so far so good, question,

is it possible to add functions to a group, so that upon changing a scene all my functions can be removed as well…how would that look in code if this is my function

function allDots()
    
for i=1,#myTable do
     dots[i] = display.newImage(myTable[i],math.random(30,x-100),math.random(30,y-100))
     dots[i].id=i;
     dots[i]:addEventListener(“touch”,Circle);
    
     end

lately ive been putting all my function outside the storyboard scenes functions eg… createscene, enterscene etc, because when i run my game it wont run if they are in the function so, it seems to me like you cant put functions inside the storyboard scene functions… is that right?

thanks

You don’t need to remove your functions.  The objects just hold pointer references to the functions location in memory and you can’t really remove code unless you un-require the entire module (which is what storyboard.removeScene() does).  Your code isn’t memory you need to worry about.

Other people think they need to remove all those touch handlers.  But if you think about it, if the object that your touching is gone, you can’t touch it can you?  No need to remove those either.   If your objects are all in the display’s “group”, then the only things you need to worry about removing are:  Runtime things, stopping physics, canceling timers and transitions, making sure audio that has onComplete listeners stop since that handler may not be around afterwards, any audio that you loaded in the scene you should dispose of and finally any native.* objects you create.

What you said makes a lot of sense but I have functions, like the one above, that create images how then do i insert those images into the groups so it removes them when i go back to a new or previous scene, so far i cant group:insert(object) only works for those displayed images using display.newImage inside the storyboard functions ,what about those random created images outside the storyboard functions,

You can put that function inside storyboard’s createScene and inside the for loop add each object to the scene’s group.

i did that and this is what i get

File: assertion failed!

Assertion failed!

stack traceback:
    [C]: ?
    [C]: in function ‘assert’
    ?: in function ‘getOrCreateTable’
    ?: in function ‘addEventListener’
    ?: in function ‘addEventListener’
    …rres APPs/myProjects/LevelBuilder copy 2/level03.lua:75: in function ‘allDots’
    …rres APPs/myProjects/LevelBuilder copy 2/level03.lua:145: in function ‘_listener’
    ?: in function <?:141>
    ?: in function <?:218>

Does a function named “Circle” exist and in scope where you are running that loop?

You don’t need to remove your functions.  The objects just hold pointer references to the functions location in memory and you can’t really remove code unless you un-require the entire module (which is what storyboard.removeScene() does).  Your code isn’t memory you need to worry about.

Other people think they need to remove all those touch handlers.  But if you think about it, if the object that your touching is gone, you can’t touch it can you?  No need to remove those either.   If your objects are all in the display’s “group”, then the only things you need to worry about removing are:  Runtime things, stopping physics, canceling timers and transitions, making sure audio that has onComplete listeners stop since that handler may not be around afterwards, any audio that you loaded in the scene you should dispose of and finally any native.* objects you create.

What you said makes a lot of sense but I have functions, like the one above, that create images how then do i insert those images into the groups so it removes them when i go back to a new or previous scene, so far i cant group:insert(object) only works for those displayed images using display.newImage inside the storyboard functions ,what about those random created images outside the storyboard functions,

You can put that function inside storyboard’s createScene and inside the for loop add each object to the scene’s group.

i did that and this is what i get

File: assertion failed!

Assertion failed!

stack traceback:
    [C]: ?
    [C]: in function ‘assert’
    ?: in function ‘getOrCreateTable’
    ?: in function ‘addEventListener’
    ?: in function ‘addEventListener’
    …rres APPs/myProjects/LevelBuilder copy 2/level03.lua:75: in function ‘allDots’
    …rres APPs/myProjects/LevelBuilder copy 2/level03.lua:145: in function ‘_listener’
    ?: in function <?:141>
    ?: in function <?:218>

Does a function named “Circle” exist and in scope where you are running that loop?