Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-19-2004, 01:38 AM   PM User | #1
the_bob
New Coder

 
Join Date: Dec 2003
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
the_bob is an unknown quantity at this point
Question cookie with multible values?

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
Code:
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
the_bob is offline   Reply With Quote
Old 06-20-2004, 08:22 PM   PM User | #2
homerUK
Regular Coder

 
Join Date: Nov 2002
Location: Manchester, UK
Posts: 533
Thanks: 4
Thanked 1 Time in 1 Post
homerUK is an unknown quantity at this point
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

Code:
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.....!!
homerUK is offline   Reply With Quote
Old 06-21-2004, 04:05 PM   PM User | #3
jalarie
Regular Coder

 
Join Date: Jun 2002
Location: Flint, Michigan, USA
Posts: 595
Thanks: 1
Thanked 20 Times in 20 Posts
jalarie is an unknown quantity at this point
Check out the "Samples of my work > Cookies > Subdivided cookies" area of my site at:

http://spruce.flint.umich.edu/~jalarie/
__________________
Visit my site at http://spruce.flint.umich.edu/~jalarie/.
jalarie is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:45 AM.


Advertisement
Log in to turn off these ads.