My choose levels wont update themselves without a refresh!

I have a chooselevel.lua which contains all the levels of my game, and in order to unlock the next level you must complete the last, and this is working TO AN EXTENT, how ever my problem is that whenever you complete a level the next level doesnt unlock until you close and reopen the app. 

Any one know how to fix this? how to get my chooselevel file to update itself without having to refresh the entire app?

Hi @hkrissansen,

I assume you are just require()-ing the “chooselevel.lua” file once, and then it executes? By design, Lua will only execute modules on the first run. If you’re not already doing so, I suggest that you build a function inside of that module which you can call anytime you need to update/unlock levels. On startup of the app, require() the module and then call that function initially, then later, call it again when necessary.

Hope this helps,

Brent

I’am working on the app with hkrissansen, how would we build a function that does this, maybe an example if possible?

Cheers

Hi @darkspike119,

A common way to set up Lua modules is to “bundle” various functions inside a table of that module, then return the table. In that way, you’ll gain access to the function within.

This is a very basic example where you have an external module and you make it accessible from another module or main.lua, and you also gain access to the function within the external module:

chooselevel.lua

[lua]

local M = {}

function M.unlockLevel( levelNum )

    – your code/process to unlock level number of ‘levelNum’ value

end

return M

[/lua]

main.lua

[lua]

– require() the external module

local levelModule = require( “chooselevel” )

– set a local variable for the function in the external module

local unlockLevelFunction = levelModule.unlockLevel

– call the function in the external module

unlockLevelFunction( 2 )

[/lua]

Thanks for Brent! I should have mentioned before that we are using the ogt level manager provided by J A Whye

Hi @darkspike119,

Does my previous answer help you? Unfortunately I can’t assist you with the level manager from J A Whye, since I don’t know what it does internally. You may want to contact him about it, or see if he has provided support or documentation on it.

Best regards,

Brent

Hi @hkrissansen,

I assume you are just require()-ing the “chooselevel.lua” file once, and then it executes? By design, Lua will only execute modules on the first run. If you’re not already doing so, I suggest that you build a function inside of that module which you can call anytime you need to update/unlock levels. On startup of the app, require() the module and then call that function initially, then later, call it again when necessary.

Hope this helps,

Brent

I’am working on the app with hkrissansen, how would we build a function that does this, maybe an example if possible?

Cheers

Hi @darkspike119,

A common way to set up Lua modules is to “bundle” various functions inside a table of that module, then return the table. In that way, you’ll gain access to the function within.

This is a very basic example where you have an external module and you make it accessible from another module or main.lua, and you also gain access to the function within the external module:

chooselevel.lua

[lua]

local M = {}

function M.unlockLevel( levelNum )

    – your code/process to unlock level number of ‘levelNum’ value

end

return M

[/lua]

main.lua

[lua]

– require() the external module

local levelModule = require( “chooselevel” )

– set a local variable for the function in the external module

local unlockLevelFunction = levelModule.unlockLevel

– call the function in the external module

unlockLevelFunction( 2 )

[/lua]

Thanks for Brent! I should have mentioned before that we are using the ogt level manager provided by J A Whye

Hi @darkspike119,

Does my previous answer help you? Unfortunately I can’t assist you with the level manager from J A Whye, since I don’t know what it does internally. You may want to contact him about it, or see if he has provided support or documentation on it.

Best regards,

Brent