Cookie Object (last update 12/05/01)

Description:

The core library includes the cookie object constructor. Cookies are small data storage containers in the visitor's browser, a little like files. You can use up to 20 cookies per visitor. A cookie must have a unique name assigned to it (like a file), you do this when you create the cookie object. If a cookie with the name you use already exists, then your cookie object will have it's value set to whatever you set it to the last time the visitor was at your site. If not, the cookie's initial value will be null.

Cookies are easy to use with the gamelib library. To simplify things for games use, expiry dates and paths etc are not used. Any cookie you create will not expire between browser sessions, and must be erased using the erase() method. You simply create, read, set and erase the cookie just as you would a file.

To use:

The cookie code is part of the core module. So is linked in to your script when you add the core (as you always will when using gamelib):

<script language="Javascript" src="gamelib_core.js"></script>

You then create a cookie object by passing the "filename" as so:

var mycookie=new Gl_cookie("visitor_name");

If you had a cookie with the filename "visitor_name" some time previously, it will hold the value it did the last time it was used. The instance name (in this case "mycookie") is simply a way of using the file. Cookies can only hold simple data - either Strings or Numbers, NOT arrays or Objects.

List of methods for cookies

erase
setValue

List of properties for cookies

value

Descriptions of methods

MethodParametersDescription
erase(none)Erase the cookie. After this, the cookie will no longer exist
setValueString/NumericThe argument to this method is the data you wish the cookie to hold. When you add new data to a cookie, it loses its old data

Descriptions of properties

PropertyData TypeRead/WriteDescription
valueString/NumericRThe current contents of the cookie. This is the data saved between page visits