Wintermute Engine Forum
Wintermute Engine => Technical forum => Topic started by: mihaipuiucernea on December 19, 2018, 04:12:39 PM
-
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 :D
Help :D
-
I have not thought this through to much - but I dont see the need for an editor control would be necessary, a normal static should be enough
p code would run something like this
define illegal chars
var somestring
while not illegal
while not return
input key
somestring = somestring+key
static. Text - Static.Text + "*"
endwhile
endwhile
static.text = " "
continue processing somestring
not tested - but that would be my start point
-
Thank you for replyinh. Will have a try.
Cheers and Happy New Year! ::rock ::beer