...

View Full Version : cookie with multible values?



the_bob
06-19-2004, 02:38 AM
is it possible?
i'm making a text based RPG and need to save a lot of variables

i have a cookie to save the current city that you're in. this is it


function save(){
d=new Date();
d.setFullYear(d.getFullYear() + 1);
expires="expires=" + d.toGMTString();
document.cookie="currentcity=" + currentcity + "; " + expires;
}

function load(){
cookies=document.cookie;
startpos=cookies.indexOf("currentcity") + 12;
endpos=cookies.indexOf(";",startpos);
if (endpos==-1) endpos=cookies.length;
currentcity = cookies.substring(startpos,endpos);
}


there is a limit of 20 cookies per domain
is there any way i could also add other values to this cookie?
i need to be able to save:

currentcity
maxhealth
health
strength
defence
exp
expntl
gold
mname
mhealth
mstrength
mdefence
mgold
mexp
level
currentmonster
quest

thats under 20, but i may need to add more. also, having that many cookies would be hard to manage

any help would be greatly appreciated

homerUK
06-20-2004, 09:22 PM
I think it is possible... you create the one cookie per user and have multiple values inside it, possibly as an array?

I'm not 100% sure, but you could have



var myCookie = array()
myCookie[0] = "manchester"; //city
myCookie[1] = "96" //health

etc


then set "myCookie" as the cookie...... that might work - but someone else might be able to suggest something better.....!!

jalarie
06-21-2004, 05:05 PM
Check out the "Samples of my work > Cookies > Subdivided cookies" area of my site at:

http://spruce.flint.umich.edu/~jalarie/



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum