Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Issues with CookieCutter

Discussion in 'Scripting' started by LunarMaster, Nov 26, 2007.

  1. LunarMaster

    LunarMaster

    Joined:
    Nov 12, 2007
    Posts:
    1
    I've been trying to save a cookie to Firefox using the CookieCutter method that is found in the Wiki, but have been out of luck. I'm new to Unity so it might be an issue when setting up the scripts.

    I'm currently using Unity 2.0
    I'm using FireFox (so that it can create local file:\\ cookies)
    And I'm exporting using WebPlayer Streamed.

    I setup the CookieCutter.js exactly as the wiki instructs (changing the section for Unity 2.0) and leaving the path as it is. I then have a separate script with the Gui script attached to the Main Camera and that creates an object from CookieCutter.js (current code below):
    Code (csharp):
    1.  
    2. var CookieCutter : CookieCutter;
    3. var stringToEdit = "";
    4. var cookieValue : String;
    5.  
    6. while(!CookieCutter.loaded)
    7.  yield WaitForSeconds(0.1);
    8.  
    9. // Read testCookie
    10. cookieValue=CookieCutter.GetCookie("testCookie");
    11.  
    12. // SetDefault
    13. if(!cookieValue)
    14.    cookieValue="!Cookie";
    15.    
    16.  
    17. //Draw Gui
    18. function OnGUI () {
    19.    
    20.     // Make a text field that modifies stringToEdit.
    21.     stringToEdit = GUI.TextField (Rect (Screen.width/2-100, 100, 200, 20), stringToEdit, 25);
    22.    
    23.     //Display cookieValue in Label
    24.     GUI.Label (Rect (Screen.width/2-100, 40, 100, 30), cookieValue);
    25.    
    26.     if (GUI.Button (Rect (Screen.width/2,70,100,20), "Change Cookie")) {
    27.         CookieCutter.SetCookie("testCookie",stringToEdit,100);  }  
    28.                
    29.     if (GUI.Button (Rect (Screen.width/2-100,70,100,20), "Show Cookie")) {
    30.         cookieValue=CookieCutter.GetCookie("testCookie");   }  
    31.        
    32. }
    33.  
    34.  
    Eveytime I change the value of the cookie it seems to show it, but after I refresh, it returns the value to !Cookie. Is there anything that needs to be done to make an Object from a different script? Should I try to run it directly from a URL? Any help is much appreciated.
     
  2. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    I'm seeing similar possibly related behavior using PlayerPrefsx, the cookie cutter derivative on the wiki (http://www.unifycommunity.com/wiki/index.php?title=PlayerPrefsx)

    Using any browser (tried Safari Firefox) the cookies are saved (confirmed by looking at them manually) but for some reason their values are not loaded.

    /me scratches head...
     
  3. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    1,027
    Yea this was nasty: The scripts on the wiki require System.X because of the str.Split.

    I made a quick fix.
    replace the FOR with this to have it working:

    Code (csharp):
    1.   while(cookie_string.IndexOf(";")>0) {
    2.       var stripText = cookie_string.Substring(0,cookie_string.IndexOf(";"));
    3.       cookie_string=cookie_string.Substring(cookie_string.IndexOf(";"));      
    4.       if(stripText.Length >= 2){
    5.         var is_pos=stripText.IndexOf("=");
    6.         var name=stripText.Substring(0,is_pos);
    7.         var value=stripText.Substring(is_pos+1);
    8.           _cookies[name] = value;
    9.       }
    10.   }