More efficient

hey guys, i just quickly made a script to allow me to change my level through a text box, however i feel instead of using say “.ModLevel 2” i should be able to enter any amount.
for example if i entered “.ModLevel 10” i want to be able to add 10 without having “.ModLevel 10” as a pre defined variable.

heres the script :

var PlayerLevel =1;
var TextEnter = "Enter Text";
var Mod1 = ".ModLevel 1";
var Mod2 = ".ModLevel 2";

var B1 = 10;
var B2 = 20;
var B3 = 60;
var B4 = 50;
var E1 = 20;
var E2 = 20;
var T1 = 20;
var T2 = 20;
var T3 = 20;
var T4 = 20;

var ShowTextBox : boolean = true;

function Update () {
if(TextEnter == Mod1  Input.GetKeyDown("return")) {
	ShowTextBox = false;
	PlayerLevel = 1;
	TextEnter = "Enter Text";
	TextBox ();
	}
if(TextEnter == Mod2  Input.GetKeyDown("return")) {
	ShowTextBox = false;
	PlayerLevel = 2;
	TextEnter = "Enter Text";
	TextBox ();
	}
}


function OnGUI () {
	GUI.Label (Rect(B1,B2,B3,B4),""+ (Money.Gold ));
	GUI.Label (Rect(E1,E2,B3,B4),"Lv." + (PlayerLevel));
	if(ShowTextBox) {
	TextEnter = GUI.TextField (Rect (T1,T2,T3,T4), TextEnter, 50);
	}
}

function TextBox () {
ShowTextBox = true;
}

hers the code in pesudo:

if(i enter .modlevel “amount”) {
level = amount;
}

if it helps, i knew you could do somthing like this in python, i can’t rember exactly but you can build strings using parts like {0} walked to a town and {1} {2}

0,1 and 2 would be replaced with somthing, but you could also insert stuff with a similar option and it would be stored as a variable

There are a couple of functions in the .NET library that will help here.
String.LastIndexOf returns the rightmost position in the string where a particular character or substring occurs. You can use this to detect where the space is in your source string. Then, you can use String.Substring to extract the portion that follows the space. Finally, Int32.Parse will convert the numeric string into an integer, assuming it is correctly formed:-

var pos = TextEnter.LastIndexOf(" ");
var numString = TextEnter.Substring(pos + 1);
var num = Int32.Parse(numString);