Programming the storyline

Talk about game designs and what goes behind designing games.
Post Reply
User avatar
havoknz
Posts: 23
Joined: Sun Apr 24, 2011 2:14 am

Programming the storyline

Post by havoknz »

Hey everyone

I am working on a web browser game in php at the moment and need some help/guidance.

Currently I have a working game. As in you can login and set up a character, fight monsters that are randomly generated, buy items and use them, heal at hospital and fight other players.

What I want to do now is create a story line the character/players have to follow to get new things and generally make the game more interesting.

This is where i am stuck. I have a storyline that I have made up and planned out but dont really know how to code it.

The way I have thought about it is that each part of the storyline will have a number code to it. So mission 1 is id = 1, mission 2 is id = 2 etc etc. So every time the user wants to continue with the story line the code checks the database for what id they are up to and continues from there. But I feel this is not practical because I the server will have to check the database every time a page is loaded and I feel as thought it will slow the game down with heaps of database requests.

Is there a better way of looking at this?
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Programming the storyline

Post by Jackolantern »

Nope, you are on the right track. One database access per page access is not bad at all, and will have basically no performance impact. You only need to start worrying if you getting up to 10 - 20+ accessed per short-visited page access. How you described it is likely the best way to do it.
The indelible lord of tl;dr
User avatar
havoknz
Posts: 23
Joined: Sun Apr 24, 2011 2:14 am

Re: Programming the storyline

Post by havoknz »

Thanks Jack i guess i was on the right track after all...
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

Re: Programming the storyline

Post by Callan S. »

Tell us more about it as you go, I'm interested to see what other designers do in terms of implementing various ways of delivering a story :)
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Programming the storyline

Post by hallsofvallhalla »

i have pages that access the DB 10 times in one page and all works fine. It all depends on indexing and not using select * in every query :)

1 check per page load is extremely light.
User avatar
havoknz
Posts: 23
Joined: Sun Apr 24, 2011 2:14 am

Re: Programming the storyline

Post by havoknz »

having trouble...

how to i send a query to the database to update it with a link? Im already using $_GET to make sure the current url query is the correct part for the user so i cant use that...
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Programming the storyline

Post by Jackolantern »

Can you give us some more background on what you are trying to do, and show us your code. I am not exactly sure what you mean.
The indelible lord of tl;dr
User avatar
havoknz
Posts: 23
Joined: Sun Apr 24, 2011 2:14 am

Re: Programming the storyline

Post by havoknz »

okay dokay...

So i got a user and storyline table in database.

each user has a scene/part they are up to. eg. intro, part1, part2 etc.

in the storyline table I have those parts, eg intro, part1 etc, which have corresponding code that they load. I call it the display. eg

Code: Select all

<p>You walk into a room<p>
I query the database for what scene the user is upto. then check if its the same as the url. if it is it displays, if not then it says "You seem lost" and has a link that redirects them to the part they are up to.

Now where I am stuck is how do I update the database to the next scene.

Eg. I have some links:

Code: Select all

<a href="index.php?scene=door1">Go through the first door</a>
<a href="index.php?scene=door2">Go through the second door</a>
So im using the url to display where they player is upto. eg. index.php?scene=intro

and I want them to click on door1 and it updates the database to door1 and displays the relevant info from the db...

Thats what im stuck on..

I am today looking at Code Igniter to code this.. using MVC architecture.. which might make it a little easier...
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Programming the storyline

Post by hallsofvallhalla »

i am not sure exactly what you mean but this might help



after the player selects door1 it reloads index

i would change these to small int so that it is light on the database and you can add more flavor to it.

Code: Select all

<a href="index.php?door=1">Go through the first door</a>
<a href="index.php?door=2">Go through the second door</a>
<a href="index.php?drawer=1">Check Drawer in Dresser</a>
index.php

Code: Select all

if(isset($_GET['door']))
{
$door = $_GET['door'];
$sceneinfo="SELECT description from scenes where door='$door' ";
   $sceneinfo2=mysql_query($sceneinfo) or die("Could not get user stats");
    $sceneinfo3=mysql_fetch_array($sceneinfo2);
echo  $sceneinfo3[0];
}

if(isset($_GET['drawer']))
{
$door = $_GET[drawer'];
$sceneinfo="SELECT description from scenes where drawer='$drawer' ";
   $sceneinfo2=mysql_query($sceneinfo) or die("Could not get user stats");
    $sceneinfo3=mysql_fetch_array($sceneinfo2);
echo  $sceneinfo3[0];
}
hope that helps.
User avatar
havoknz
Posts: 23
Joined: Sun Apr 24, 2011 2:14 am

Re: Programming the storyline

Post by havoknz »

Thanks Halls.

That is kinda what I was doing. But good advice about the small int in db.

What I was trying to achieve was a 1 liner script where it loaded the correct page up to what the user selected.

Code: Select all


$playerupto = $this->db->sql("SELECT scene FROM players WHERE id=".$session->id." LIMIT 1");
$sceneinfo = $this->get->sql("SELECT discription FROM storyline WHERE scene=".$playerupto);

if($_GET['scene']==$playerupto) { echo $sceneinfo; }
else { echo "You seem lost...<p><a href="index.php?scene=".$playerupto.">Continue</a></p>"; }

I think I can do something pretty good with code igniter... but i just gotta have a play with it today.
Post Reply

Return to “Game Design”