Simulator bug?

Hello,

I’m new to Corona and am having a problem wherein I use require.<filename> to navigate to a file, then require.<filename> on that file to come back to the orginal one which works fine, but then when you click to go back again to the second file screen is blank! Is this a simulator problem? Or am I not clearing something from memory perhaps? Any ideas welcome…

Thanks

MD

Hi @MD,

I think you’ll need to post some code related to this so the community can get a better sense of your current implementation.

Thanks,

Brent

P.S. - Please remember to surround your code with “lua” tags for clarity:

[lua] -- [/lua]

Hi Brent,

Thanks for the response, here’s the code; to give you an idea: it’s an app to learn Arabic through clicking on words to see them translated, or double-clicking to see words derived from a root word, so in the below code the user is going between two lua files - home.lua with the root words and qaala.lua with derivations of qaala (to speak).

I’ve highlighted in red the two lines in each file that do the naviagtion using ‘require’. All works fine to go from home.lua to qaala.lua then back again, but upon going into qaala.lua again the screen is blank. 

home.lua file:

[lua]

local function qaalaTapListener ( event )

    if ( event.numTaps == 2 ) then

        require(“verbs.qaala”) – calls word script 

    else 

    return true

    end

display.remove( textGroup )  – clear text from screen

display.remove( buttonGroup ) – clears buttons from screen

buttonGroup = nil

textGroup = nil

end

[/lua]

qaala.lua:

[lua]

local function homeTouchListener( event )

    if ( event.phase == “began” ) then       

        display.remove(directionsText)

        directionsText = nil

        display.remove(buttonGroup)

        buttonGroup = nil

        require(".home") – takes user back to screen with root words

    end

    return true  --prevents touch propagation to underlying objects

end

[/lua]

Also: just tested on an Android device and it throws an error when user clicks to go back to home.lua from qaala.lua (which works fine in simulator):

[lua]

require(".home") – takes user back to screen with root words

[/lua]

error: module ‘home’ not found: resource (home.lu) does not exist in archive

no field package.preload[’.home’]

Thanks for your time! And sorry if I’m making simple errors - am an amateur and haven’t coded in a while!

First you need to leave the dot off of the front:  require(“home”) not require(".home").   Next we still don’t know what verbs.qaala and home does.  Are they Composer scenes?  Have you written your own scene manager?

Normally you require modules that return some object that you access.  We still need to know more about what you’re doing.

As for the [lua] and [/lua] tags, you’re not doing that correctly.  Type an opening bracket followed by lua and close the bracket (no spaces) and then at the end do the same with /lua.  Or its easier to highlight the code and click on the <> symbol in the editing button bar above!

Rob

I started off trying to use Composer scenes but found it tricky - so have been simply using require to go between scenes which could be why it’s not working properly?

Could be time to revisit Composer then - can you recommend a good tutorial?

Thanks for your patience!

MD

Maybe start  here:   https://coronalabs.com/blog/2015/04/14/tutorial-the-basic-game-template/

It’s a complete game template.  The only objects in the game are buttons to move between scenes, but it should demo how to do things correctly.  The important thing is when looking at a Composer scene file, all the parts except the buttons have to be there.  You can change the content of the various event functions but don’t take them out.  There is nothing in these files that can be removed.

Rob

Thanks Rob will give it a go.

Hi @MD,

I think you’ll need to post some code related to this so the community can get a better sense of your current implementation.

Thanks,

Brent

P.S. - Please remember to surround your code with “lua” tags for clarity:

[lua] -- [/lua]

Hi Brent,

Thanks for the response, here’s the code; to give you an idea: it’s an app to learn Arabic through clicking on words to see them translated, or double-clicking to see words derived from a root word, so in the below code the user is going between two lua files - home.lua with the root words and qaala.lua with derivations of qaala (to speak).

I’ve highlighted in red the two lines in each file that do the naviagtion using ‘require’. All works fine to go from home.lua to qaala.lua then back again, but upon going into qaala.lua again the screen is blank. 

home.lua file:

[lua]

local function qaalaTapListener ( event )

    if ( event.numTaps == 2 ) then

        require(“verbs.qaala”) – calls word script 

    else 

    return true

    end

display.remove( textGroup )  – clear text from screen

display.remove( buttonGroup ) – clears buttons from screen

buttonGroup = nil

textGroup = nil

end

[/lua]

qaala.lua:

[lua]

local function homeTouchListener( event )

    if ( event.phase == “began” ) then       

        display.remove(directionsText)

        directionsText = nil

        display.remove(buttonGroup)

        buttonGroup = nil

        require(".home") – takes user back to screen with root words

    end

    return true  --prevents touch propagation to underlying objects

end

[/lua]

Also: just tested on an Android device and it throws an error when user clicks to go back to home.lua from qaala.lua (which works fine in simulator):

[lua]

require(".home") – takes user back to screen with root words

[/lua]

error: module ‘home’ not found: resource (home.lu) does not exist in archive

no field package.preload[’.home’]

Thanks for your time! And sorry if I’m making simple errors - am an amateur and haven’t coded in a while!

First you need to leave the dot off of the front:  require(“home”) not require(".home").   Next we still don’t know what verbs.qaala and home does.  Are they Composer scenes?  Have you written your own scene manager?

Normally you require modules that return some object that you access.  We still need to know more about what you’re doing.

As for the [lua] and [/lua] tags, you’re not doing that correctly.  Type an opening bracket followed by lua and close the bracket (no spaces) and then at the end do the same with /lua.  Or its easier to highlight the code and click on the <> symbol in the editing button bar above!

Rob

I started off trying to use Composer scenes but found it tricky - so have been simply using require to go between scenes which could be why it’s not working properly?

Could be time to revisit Composer then - can you recommend a good tutorial?

Thanks for your patience!

MD

Maybe start  here:   https://coronalabs.com/blog/2015/04/14/tutorial-the-basic-game-template/

It’s a complete game template.  The only objects in the game are buttons to move between scenes, but it should demo how to do things correctly.  The important thing is when looking at a Composer scene file, all the parts except the buttons have to be there.  You can change the content of the various event functions but don’t take them out.  There is nothing in these files that can be removed.

Rob

Thanks Rob will give it a go.