LebGeeks

A community for technology geeks in Lebanon.

You are not logged in.

#1 February 26 2008

rapacity
Member

ajax

hello I'm coding an online web text based rpg game, similar to the idea of www.kingsofchaos.com, no need for polling in these kinds of games.

my current plan is to have an index.html with a main javascript library, which has an ajax function and another function that dynamically loads an external javascript file

when a user clicks a link say battlefield it loads index.html#battlefield which then runs a function loadScript("battlefield") which then imports and runs battlefield.js

battlefield.js then calls using ajax game.pl?battlefield which outputs

1,432,player1,40000|2,535,player2,60500|etc... *** felt sending it this way would be better than in xml format coz it would save bandwidth :?

once fully received the battlefield.js will then parse the string and output it as proper html

say for example

<ul>
<li>1 432 player1 40000</li>
<li>2 535 player2 60500</li>
</ul>

and then insert it in to the innerHTML of a div called "main"


so its

index.html#xxx -> xxx.js -> game.pl?xxx


question: is there a better design than the one im implementing or is the design im coding ok?

Last edited by rapacity (February 26 2008)

Offline

#2 February 26 2008

mir
Member

Re: ajax

since this is a web text based rpg game
i don't think there will be anything that will eat connection

the "slow" game will come not from internet speed ..you are not updating and transmitting images or videos, but guess the slow factor will come from the time to process the game actions and compare it.. and from load on the server

i didn't exactly get what the game does
do you save the progress of the players? are you using a database ?
maybe more details would be good
how many users are supposed to use the db.. to know how much optimization you must do
how do users interact ?

but i didn't notice something terribly bad in ur plan
so guess it must work

and by the way  where are my manners - WELCOME -

Last edited by mir (February 27 2008)

Offline

#3 February 27 2008

rapacity
Member

Re: ajax

thx, well erm the game is a turn based game im making it sortof like u have a base and u can attack,invade,trade,ally  with other players, and it has grid map with all the bases on it. say u click on a base 4 squares away it would take more time than if the enemy were 2 squares away, also im only coding it in ajax just to learn it, the progress is stored on a mysql database, the server-side of the game is coded on perl, i'd imagine alot of users would be accessing the db all at once. the game has a coupled irc bot, players can play online in their browsers, or play the game through the irc bot.

Offline

#4 February 27 2008

mir
Member

Re: ajax

nice
good luck with your coding

i don't really know details about the technologies you are using

but i guess the typical general guidlines
i think the most important is you have to be careful with your database
do some reading on optimizing mysql DBs .. review your db carefully.. see if any fields and tricks can be done ta tkhafef 3annak shegel
cuz if lot of users and traffic.. it is likely you would bend some rules to get better performance
let the db engine do most of the db work 

post the db design u did so far

once u are sure all the things u may want to do can be done.. do the core functionality (the hardest thing)

and when u optimizing ur code.. if at some point you can't get the minimum result.. consider a completely total different approach (the TANSTATFC rule)

and good luck with your learning  ... don't forget to bring reserve nescafe

Last edited by mir (February 27 2008)

Offline

#5 February 27 2008

samer
Admin

Re: ajax

index.html#xxx -> xxx.js -> game.pl?xxx

The above uses a somewhat good logic, but i wouldn't put it that way.

Here's what you are (or should be doing : )

Call a javascript function to to pull the data from the perl script, then display the data in the div you want.

<a href="http://example.org/#crap" onclick="pullAttack();">Attack!</a>

no need to generalize the whole thing by doing this (check bold) :

index.html#xxx -> xxx.js -> game.pl?xxx

Offline

#6 February 27 2008

rapacity
Member

Re: ajax

yea but the javascript parser functions i coded were page specific so i decided to split them up so that they would be modular

home.js would have its own code to parse the content off game.pl?home
attack.js would hold the attack code etc
...
also I didn't like having say pullHome(data) and pullArmory(data) and such for each page on one javascript file. If i had it all on one file and i updated part of the code say I updated pullHome the user wouldve had to redownload the whole monolithic javascript library i coded vs just downloading a new home.js file for function only . hope this explains why i didn't implement it as just pullAttack();

anyways with this in mind I then had in my index.html
<script src="script/home.js">
<script src="script/attack.js">
...
but this had a http overhead and so came out slower than the monolithic one i had,

so then I decided I'd have the thing dynamically import the xxx.js file when needed and cache it instead of it preloading all the js files at load time

so for me its actually like
<a href="http://example.org/#attack" onclick="sload('attack');">Attack!</a>

the sload function dynamically imports/runs the .js page

so it really is   what i stated it to be

index calls sload('xxx')  -> xxx.js imported runs calls content ->
index has new content   <-   received data is parsed   <- sends content back

wondering if any1 here knows a better design or could point out to me why my design sucks

thx anyways

Last edited by rapacity (February 27 2008)

Offline

#7 February 28 2008

samer
Admin

Re: ajax

can you provide me w/ a demo page ? :)

Offline

#8 February 28 2008

rapacity
Member

Re: ajax

ok ill upload the page soon, i need to do some edits to the page first.

Offline

Board footer