Creation of a Flash arcade site using WordPress – step 5
In Creation of a Flash arcade site using WordPress - step 4, we saw how to post a game into a wp database, now we'll see how to retrieve game information.
It's time to parse the json feed.
Where can I find the feed?
At this link http://www.mochiads.com/feeds/games/xxx/all/all?format=json you will find the json feed. Just replace the xxx with your publisher id.
Or use http://www.mochiads.com/feeds/games?format=json like I am doing in this example.
There are various solution according to your php settings. If you don't know how to check your php settings, refer to phpinfo() at this link.
Php version 5.2.0 or above
If your server runs php 5.2.0 or above, you're really lucky because it provides native json support.
In order to have the $mochi array as shown at lines 37-50 in Creation of a Flash arcade site using WordPress - step 4, you just need to use this script:
-
<?php
-
-
$mochi_url = "http://www.mochiads.com/feeds/games?format=json";
-
$games_array = json_decode($feed, true);
-
-
-
for($x=0;$x<$number_of_games;$x++){
-
foreach($games_array[games][$x] as $varname => $varvalue) {
-
$mochi[$varname] = $varvalue;
-
}
-
// post game in wp
-
}
-
-
?>
and you'll have everything you need in $mochi array. Then you'll only have to include your posting routine at line 11
Php version before 5.2.0 or unknown php version
If your php version is older than 5.2.0 or you just' don't know what php version you are using, A Beautiful Site provides a class that works in the same way as 5.2.0 built-in functions.
Moreover, the class degrades if (or once) your server supports 5.2.0
You can download the class here and once uploaded JSON.php in the same directory of your parsing script, you just need to add
require("JSON.php");
as the first line of the parsing script.
Running out of memory
In some servers, you may run out of memory or getting strange errors (due to memory) while executing the script. You can save memory rewriting reduce_string function in the JSON.php file to
-
function reduce_string($str)
-
{
-
}
since mochi feed does not have comments.
Running out of memory (again!!) or 500 Internal Server Error
If you get this message, then you should consider changing your provider.
Anyway, I made an awful script to make it work even on the cheapest server... but consider it's not the best solution.
It works because it knows how mochi feed is made, so don't try it with another json feed
-
<?php
-
-
require("json.php");
-
-
$mochi_url = "http://www.mochiads.com/feeds/games?format=json";
-
-
-
$games[$x] = "{\"rating\": \"".$games[$x];
-
$games_decode = json_decode($games[$x], true);
-
foreach($games_decode as $varname => $varvalue) {
-
$mochi[$varname] = $varvalue;
-
}
-
// post game in wp
-
}
-
-
?>
If you still experience errors, then you must change your hosting plan.
You will be pleasantly surprised by WordPress Themes provided by Template Monster. All of them are of professional design and high quality.
16 Responses to “Creation of a Flash arcade site using WordPress – step 5”
Leave a Reply
Trackbacks
-
Hacer un sitio con Arcades sobre WordPress | Summarg on
May 23rd, 2009 2:37 am
[...] Creation of a Flash arcade site using WordPress – Step 5: Ahora si, se agregan juegos desde el feed y habla sobre algunos problemas frecuentes y sus soluciones. [...]
Posts
- Rick Triqui: my first PlayCrafter game
- Prototype of a Flash game like Meeblings
- Games for the game developers!
- The art of debugging
- How to embed a text file in Flash
- Create a Flash game in minutes with PlayCrafter
- Upgrade your Flash CS4 to 10.0.2
- Play Mazeroll, my latest Box2D game
- Triqui MochiAds Arcade plugin for WordPress Released!!
- The MochiAds funnel
- Flash game creation tutorial - part 1
- Create a Lightbox effect only with CSS - no javascript needed
- Flash game creation tutorial - part 2
- Make a Flash game like Flash Element Tower Defense - Part 2
- Flash game creation tutorial - part 3
- Create a flash draw game like Line Rider or others - part 1
- Create a Flash Racing Game Tutorial
- Make a Flash game like Flash Element Tower Defense - Part 1
- Create a flash artillery game - step 1
- Create a flash draw game like Line Rider or others - part 5
- Flash game creation tutorial – part 5.2




(4.9 out of 5) - Flash game creation tutorial – part 3




(4.86 out of 5) - Creation of a platform game with Flash – step 2




(4.84 out of 5) - Create a survival horror game in Flash tutorial – part 1




(4.82 out of 5) - Create a flash artillery game – step 1




(4.82 out of 5) - Create a Flash Racing Game Tutorial




(4.8 out of 5) - Create a flash artillery game – step 2




(4.75 out of 5) - New tile based platform engine – part 6 – ladders




(4.74 out of 5) - Flash game creation tutorial – part 2




(4.73 out of 5) - The experiment – one year later




(4.7 out of 5)
(6 votes, average: 3.83 out of 5)

Hey Emanuele! Your blog has inspired me to do so many things! I’ve made games and gotten them sponsored, and now I’ve made a blog! Check it out:
http://flashdevz.wordpress.com/
but won’t this script add games that exist or is it still not in the add part?
Emanuele, thanks, you rocks!
Erik, as long as the game tag is in the database, it will not add the game again.
However if a new version of same game using the same game tag, it will not update either. Deleting the old “post” might work.
Thanks for new step.
But could you please offer us a complete version of this script? Oh I’m not lazy, But don’t know much about programming.
Thanks.
So where do you put that code and how do you make it work? I’ve got everything working fine so far even the adding of the one game to the wordpress database and displaying it. But where does this code go? I’m quite confused as you may have worked out.
Hope you can tell me how to get it all to work.
Killy
I am preparing the next step…
oh, ok cheers for that :) look forward to it
Woohooooo thank you Emanuele.
You’re so kind.
Could you learn us how can i manage games with that script in next step?
I mean change that script in a way so that for example we can see last 10 games and check what games we want to add.
Thanks.
Thanks for your tutorial. Just one comment/suggestion… in my case, Mochiads Json is so long that I had to add a “set_time_limit(xx);” in order to be able to execute all the script. Otherwise the standard 30 sec. isn’t enough long.
Thanks again. Continue like this !!
Alain
playZgame.com
can you please explain where this code is supposed to go?
i put it where i thought it was supposed to go and i get Fatal error: Maximum execution time of 90 seconds exceeded in /home/&&/hidden/hidden/public_html/&&/JSON.php on line 701
anyway you could set this up on my system or help me get it going?
Can someone plllease show me a working version of this script. I need to try the non php 5 version on my current server to find out if i need a new host or not. If anyone can recommend an affordable host that can handle this script please do.
Thanks
hi, when i try to run script, it is waiting for a time, then it says
Duplicate entry ‘40-1′ for key 1
40-1 changing every try
idea ?
thanks
Hi.
First a thousand thank you .
I manage to make it work , but it only loads about 10 games at a time so I have to run the script till I go crazy :) .Could the free host be the problem ?
Also isn’t it dangerous to just let scripts for everyone to run ?
Thanks
Hello,
I have followed this series of tutorials and have got to the point of automating the Mochiads feed. I am not sure exactly where to put the code and I have tried numerous places. The best I could get was a broken feed where it would say “record not inserted” about 50 times while maybe saying “record inserted” once in the whole thing and then ending with an error speaking of a duplicate or of some weird thing related to the descriptions of the games. I would really appreciate some help on how to make them all say “record inserted” so that I can have the games on my arcade.
Thanks