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

Get help using Construct 2

Post » Wed Dec 24, 2014 7:18 pm

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"
Last edited by FredQ on Thu Jan 01, 2015 7:44 pm, edited 1 time in total.
ImageImage
Mr. Green - Platform/puzzle game out now!
B
25
S
7
G
1
Posts: 222
Reputation: 3,350

Post » Thu Dec 25, 2014 12:28 am

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.
You do not have the required permissions to view the files attached to this post.
Nothing goes unanswered!
B
24
S
5
G
1
Posts: 434
Reputation: 3,446

Post » Thu Dec 25, 2014 2:15 pm

Thanks! That's exactly what I need!... Merry Christmas :)
ImageImage
Mr. Green - Platform/puzzle game out now!
B
25
S
7
G
1
Posts: 222
Reputation: 3,350

Post » Thu Dec 25, 2014 7:21 pm

@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.
ImageImage
Mr. Green - Platform/puzzle game out now!
B
25
S
7
G
1
Posts: 222
Reputation: 3,350

Post » Thu Dec 25, 2014 11:48 pm

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:

Code: Select all
1|Don't forget to like this on Facebook


or anything you want. Note the '1' and the '|' we can use the system expression

Code: Select all
tokenat(src, index, separator)


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.
Nothing goes unanswered!
B
24
S
5
G
1
Posts: 434
Reputation: 3,446

Post » Fri Dec 26, 2014 4:04 am

@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.
ImageImage
Mr. Green - Platform/puzzle game out now!
B
25
S
7
G
1
Posts: 222
Reputation: 3,350

Post » Sat Dec 27, 2014 5:20 pm

@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.
ImageImage
Mr. Green - Platform/puzzle game out now!
B
25
S
7
G
1
Posts: 222
Reputation: 3,350

Post » Thu Jan 01, 2015 6:49 pm

To summarise the capx attached the alert.txt file has the contents:
Code: Select all
1|This is your first alert
{id}|{alert}

Using the first example, this is what will be returned. However, using the attached example only:
Code: Select all
This is your first alert

will be returned and will only be returned once. This is because the id of the alert has been stored.
You do not have the required permissions to view the files attached to this post.
Nothing goes unanswered!
B
24
S
5
G
1
Posts: 434
Reputation: 3,446

Post » Thu Jan 01, 2015 7:44 pm

@briggybros thanks so much for your help. Really appreciate you taking the time to build an example capx.
ImageImage
Mr. Green - Platform/puzzle game out now!
B
25
S
7
G
1
Posts: 222
Reputation: 3,350

Post » Thu Jan 08, 2015 12:49 am

You're welcome!
Nothing goes unanswered!
B
24
S
5
G
1
Posts: 434
Reputation: 3,446


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 48 guests