#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    23
    Rep Power
    0

    Help with complex cookie script for my boardgame site


    Hi all.

    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
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,110
    Rep Power
    119
    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.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    26
    Rep Power
    0
    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:

    javascript Code:
    return document.getElementById('radio1').value;


    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:

    Code:
    board_game_data="12,8,knight,black,10,6,bishop,white,2,7,queen,black"
    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.

    - Null
    Last edited by null.if.ied; February 13th, 2013 at 03:52 PM. Reason: fixed broken [code] tag
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    23
    Rep Power
    0
    Originally Posted by web_loone08
    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.
    Thanks guys.

    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.

    It is a shame too because my site is quite cool. Tonnes of javascript. Hundres of movable pieces. Rewards system. Complex drawcard system that uses 3 decks of 150 cards each, which can be collected and combined and redeemed for cash (ie. RISK)

    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.

    Thanks all
  8. #5
  9. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    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.
    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.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    23
    Rep Power
    0
    Originally Posted by E-Oreo
    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.
    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.

    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.

IMN logo majestic logo threadwatch logo seochat tools logo