February 13th, 2013, 04:04 PM
Help with complex cookie script for my boardgame site
My boardgame site is ALMOST done!
But... I still need a save option (for all the various form fields throughout the site). I've been trying to implement the cookie ability but am having all kinds of problems. The script needs to:
- Save all form elements to cookie with ONE button.
- Load all variables back into fields with ONE button.
PROBLEM 1: there is more than 1 form on my page, the scripts I've seen only save variables from a single form (multiple save buttons would be needed - one for each form). I need to be able to save ALL forms with just ONE button (same with loading).
PROBLEM 2: the scripts I've seen only deal with simple text-box variables. what would the code look like to get other types of form elements (ie. radio buttons, checkboxes, etc.
PROBLEM 3: my site has moveable game pieces that need their x & y coordinates saved to and loaded from the cookie as well. Haven't a clue how to approach this one.
As this is my last hurdle to overcome on the site I've been working on for a few years, my brain has fizzled from too much work. So any and all help would be exuberantly appreciated.
ps. my forms are split up as follows:
TOKENS, UPGRADES, ETC. (moveable pieces)(not a form obviously)
PLAYER TURN (radio buttons - form 1)
CURRENT CASH (textbox - form 2)
PROPERTY OWNERSHIP (form 3)
PROPERTY UPGRADES (form 3 also)
COLLECTABLE DRAW CARDS (checkboxes, ownership drop-downs - form 4)
Thanks in advance
February 13th, 2013, 04:25 PM
I would think more modern and get away from cookies; for storing so much data; all at once. I would look into HTML5 Web Storage; plus it's allot less coding, then going the cookie route. The only limitation; is that some older browsers; such as IE7 & below, do not support localStorage and sessionStorage and I guess you consider that or offer a "Upgrade Your Browser" message or require at least IE8 and above; for Microsoft Internet Explorer. Just something to think about; good luck.
February 13th, 2013, 04:50 PM
I agree with web_loone08 that cookies may not be the best route here, since it sounds like you need to store quite a bit of session information.
Also keep in mind that while the cookie specification does not suggest a size limit, some browsers limit them to 4K and so, realistically, you'll want to avoid anything larger.
As for pulling data from multiple forms, I'm sure we could give a more thorough answer if you had a link to a demo or could post some code. From what you've described, however, most <input> elements use the value property to define their contents. You can read more here: https://developer.mozilla.org/en-US/docs/XUL/Attribute/value
So, for example, to access the state of a radio button you'd use:
Speaking on cookies directly, if you were to go that route, probably the most useful way to store the information would be as an array, i.e. separate each piece of data with a comma or some other character that won't be used as a part of the data you write.
For example, your cookie would look like this:
Then you'd read the cookie, splitting the data at each comma into a new value in an array. Once that was done, you'd have to write the necessary code for disseminating that data into the appropriate forms/fields.
Again it would take quite a bit of coding, and there are more modern approaches as suggested by web_loone08. However, should you decide to go this route, I do have some code for reading and writing cookies that I'd be willing to share, just let me know if you'd like to have a look at it.
Last edited by null.if.ied; February 13th, 2013 at 04:52 PM.
Reason: fixed broken [code] tag
February 13th, 2013, 06:44 PM
Originally Posted by web_loone08
To clarify, my site is meant to only be played OFFLINE.
I created it to playtest a boardgame I designed so as to avoid unnecessary pre-production costs. Never meant for it to get online, though... maybe some day.
I WISH I could get it online, but my coding skills, though fairly good in some areas, are lacking in others. (Just adding a DOCTYPE declaration to my page screws up a bunch of formatting.
The game plays like a combo of Monopoly and RISK, with touches of concepts from other games as well. It is WAY bigger than Monopoly, WAY nicer to look at, is WAY more fun to play, has a better theme, and can take many nights to finish (or can end at any time). The replayability is HUGE, with the ability to shuffle and distribute the gameboard squares in any order on the gameboard.
My boardgame is fully polished now (well, the playtesting site is, minus the save feature). The game itself is just in need of playtesting.
It really is an unbelievable game and concept that will hopefully soon rock the boardgame world and take Monopoly off the market (everybody loves Monopoly, but I figured a way to make it 1000 times better).
I will look into the HTML5 starage thing, never heard of it before, but if it requires money to use or a server to run it through, than I can't take that route.
I'll check back later.
February 13th, 2013, 07:05 PM
HTML5 is client side. But honestly, you can get web hosting for like $5/mo. If the concept is as good as you say it is I would think you could spare that to help make it a reality.
February 13th, 2013, 08:45 PM
I'm actually not quite sure what route to take now. I'm worried about letting others see my game until I've spoken with a lawyer about protecting my work and so forth. As I'm currently awaiting dissability benefits (could still be months away), money IS an issue. Both for lawyers and even $5.00 a month. Would probably need to hire someone who is better at dealing with compatibility issues and all the stuff required to convert it to online.
Originally Posted by E-Oreo
If DOCTYPE screws up my formatting, and HTML5 needs a doctype declaration (as mentioned to me on another forum), than my problems with being able to save and going to be joined by other problems.