Some tips needed to point me in the right direction

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
DazZzL
Posts: 9
Joined: Sun Jul 10, 2011 4:10 pm

Some tips needed to point me in the right direction

Post by DazZzL »

First let me thank HallsofVallhalla for his excellent tutorials! Thet really got me going considering creating a game on my own.

Im a RPG/Linc/Cobol programmer for profession but in my free time Ive always wanted to create my own browsergame =) Eventually I want to create some sort of Warhammer Fantasy clone, but for now Im just trying to learn and improve my skills.

A few things Im not sure about how I should handle them, and any input/advice would be much appreciated.

* Eventually I want to , next to a text based side of the game, create a 'battle arena' which will consider of hexagons. Im not sure which route I should go with this. For simplicity lets say I want to create a chess game. Where the chess-board will be used to fight the battles.
Would I be needing a java applet? Flash? Ajax. What works well with PHP? Any example projects you recommend to check?

I dont/wont need full solutions, just a push in the right direction, with if possible some directions to good tutorials/examples =)

* This has been asked often I guess. And the answer was mostly 'use Ajax'. But... Is there another good way to let the browser know who's turn it is, or even let you see what your oponont is doing in his turn, before ending it (like seeing his piece movement on the board).

Which techniques/languages would you use for something like that?

* Can php handle triggered events like, lets say you have 1 minute to finish your turn. The moment your oponent finishes his turn a clock starts ticking. Could anybody point me to some example on how to do this? So let a clock tick to zero, and when that happens , trigger some event. All without refreshing the page.

* Like most browsergames I want to use some server side timers. From what I understand cron jobs are the way to go. Unfortunately my current host doesnt support them. Ive noticed many free webhosts do. Would you suggest using any of those (any specific one?) for just the cron job, or move the webhost alltogether?

* Id like to make most of my text ingame easy configurable (maybe make it possible to support multiple languages. I was thinking to create a file where I create variables containing the text strings. And then use include to use them in my game.

So for example something like ;

$welcometext = "Welcome to this game";

and then be able to use $welcometext whereever Ill need it. Is the way I want to do it a normal way? Any examples on how this should be implemented?


Like I said before, not looking to complete solutions / anwers. Its just that at this moment im in doubt which things I should learn. Id rather ask some ppl with more skills which route to go, and then start learning towards that direction instead of finding out myself (and maybe missing obvious solutions=)

Many thanks in advance.
with regards DazZzL
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Some tips needed to point me in the right direction

Post by Jackolantern »

The reason why we suggest Javascript/AJAX so often is because it has the farthest reach (due to not needing a plugin), and because it interfaces the best with HTML (and therefore PHP). Java, Flash, Silverlight, etc., while most of them can access the HTML DOM, they are typically used in their own sandbox on the page. All Javascript/AJAX is is an interface into the HTML. Also if you use a Javascript library like jQuery, JS/AJAX can be much easier than learning Java, Flash or C#.

PHP has no events. That is because that is not the way it works. When a PHP page is requested, the PHP engine on the server creates the data objects to run the script, those data objects generate static HTML based on how the script was parsed, and then those objects are destroyed as the static HTML is sent to the user who requested it. So once the user sees the HTML page appear in their browser, the PHP objects that created it for them is already gone on the server. In most circumstances (and the odd circumstances are very complex and hardly worth it) PHP has no way at all to know what happened on the client-side, nor to communicate back with it without another page being loaded.

You would ideally want to have your web host on the same host for your cron jobs. While it is possible with higher-end hosts to have them split between hosts (a form of load balancing), most hosts won't allow another host to access their databases. For all free and low-paid hosts, they need to be on the same host. If you need crons and your current host doesn't allow them, you need to change hosts.

That should work to make configurable text, but if you find you need something deeper, you could use a loosely-coupled PHP framework such as CodeIgniter, which offers "internationalization" features, allowing you to create pages as templates, and then create entire text files to hold however many alternate language/text files you need.
The indelible lord of tl;dr
DazZzL
Posts: 9
Joined: Sun Jul 10, 2011 4:10 pm

Re: Some tips needed to point me in the right direction

Post by DazZzL »

Thanks a ton for the quick reply.

I guess before I go any further, Ill have to get myself more familiar with Ajax then =) (And that's not easy being a Feyenoord supporter!... Dutch ppl will understand, lol).
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Some tips needed to point me in the right direction

Post by Jackolantern »

Oddly enough, I actually got that lol. If it makes you feel any better, you aren't actually learning AJAX, you are learning Javascript :) AJAX is just a technique in Javascript.
The indelible lord of tl;dr
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: Some tips needed to point me in the right direction

Post by Xaleph »

AJAX sucks, I agree. Then again, Feyenoord isn`t my favourite either ;)

Anyway, PHP is stateless, like HTTP. It only serves once, so every request it being spon on it`s own thread, which sucks. The only way to recieve a "state" is using cookies or sessions ( which are glorified cookies anyway) so AJAX solves this problem in a way that the current page has all the info it needs, all you do is pass ( for example ) a user ID and update some table in the database. This form of communication simulates the state in which the user or browser is in.

On the timer thing, it could work, either by cron or whatever, however you have to realise that you cannot push data to a user. So if you have a minute to select a skill to perform and you did it in 10 seconds, you still have to wait 50 seconds before the server gets updated. Because the other player/browser/session cannot see that you actually performed that action.

The only way to counter it is by polling the server. Which in turn is quite server intensive. Since you probably make 20 useless requests to the server each minute ( considering every polling has a 2 second interval and the other player reacted after 40+ seconds). Now, that`s not bad, 20 requests is something any server can handle, but if there are hundreds of players all polling the server for updates, it can get real messy.

Anyway, hope it helps.
DazZzL
Posts: 9
Joined: Sun Jul 10, 2011 4:10 pm

Re: Some tips needed to point me in the right direction

Post by DazZzL »

Again thanks a lot=)

Ive read up a little on Ajax, found this a nice read http://www.tizag.com/ajaxTutorial/ajaxform.php just to get the very basics.

For now Ill just focus on getting the functional design of what I want in the game. But... Do I need to make preparations in the rest of the code/page already to be able to make use of Ajax?
Can I push the staging room and battle section of the game ahead in time, and finish the other areas already (where submit buttons will be sufficient)?

From what Ive seen so far I think the answer is yes , and I could just make 2 dummy pages for now and finish the rest of the game first? And at a later stage can easily replace the dummy pages with pages using Ajax?

Seeing nice usage in some inventory type page also=)
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Some tips needed to point me in the right direction

Post by Jackolantern »

If you use jQuery, you can basically just drop in AJAX functionality wherever you want whenever you want. A jQuery AJAX call can be as short as 3 lines of code, whereas the equivalent raw Javascript AJAX call would be over 45 lines (the actual super-robust jQuery AJAX call actually runs over 100 lines, all of which you don't have to type or worry about).

There really is no reason to write raw Javascript (although it is a good idea to understand how it works). Basically no professional web developers do.
The indelible lord of tl;dr
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: Some tips needed to point me in the right direction

Post by Xaleph »

No, you don`t really have to worry about the AJAX part for now. Mostly because you don`t have to worry about any code yet. First be sure what you want, write a document for yourself what you want the game to be. Once you`re done, you can start looking at coding the game.

If you want it all to be AJAX, your page ( index.php or whatever you name it) it probably not going to contain much besides the main layout. All other things like the arena or inventory can be saved as individual html pages.

If, like Jack recommended, you use jQuery ( I`ll recommend it too for the sake of arguments ) you can bind buttons/links/anything to those other pages. It can be as short as 3 lines or as long as a 100. However, that`s up to you.

If you have a menu like:

<div class="button" id="open_inventory">Open inventory</div>

in jquery you can do something like:

$('button').click(function(){
buttonID = $(this).val("id");
switch(buttonID){
case "open_inventory":
open_inventory();
default: return;
}
});

open_inventory(){
$("content_field"){
// do some jquery magic ajax calls and replace the contents of the #content or whatever with new stuff
}
}
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Some tips needed to point me in the right direction

Post by Jackolantern »

Of course the "3 lines of code" is the most basic AJAX call with a callback function in jQuery. If you need longer callback functions, it will be much longer. I think my longest to date was near 700 lines from having to do a super-complex parsing and reacting based on the AJAX results. But without AJAX, and if you make your AJAX calls as robust as they should be (ie individual reactions and plumbing to every result code, which is how it should be) you will be at least 40 or more lines of code. Most experienced raw JS coders (those who choose not to use jQuery or another library, such as Prototype) will create one flexible function or object with the skeleton of the AJAX call, and have callbacks, error reaction logic function objects, etc. passed into the function as optional arguments. That is how jQuery works under the surface, but of course, using the library you don't have to know that ;)
The indelible lord of tl;dr
DazZzL
Posts: 9
Joined: Sun Jul 10, 2011 4:10 pm

Re: Some tips needed to point me in the right direction

Post by DazZzL »

Xaleph wrote:No, you don`t really have to worry about the AJAX part for now. Mostly because you don`t have to worry about any code yet. First be sure what you want, write a document for yourself what you want the game to be. Once you`re done, you can start looking at coding the game.
I got that part done now=) Also created the data model in Visio, and been tweaking and brainstorming about it for weeks.

I got a good idea which techniques Ill use and how I want to setup my pages, which layout, what will go where in which page etc. The only thing I dont know, cant actually code myself YET, is the part I described.

But you guys gave me some great tips. Ill finish up the core functionalities of the game first, and in the meanwhile learn more about jQuery and Ajax, so hopefully when the core is done in 3-4 weeks, ill be able to implement the battle, inventory and staging room areas using those techniques=)
Post Reply

Return to “Beginner Help and Support”