i am new to javascript, gadgets, and cookies, so apologies in advance if i am asking the wrong people the wrong questions.
I want to have graduate students in school leadership create text based adventure games in school leadership. I want to have them write the games on google sites, because this is a convenient platform. an example of such a game is here: https://sites.google.com/a/hightechhigh.org/school_leadership_games/can-parents-control-1 i would like to keep track of a running total score within the game. i thought maybe the way to do this was through writing a google gadget that stores the score in a cookie. so i created 3 gadgets. one to create the cookie and set an initial value. one to grab the cookie, increase it by one, and report out the new score. and one to decrease it. my thought was that after a player makes a decision within the game, on the next page i would run the increase score or decrease score gadget on that page. i created the gadgets and tested them on the google gadgets editor page: http://code.google.com/apis/gadgets/docs/legacy/gs.html they worked! but then when i inserted the gadgets onto my google sites page, they don't work. the increase score gadget does not appear to recognize that i already created a cookie. so it returns a value of 1. the decrease score gadget returns a value of -1. when i went into chrome/options/under the hood/view cookies, i see that i have three cookies, all the with same name, but slightly different domains. (example: mdh4un7qk5eo5hq021cllr868ogdu4vc-a-sites- opensocial.googleusercontent.com) can anyone help with this? i am open to any solutions (e.g. not using cookies) but prefer to continue using google sites if at all possible. thanks, Ben Daley High Tech High Graduate School of Education San Diego, CA here's my gadget code: create the cookie: <?xml version="1.0" encoding="UTF-8"?> <Module> <ModulePrefs title="create cookie" /> <Content type="html"><![CDATA[ <script type="text/javascript"> function get_cookie ( cookie_name ) { var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;] *)(;|$)' ); if ( results ) return ( unescape ( results[2] ) ); else return null; } document.cookie = "score=5"; var tot = get_cookie ( "score" ); document.write('total score = ', tot, ' / 10'); document.write('<br />'); </script> ]]></Content> </Module> increase score: <?xml version="1.0" encoding="UTF-8"?> <Module> <ModulePrefs title="increase score" /> <Content type="html"><![CDATA[ <script type="text/javascript"> function get_cookie ( cookie_name ) { var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;] *)(;|$)' ); if ( results ) return ( unescape ( results[2] ) ); else return null; } var tot = get_cookie ( "score" ); tot++; document.cookie = "score"+"="+tot; document.write('total score = ', tot, ' / 10'); document.write('<br />'); </script> ]]></Content> </Module> if it's helpful, the site where i am testing out this code is here: https://sites.google.com/a/hightechhigh.org/school_leadership_games/introduction --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "iGoogle Developer Forum" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/Google-Gadgets-API?hl=en -~----------~----~----~----~------~----~------~--~---
