Hey
I am creating a huge app in Corona SDK and I need to create a lot of external modules for different purposes like Urban Airship, connections to our .NET Server Library and so on… One of my greatest issues now is that I need to be able to call a function inside an external module and have that listener inside that function return the value back to the calling script.
This is my code…
main.lua and here I include the smart library as global, correct?
[lua]smart = require(“smartfunctions”)[/lua]
products.lua and here I need to present some strings that should be retrieved from network and displayed correctly…
[lua]local headline = display.newRetinaText(smart.getText(“proHeader”,“SE”), 10, 35, native.systemFontBold, 16)[/lua]
So I made a function called getText and that function is placed inside the smartfunctions.lua as below and it takes two arguments, textID and langaugeID and should return the string I get back from the server.
smartfunctions.lua
[lua]module(…, package.seeall)
– smartfunctions.lua
– version 1.0
– Updated by Andreas Kviby, 10Fingers AB
– *********************************************************
function netTextListener( event )
if ( event.isError ) then
returnString = “”
else
returnString = event.response
end
print ("The returning text should be " … returnString)
return returnString
end
function getText(textID, languageID)
print("get network text: " … textID … " in language " … languageID)
if (languageID == nil) then
languageID = app.languageID
end
– Get the text requested and return it through the listener
network.request( app.netWorkTextURL … “?languageID=” … languageID … “&textID=” … textID… “&appWebID=” … app.appWEBID, “GET”, netTextListener )
end[/lua]
The print line inside the networklistener is printing the correct value from our servers but I can’t make the getText function to return that string because it ends inside the listener. Please help me get this work. [import]uid: 22737 topic_id: 20989 reply_id: 320989[/import]