Downloading one line of news text to display in app

Hiyas!
I searched the forum but didn’t find a good way to do this.
I just want a file on a server… something like:
news.txt
with one line of the news headline:
News update: Don’t forget our free giveaway!

Something like that. Do I download the file to a tmp dir and extract the text out and assign it to a variable or is there an easy way to do this?
TIA :slight_smile: [import]uid: 10389 topic_id: 17893 reply_id: 317893[/import]

easiest way how about ,

http://developer.anscamobile.com/reference/index/displayloadremoteimage

or you want only on text? [import]uid: 12482 topic_id: 17893 reply_id: 68291[/import]

You could use the network.request

Here is an example of creating a variable named News and then setting it depending on the info from the webpage.

local News  
  
local function networkListener( event )  
 if ( event.isError ) then  
 News = 'Could not load news'  
 else  
 News = event.response  
 end  
 print(News)  
end  
   
network.request( "http://yourwebsitename.com/news.txt", "GET", networkListener )  

This gets the response from the website and sets the News variable with the data, if its an error it just sets the news to Could not load news, if its not an error it sets it to whatever is in the news.txt file. Then it prints out the News variable. You could change it so it so that a newText display is created and displays the News variable on your app to the user.

The info for network.request can be found here [import]uid: 69700 topic_id: 17893 reply_id: 68295[/import]

Thanks, ertzel. I did see that page but wasn’t sure if it’d do the job! Just what I wanted! :slight_smile: [import]uid: 10389 topic_id: 17893 reply_id: 68345[/import]

also you could check out this module: http://developer.anscamobile.com/code/promotion-library

cheers… [import]uid: 11686 topic_id: 17893 reply_id: 68358[/import]

Does anyone know if there’s caching involved with this method from @ertzel ?

I updated the news on the website and the news headline is updated:
“Giveaway - Tech Webcast mousepad”

but if I view it on my phone it has an old news headline from earlier today.
How on earth can my app download an old one?
Maybe there’s some weird caching going on somewhere… hmm.

If I start my app on the iPhone the news headline it says “Tech Webcast Giveaway - TShirt”. [import]uid: 10389 topic_id: 17893 reply_id: 69290[/import]

I am not sure if there is some kind of caching involved… but anyway, you can always get rid of caching by using a slightly modified (randomized) version of url request i.e:

local rnd = math.random(1024\*1024) network.request( "http://yourwebsitename.com/news.txt?"..rnd, "GET", networkListener ) [import]uid: 11686 topic_id: 17893 reply_id: 69333[/import]

I’m not 100% sure but I think that worked! :slight_smile: [import]uid: 10389 topic_id: 17893 reply_id: 69343[/import]

Thanks ertzel the code works well as is

@Waulok - The issue with the caching, did that only happen on the device? I am running in the simulator and when I edit the file on my website it changes the text in the simulator. [import]uid: 31262 topic_id: 17893 reply_id: 71126[/import]

I think it was intermittent. [import]uid: 10389 topic_id: 17893 reply_id: 71179[/import]