GUI.Textfield function won't update variable

Hello,

I have this tad bit of code, but the variable in the textfield won’t change because it’s thru the function.(I think this is the reason)

var tft : String;

function OnGUI () {

Block ("Texture", "texturefile=", tft, 25, 85);
}

function Block (lblk : String, wblk : String, blk : String, vx : int, vy : int) {
		GUI.Label (Rect (vx, vy, 150, 20), lblk);
		blk = GUI.TextField (Rect (vx + 90, vy, 150, 20), blk);
		if (blk != "") info += wblk + blk + "

";
}

If anyone knows a workaround for this, I’d be very greatful.

The content of the TextField isn’t changing because you never store the return value of GUI.TextField anywhere.

GUI.Textfield returns the string in the text field every frame (so you can do something with it). For it to get updated when the next frame happens, you need to store it somewhere.

Using your code as an example:

There’s no need to pass tft as a parameter in the function named Block.

You can just put the following inside of Block:

tft = GUI.TextField(someRectangle, tft);

Think of your script as a class. The variable tft is a member (or property) of that class, so functions (or methods) inside the class have access to it.

In your code the return value of GUI.TextField is never recorded. The unchanged value of the variable tft is continually re-assigned to the contents of the TextField every frame.