Jump to content


Photo

Using Playtomic API


  • Please log in to reply
43 replies to this topic

#1 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9281 posts
  • Version:Unknown

Posted 02 May 2012 - 06:20 AM

I spoke to a mobile HTML5 sponsor who recommended Playtomic to add highscores into HTML5 games. I've used it, and it's much more secure than my old method, so I thought I would post about it here.

Please note that Playtomic supports a lot of features, and I have not yet added them all into my "Davetomic" extension. I'm adding them as I use them, but it is rather simple to add so if you want me to add something just say so (so long as it is supported by Playtomic).

I've put together a little "Davetomic" pack you can download here: http://cl.ly/041r3u1A1a3N351o3o0A

Edit: Updated GEX found here: http://cl.ly/1L2h1b033W2l2q3r1E2m
Davetomic JS script is the same, but this updated file includes all of the currently supported functions in the GEX (was previously missing
Davetomic_submitscore()) and an updated version of the Playtomic API.

It has the extension GEX, and the two scripts inside the extension. One script is the Playtomic API (playtomic.js) and the other is the proxy script I wrote to use the API in GM (Davetomic.js). You should only need the GEX, but I have included the others for informational purposes, or in case you want to play with the scripts yourself (feel free).

You need to start by setting up an account at http://www.playtomic.com and then creating a game in that account.

Add the extension to your GMHTM5 project in the usual way.

On game load, call the function Davetomic_init(SWFID,"guid","apikey" ). The three arguments are given to you when you create your game in your playtomic account.

Calling this function sets up the other functions, and also logs a "view", so you can see how many people loaded up your game.

To submit a score, use the function: Davetomic_submitscore(pname, pscore, table)

pname is the player's name. pscore is their score. table is the name of the high score table. So if you had multiple highscore boards in the game, this would be the name of each board. Just make it up, ie "highscores". If it doesn't exist, it is created.

To show scores is a little more complicated. I'm not sure if it's possible to pass a JS array to GM, so I've made the script convert it into a format I'm familiar with: "Name1|Score1|Name2|Score2|Name3|Score3|" .

Start by calling the script Davetomic_getscores(table). table is the name of the highscore table used when submitting.
This function calls my secondary function crunchscores() which then converts it into the format I like. Unlike with my Davescores example, the game doesn't freeze when waiting for a response. That means you have to poll for it, checking a few times a second to see if the scores have been returned yet (Technically a callback function should be used, but I'm not sure how to trigger this in GM from an external script, or if it's even possible). You do this with Davetomic_pollscores(). This function returns "" if the scores are not ready, or "Name1|Score1|Name2|Score2|Name3|Score3|" etc if the scores are ready (so check for blank string until it is not blank, say, at intervals of 15 steps or so).

I use this GML script to separate them:
Spoiler

It assigns each section between |'s into the array explodearray[]. I wrote it many years ago so I'm sure it could be improved but it works.

Hopefully this is enough for you to get scores working. After initialising the Playtomic API, it also reports back every 30 seconds with any updated information. If you don't call any other functions then it just pings to report how long each user plays the game for. So from this basic setup, you get views, play time, and highscore boards.

The Playtomic API is outlined here: https://playtomic.com/api/html5
As far as I can tell, everything should be possible in GM, but I just haven't implemented it all.
Functions I have implemented:
Spoiler


Hopefully this helps you to get it all working, but if you need help feel free to ask. I haven't covered the extra functions but I think the Playtomic API documentation covers it pretty well. Good luck :)

Edited by Dangerous_Dave, 25 May 2012 - 10:26 AM.

  • 1

#2 Jack Indie Box

Jack Indie Box

    GMC Member

  • GMC Member
  • 1489 posts
  • Version:GM:Studio

Posted 02 May 2012 - 09:21 AM

good job man, i haven't made anything notable in html5 but that sure is useful for people that plan to make stuff with it!!
  • 0

#3 dukeraoul

dukeraoul

    GMC Member

  • New Member
  • 1 posts
  • Version:GM:HTML5

Posted 23 May 2012 - 02:17 PM

I'm having trouble submitting scores to Playtomic.

The Davetomic_submitscore(pname, pscore, table) function was not registered as a function in GM under the Davetomic.gex/Davetomic.js file, so I added it with arg0 as string, arg1 as double, arg2 as string.

The function (Davetomic_submitscore("Dude", 200, "Highscores")) doesn't seem to be sending any info to Playtomic. The game is showing up as being viewed, so it seems like the Davetomic_init function is working as expected...

Dangerous_Dave, if you could write a bit more about how you are successfully using Playtomic with GM, I would be very grateful.
  • 1

#4 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9281 posts
  • Version:Unknown

Posted 24 May 2012 - 05:30 AM

It looks like you are using it correctly, I'm not sure why it isn't working. Here is a GEX I just exported from a game in which it is working in: http://dl.dropbox.co...vetomic_old.gex

It's an older version, from before my recent updates, but it should work, as it works in the game I have it in.

It's got the highscore functions, but it's missing some of the others. Check if it works and let me know either way.
  • 0

#5 jonn

jonn

    GMC Member

  • GMC Member
  • 20 posts

Posted 24 May 2012 - 01:11 PM

I got the same error as dukeraoul, it doesn't take Davetomic_submitscore().
I tried the old verison of Davetomic, and it recognizes the function Davetomic_submitscore(), but it seems like it is only allowing one argument.

I dont get the view count going up either so i might just be messing it all up.(Edit: I get views now. havent changed anything, seems like playtomic is alittle slow)


Edit: Example project would be very helpful but thats only if you have the time and patient doing it.
Thanks for you work!

Edit2: Checking the extension from inside gamemaker the only functions I can see avaible is: Davetomic_init, _logplay, logmetric, _forcesend. I cant find _submitscore. This is in the new version.

Edited by jonn, 24 May 2012 - 07:39 PM.

  • 0

#6 jonn

jonn

    GMC Member

  • GMC Member
  • 20 posts

Posted 25 May 2012 - 09:40 AM

I seem to have fixed something, I added the the Davetomic_submitscore via gamemaker. It might not be time saving or sexy but it seems to work.

I right clicked the extension packages Davetomic.js inside game maker. Then add function. Give it name Davetomic_submitscore, and add three argument: argument0= string, argument1= double, argument2 = string.
  • 0

#7 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9281 posts
  • Version:Unknown

Posted 25 May 2012 - 10:23 AM

Sorry guys, I'm having trouble getting it working myself. I keep getting HTTP 500 errors (internal server error) when trying to even log a view in the example file I've made, but my older game works just fine. There seems to be a few other people getting these errors over the past few days (on the playtomic forum), so I'll try to find out whether it's something we are doing wrong, or if it's something on their end.

Here's an updated version which includes all the functions in the GEX, and also uses the most up to date Playtomic API (2.0, API in previous file is 1.8 I believe):

http://cl.ly/1L2h1b033W2l2q3r1E2m

If you get it to work with your own game credentials, let me know :)
  • 0

#8 jonn

jonn

    GMC Member

  • GMC Member
  • 20 posts

Posted 25 May 2012 - 01:09 PM

Man this is awsome! Glitches or not.

I can send highscores to playtomic, with the latest build you gave us aswell. It counts views as it should.
I havent tried fetching highscores yet.
  • 0

#9 jonn

jonn

    GMC Member

  • GMC Member
  • 20 posts

Posted 25 May 2012 - 02:16 PM

When you fetch the score from playtomic, your script fetches every highscore in that particular table right?
What if the table contains alot of names and scores?
Lets say i want a top 500 highscore list. Wouldn't it take alot of time getting it?

If one person get highscore placement 150. I would want to fetch highscores placement 145-155. Displaying the player that this is where you are and these people are close to you in highscore.

Is that possible with playtomic, or and is it possible to implement with your extension?
  • 0

#10 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9281 posts
  • Version:Unknown

Posted 25 May 2012 - 09:26 PM

Thanks for letting me know it's working for you! It's still not working for me, it's now returning HTTP 503 errors (service unavailable)... I might try creating new game credentials.

For returning scores, the default is 20 scores, but this can be changed. My scripts don't yet support it, but Playtomic does. It also supports choosing the number of scores per page, and selecting a page number, so if you wanted the top 500 scores, you would just show one page worth, and send another query when you wanted the next page.

Playtomic also has the ability to return the page that your score appeared on, but this requires a function I haven't yet implemented in the Davetomic extension. So if you submit the 1187th best score at 30 per page then it will show you page 39, scores #1170 - #1200. If you submitted the 1170th best score, it would still show you that same page (so you would only see the few scores below yours). I'm not aware of another way to do this.

The playtomic information for high scores (Leader boards) can be found here: https://playtomic.co...l5#Leaderboards
It should all be possible to implement in some way or another, once I get around to adding it to the Davetomic extension.

I will try to add the features mentioned above over the next few days, but it's not as simple as just making a wrapper function. The Playtomic scripts use things such as overloaded functions, and many options being set through one argument, which GM isn't really compatible with. I'll have to redesign how the functions work, to make them more compatible with GM. I'm not yet sure how much of a challenge that will be, but I'll try to let you know here if I'm not going to get it done within the next few days.

Edited by Dangerous_Dave, 25 May 2012 - 09:27 PM.

  • 0

#11 jonn

jonn

    GMC Member

  • GMC Member
  • 20 posts

Posted 26 May 2012 - 09:43 AM

If I understand you correct: your extension grabs the 20 first highscores? Not a issue at the moment at least.

My game broke done today. Everything worked great yesterday.
This morning I could log views, plays and send highscores. But not receive highscores.
I created a new game/api on playtomic, new id etc. Now I can only log views and plays. Cant send, and not receive.

Is it working for you now or is it still broken?
I found you post on playtomic forums. They say that the issue should be fixed 10 hours ago.

Edit: Now i'm getting "503 Service Unavailable"

Edited by jonn, 26 May 2012 - 09:57 AM.

  • 0

#12 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9281 posts
  • Version:Unknown

Posted 26 May 2012 - 09:57 AM

It's been intermittent for me. It worked at the time, then sometimes it wouldn't work, but refreshing it, it would work. Check the javascript console, to see what errors you are receiving. That can help to determine whether it's their issue or not.

It looks like it's been an issue over the last few days as they have been doing server upgrades, hopefully they will sort it out.

I have the new version of the Davetomic GEX mostly done, but I need to test it (to make sure it actually works), and I haven't been able to do that successfully so far. Hopefully the Playtomic guys work over weekends, or it may be at least next week before the issues get sorted.
  • 0

#13 jonn

jonn

    GMC Member

  • GMC Member
  • 20 posts

Posted 26 May 2012 - 10:11 AM

Good work on the new gex!

Yeah, hopefully they get up and running soon.

The errors I get from browser consoles are 503 on my new game (playtomic created about 11:00 CET, thats an hour ago).
And my "old-new" game (playtomic created at about 1030) gives me {"Status": 0,"ErrorCode": 2}.
And the one that worked yesterday and was broken this morning gave something I cant remember. I deleted that one at playtomic to see if a new api could fix the issue.

Edit: I bumped your thread at playtomics forums

Edited by jonn, 26 May 2012 - 10:12 AM.

  • 0

#14 ben0

ben0

    GMC Member

  • New Member
  • 24 posts
  • Version:GM:HTML5

Posted 10 August 2012 - 04:58 AM

@dangerous_dave just curious, which mobile html5 sponsor demanded playtomic integration?

i used to work at playtomic, and things occasionally don't work because when you've got 1 billion requests going though your servers very day, there's bound to be 0.001% of fails. That's normal with any analytics service. Worry not, the team is working hard on improving the reliability.

Edited by ben0, 10 August 2012 - 05:00 AM.

  • 0

#15 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9281 posts
  • Version:Unknown

Posted 10 August 2012 - 05:59 AM

@dangerous_dave just curious, which mobile html5 sponsor demanded playtomic integration?


I can't remember the name of the company, his name is JP. Any of the guys here selling HTML5 games will know who I mean. And he didn't "demand" it :P, just suggested it as an option for online high scores.

i used to work at playtomic, and things occasionally don't work because when you've got 1 billion requests going though your servers very day, there's bound to be 0.001% of fails. That's normal with any analytics service. Worry not, the team is working hard on improving the reliability.

The main problem I had was a game killing bug with 100% reproducibility. I tracked it down to a missing comma in the response and reported it, and it's now fixed. The server issues were failing consistently, but I think that's come from a great system getting far more traffic than originally prepared for.
  • 0

#16 orange08

orange08

    Art Game Movement

  • GMC Member
  • 2203 posts
  • Version:GM:HTML5

Posted 14 August 2012 - 03:22 PM

I made a test project and followed all the steps in your post. However, after you submit a score(Davetomic_submitscore(pname, pscore, table)), it doesn't show up on the game's leaderboard(the one you can check on the Playtomic website).

Edited by orange08, 14 August 2012 - 03:23 PM.

  • 1

#17 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9281 posts
  • Version:Unknown

Posted 14 August 2012 - 11:31 PM

Are the view counts working?
  • 0

#18 Osmium

Osmium

    Graphic Artist

  • GMC Member
  • 306 posts
  • Version:GM:Studio

Posted 15 August 2012 - 01:19 PM

I made a test project and followed all the steps in your post. However, after you submit a score(Davetomic_submitscore(pname, pscore, table)), it doesn't show up on the game's leaderboard(the one you can check on the Playtomic website).


Exactly my problem.

Are the view counts working?


Yes.
  • 0

#19 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9281 posts
  • Version:Unknown

Posted 15 August 2012 - 11:26 PM

Is there a javascript error from the response from submitting the score?
  • 0

#20 Osmium

Osmium

    Graphic Artist

  • GMC Member
  • 306 posts
  • Version:GM:Studio

Posted 16 August 2012 - 11:55 AM

Is there a javascript error from the response from submitting the score?


No. :(
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users