x


Character's name won't save

For some reason the character's name will not save when I hit the "finish" button, what could be wrong?

    var CharacterName : String = "Hello World";


function OnGUI(){
    CharacterCreater();    
    FinishedWithCharacter();
}

function CharacterCreater() {
     CharacterName = GUI.TextField (Rect (10, 10, 200, 20), CharacterName, 25);
}

function FinishedWithCharacter(){   

    if(GUI.Button(Rect(300,10,50,20), "Finish")){
       SaveGame();
    }
}

function SaveGame(){
    Debug.Log("Saving Game...");
    PlayerPrefs.SetString("PlayerName", CharacterName);
}
more ▼

asked Apr 24 '12 at 04:56 AM

Mattchuuu gravatar image

Mattchuuu
94 9 16 20

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

2 answers: sort voted first

I think there is a typo in the code. I mean, in the last line of the code.

Make PlayerPrefs.SetString("PlayerName", CharacterName); as PlayerPrefs.SetString("PlayerName", "CharacterName");.

more ▼

answered Apr 24 '12 at 05:00 AM

venkspower gravatar image

venkspower
284 17 24 27

I'm sorry, I spoke too soon, now it only saves as CharacterName.

Apr 24 '12 at 05:08 AM Mattchuuu

Alright. Use PlayerPrefs.SetString("PlayerName", CharacterName); itself. And try to print the PlayerName, and let me know what you are getting.

Apr 24 '12 at 05:18 AM venkspower
(comments are locked)
10|3000 characters needed characters left

So apparently the problem was in how there was a space between Textfield and (rect . It works just fine now.

more ▼

answered Apr 24 '12 at 05:09 AM

Mattchuuu gravatar image

Mattchuuu
94 9 16 20

(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:

x143
x133

asked: Apr 24 '12 at 04:56 AM

Seen: 343 times

Last Updated: Apr 24 '12 at 05:19 AM