The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Cookie based inventory system
rhodge
post Dec 23 2008, 06:27 AM
Post #1





Group: Members
Posts: 7
Joined: 23-December 08
Member No.: 7,392



I'm creating a web based sort of mystery game and an using cookies to store clickable objects in an inventory style area so they can be carried around as you explore and be called on late. The problem i'm having is that if I have them linked to the page they need to unlock when they're sent to the inventory the user could click on them instantly and avoid navagating through the game. What i'm looking for is a way to switch out an element of the cookie and replace it with the linked one when a certian page is reached. At the moment i'm just using a invisable clickable style sheet that hovers over where the inventory is. It functions as far as letting people play the game but as soon as you know it's there you can just bypass the items alltogether and skip right to the end.

Here's a link to the game's website: Link

If you need me to post anything else that will help then just ask. Thanks

ps: ignore the adobe air link. I haven't made an up to date build of that yet.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
rhodge
post Dec 23 2008, 08:46 AM
Post #2





Group: Members
Posts: 7
Joined: 23-December 08
Member No.: 7,392



It might help for you to have the javascript file to look at.

CODE


//a function to save cookies
function savecookie(itemname)
{

   var items = retrievecookie("items");

   if (items)
   {
      if (items.indexOf(',') != -1)
      {
         var items_array = items.split(", ");
      }
      else
      {
         var items_array = new Array();
         items_array[0] = items;
      }

      for (var i = 0; i < items_array.length; i++)
      {
      
         if(items_array[i] == itemname)
         {
            var exists = 1;
         }
         else
         {
            var exists = 0;
         }
      }


      if (exists == 0) items_array.push(itemname);

      items = items_array.join(", ");

      //save a cookie with the passed information
      document.cookie = "items=" + items + "; expires=13/06/2010 00:00:00;";
   }
   else
   {
      //save a cookie with the passed information
      document.cookie = "items=" + itemname + "; expires=13/06/2010 00:00:00;";
   }


}



//a function to retrieve cookies
function retrievecookie(cookie_name)
{
   //call an alert popup with the variable
   var results = document.cookie.match('(^|;) ?' + cookie_name + '=([^;]*)(;|$)');

   if (results)
   {
      return (unescape(results[2]));
   }
   else
   {
      return null;
   }
}


User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 24th April 2024 - 12:52 AM