- Home /
Save what you write in textarea as variable?
Hey geeks! Does anyone have a cleaver solution for saving whatever you type in a textarea (GUI.TextArea) as a variable when you click enter? Thanks in advance! //Tommy
Answer by Peter G · Jan 18, 2011 at 08:17 PM
I'd like to call myself clever for coming up with this solution, but I can't. :)
if( GUI.Button() ) {
PlayerPrefs.SetString("ValueInTextArea", stringStringToStore);
//PlayerPrefs.SetString("Key", "Value");
}
or: if you want to save it locally, but only when the user clicks a button, then I guess you could do something like:
var text : String; private var internalText : String = "";
function OnGUI () { internalText = GUI.TextArea();
if( GUI.Button() ) {
text = internalText;
}
}
Thanks! I had the first option figured out. Problem is that as soon as i write something in the textarea, the Playerpref sure becomes that. However, i can't seem to stop editing the textarea, so when i quit the game the playpref goes back to default. (Sorry for poor english)