[solved]How do I send real time alerts to my app?

0 favourites
  • 10 posts
From the Asset Store
Create your own casino app and import it to Google Play and the App Store.
  • I'm not sure if the title is worded clearly. I'll try to explain.

    I want to be able to trigger alerts within my app by reading a file hosted on a server. So, I obviously have no idea how this would be implemented but I'm hoping it'd work like this...

    Let's say I want to inform people playing my game of a new app I am releasing, or tell them that there is an update available. To do this I will first compile my game with a hidden layer with a text box on there. Then from my computer I can type up the text I want to be displayed into a text file or wherever it needs to be and upload it to my server. Then everytime the app loads it checks to see if this txt file or whatever it may be is present and if so it then displays this hidden layer and sets a text box to the contents I uploaded from my computer.

    I'd like to think it would be as simple as the below, although I'm sure it won't be lol

    Condition:

    On start of layout

    Action:

    Check is file "alert.txt" at "http://www.whatever.com" present

    Condition:

    File "alert.txt" is available

    Action:

    Set layer "alert" to visible

    Set Text to contents of "alert.txt"

  • Yes, it is possible, and the method would be almost that of above, it doesn't even need to be a webserver you own, just use dropbox or something. You can use the AJAX object in C2. I have created an example, see attached.

  • Thanks! That's exactly what I need!... Merry Christmas

  • briggybros one more question...

    I know I could use webstorage/global variable to ensure an alert message is only shown to a player once but is it possible to go one further and have the app also check if previous the text file is edited to then display latest alert. Is it possible to check for any changes?

    So in other words I don't want the same old alert to load every time a user opens the app, but I do want it to display the popup if the text file changes so I can be sure the user sees the latest alert.

    I hope I've described that properly.

  • This can be done in many ways. The very first thing that comes to mind is storing the most recent alert and then checking if the alert has changed since then. If your alerts are long then this might take up some space. A simple remedy to this would be to assign every message with an id and store the most recent id. Your txt file could look something like:

    1|Don't forget to like this on Facebook[/code:2j1kgoa3]
    
    or anything you want. Note the '1' and the '|' we can use the system expression
    
    [code:2j1kgoa3]tokenat(src, index, separator)[/code:2j1kgoa3]
    
    with src as the txt file as returned by AJAX, index being 0 and separator being '|', this will return purely the id of the alert. Make sure the message does not contain a separator character.
    
    This value can then be stored using webstorage. Every time you make an update, increment the id by 1 and then change the message keeping the separator in place. Simply create a condition where if the id retrieved is not equal to the value stored, display the message retrieved (by replacing index with 1 instead of 0) and then update the stored value to the one retrieved.
  • briggybros thanks so much for your help! I really appreciate it. I understand the concept of what you're saying above but I'm not 100% sure how to implement it correctly, I've tried. I got ajax alert implemented no problem but am struggling with your latest reply.

    Are you please able to throw a couple events together in a capx for me demonstrating how it would work please, like you did for the first example? That'd be a huge help! Thanks again.

  • briggybros or anyone else?! I'm still having difficulty implementing the second part of your response. Are you able to break it down for me a little more. I'd really appreciate the help.

  • To summarise the capx attached the alert.txt file has the contents:

    1|This is your first alert
    {id}|{alert}[/code:2u0ozydp]
    Using the first example, this is what will be returned. However, using the attached example only:
    [code:2u0ozydp]This is your first alert[/code:2u0ozydp]
    will be returned and will only be returned once. This is because the id of the alert has been stored.
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • briggybros thanks so much for your help. Really appreciate you taking the time to build an example capx.

  • You're welcome!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)