So yeah, I'm trying to make it so that asterisks re shown whle typing a text.
I have a window and an editor control. If the player presses Return and the editor is not empty, it stores the text in a var.
My spaghetti code is this:
var DescriptionControl = self.GetControl("insert");
global DescriptionText;
DescriptionControl.CursorChar = "|";
global editornou;
var mesaj = "";
var removeAsterisk = "";
var asterisk="";
var SomeText ="";
var count=0;
on "Keypress"
{
if(Keyboard.KeyCode!=VK_RETURN)
{
//this is the logic that masks the letters with asterisks
count=count+1;
SomeText = DescriptionControl.Text;
var StrObject = new String(SomeText);
mesaj = mesaj+removeAsterisk;
if(StrObject.Length>1)
{
removeAsterisk = StrObject.Substr(count-1, StrObject.Length); //remove *
}
else if(StrObject.Length==1)
{
removeAsterisk = StrObject;
}
DescriptionControl.Text = AsteriskRecursion(count, asterisk);
}
//If return is pressed and the input bar isn't empty
if(Keyboard.KeyCode==VK_RETURN && mesaj != "")
{
while(afostselectat)
{
mesaj = mesaj+removeAsterisk;
//save user input in the inputline variable
DescriptionText = mesaj;
//Game.UnloadObject(this);
DescriptionControl.Visible = false;
Sleep(10);
}
}
//In case enter is pressed when the inputline is empty
else if(Keyboard.KeyCode==VK_RETURN && mesaj == "") //DescriptionControl.Text == "")
{
this.Text = "Please enter your description";
DescriptionControl.Text = "";
DescriptionControl.CursorChar = "|";
}
}
My questions:
1. is there an easier way to achieve this?
2. this code only works if the user doesn't press backspace. If backspace is pressed (to delete a letter for example), it messes the entire string with lots of asterisks shown (more than it should be). I'm pretty sure I'm doing something wrong
Help