x


bza, Saving color to player prefs

here is the colorpicker code i am using,

  if (GUI.RepeatButton(new Rect(xxx, yyy, xxx, yyy), colorPicker, GUI.skin.GetStyle("ColorPickerStyle"))) {
        Vector2 pickpos = Event.current.mousePosition;
        Vector2 coords = new Vector2((pickpos.x - xxx) / xxx, -(pickpos.y - yyy) / yyy);
        Color color = colorPicker.GetPixelBilinear(coords.x, coords.y);
         _headMaterial.SetColor ("_Color",col);
    }

and use GameSettings2.SaveColor( col );

and this is what i am trying to do to save

and load from gamesettings script,

       public static String SaveColor( string col ) {
    PlayerPrefs.SetString( "col", Color );
}
    public static String LoadColor() {
 return PlayerPrefs.GetString( "col", Color );
}

and my error, currently anyways, is

Assets/_Scripts/_Items/GameSettings2.cs(87,37): error CS0161: `GameSettings2.SaveColor(string)': not all code paths return a value so what am i doing wrong? cause i am failing to truly understand what i am really doing lool i cant seem to get it to work, though choosing the color etc, works fine, i might not have fully translated java to c#? any help or straight forward fix would be grand, thank you!!

more ▼

asked May 29 '12 at 04:19 PM

EntropicJoey gravatar image

EntropicJoey
23 4 6 7

(comments are locked)
10|3000 characters needed characters left

2 answers: sort oldest
// "not all code paths return a value"
//              ||
//            vvvvvv
public static String SaveColor( string col ) {
//            ^^^^^^
    PlayerPrefs.SetString( "col", Color );
}

Your code expets SaveColor to return a string, but you aren't returning anything there. Either remove String from the signature or return a string.

more ▼

answered May 29 '12 at 04:48 PM

Statement gravatar image

Statement ♦♦
20.1k 35 70 175

how do i return a string, it seems the color picker is a string, unless i am wrong ive tried floats and ints and they give me the same error, and right now i have error like this Assets/_Scripts/_Items/GameSettings2.cs(88,50): error CS0119: Expression denotes a type', where avariable', value' ormethod group' was expected

and this is what i tried

   public static void SaveColor( string col ) {
    PlayerPrefs.SetString( "_Color", Color );
}
    public static string LoadColor() {
    return PlayerPrefs.GetString( "_Color", 1 );
}
playerprefsX is something i never heard of therefore i believe its not something i should try to wrap my head around just yet..
May 29 '12 at 05:41 PM EntropicJoey
(comments are locked)
10|3000 characters needed characters left

You can't save a Color as a string; they are different types. Use ArrayPrefs2, then you can just do PlayerPrefsX.SetColor/GetColor and save yourself a lot of bother.

more ▼

answered May 29 '12 at 04:49 PM

Eric5h5 gravatar image

Eric5h5
80.2k 41 132 519

thank you both kindly

May 29 '12 at 05:07 PM EntropicJoey
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4151
x3731
x295

asked: May 29 '12 at 04:19 PM

Seen: 445 times

Last Updated: May 29 '12 at 05:41 PM