switching a flag remotley from a webserver

Hi,

say for example I have a game that contains a simple flag true/false that would switch 2 ad serving networks.

So if switchAdNetworkFlag == true then “show ad network1” else "showAdNetwork2.

Now I figure I would need the game to check on startup using the network apis and query the webserver for the flag.

Rather like checking if youve bought the game/app in the stores.

I also figure I need no login info from the user and maybe no encryption, after all iam just retrieving a true or false.

Also is there a problem doing this with googleplay or the appstore which will be against their TOS etc?

I have read Robs post and a few others on ways to do this but looking for clarification, so any help much appreciated.

could you please move this to the “network forum” please apologies

In main.lua:

[lua]

function configListener(event) – listener to handle retrieval of config file from server

    if (event.isError) then

        print(“Network error!”)

    else

        local params = json.decode(event.response)

        print("GOT CONFIG FILE, VERSION: " params.config.version)

            if tonumber(params.config.showAds) == 1 then

                  if tonumber(params.config.adType) == 1 then

                                    – show ad type 1

                        else

                                    – show ad type 2

                        end

                  end

                       

    end

end

local config = “http://www.mydomainname.co.uk/config_file.cfg

network.request(config, “GET”, configListener)

[/lua]

A txt file called ‘config_file.cfg’ on your server, containing a json table:

[lua]

{

   “config” : {

“version”  : “1.0”,

     “showAds” : 1 ,

      “adType” : 2

  }

}  

[/lua]

Hi Nick,

this looks really good, I am going to give it a go later today and report back.

If I remember  correctly this is the second time youve helped me.

Thank you appreciate it.

No problem - it’s nearly lunch so I’m killing time :smiley:

A word of warning, I’ve occasionally had problems after editing the txt file on the server where Corona will suddenly decide it’s not valid json when it clearly is.

At that point, I’ve had to set up a new blank text file and copy the json table into that, delete the old one and rename the new one to the old name.

Also, sometimes the Corona Simulator seems to cache the file and not download the newly edited version. When that happens I remove or add the http:// before the web address so it forces a refresh.

You should also be able to just add a random value to the query string, and it should push the cache.

http://www.mydomainname.co.uk/config\_file.cfg?r=some\_random\_number

Best.

In main.lua:

[lua]

function configListener(event) – listener to handle retrieval of config file from server

    if (event.isError) then

        print(“Network error!”)

    else

        local params = json.decode(event.response)

        print("GOT CONFIG FILE, VERSION: " params.config.version)

            if tonumber(params.config.showAds) == 1 then

                  if tonumber(params.config.adType) == 1 then

                                    – show ad type 1

                        else

                                    – show ad type 2

                        end

                  end

                       

    end

end

local config = “http://www.mydomainname.co.uk/config_file.cfg

network.request(config, “GET”, configListener)

[/lua]

A txt file called ‘config_file.cfg’ on your server, containing a json table:

[lua]

{

   “config” : {

“version”  : “1.0”,

     “showAds” : 1 ,

      “adType” : 2

  }

}  

[/lua]

Hi Nick,

this looks really good, I am going to give it a go later today and report back.

If I remember  correctly this is the second time youve helped me.

Thank you appreciate it.

No problem - it’s nearly lunch so I’m killing time :smiley:

A word of warning, I’ve occasionally had problems after editing the txt file on the server where Corona will suddenly decide it’s not valid json when it clearly is.

At that point, I’ve had to set up a new blank text file and copy the json table into that, delete the old one and rename the new one to the old name.

Also, sometimes the Corona Simulator seems to cache the file and not download the newly edited version. When that happens I remove or add the http:// before the web address so it forces a refresh.

You should also be able to just add a random value to the query string, and it should push the cache.

http://www.mydomainname.co.uk/config\_file.cfg?r=some\_random\_number

Best.