Wintermute Engine > Technical forum

Asterisks while typing


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:

--- Code: ---var DescriptionControl = self.GetControl("insert");

global DescriptionText;
DescriptionControl.CursorChar = "|";

global editornou;

var mesaj = "";
var removeAsterisk = "";
var asterisk="";
var SomeText ="";

var count=0;
on "Keypress"

//this is the logic that masks the letters with asterisks
SomeText = DescriptionControl.Text;

var StrObject = new String(SomeText);

mesaj = mesaj+removeAsterisk;

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 != "")
mesaj = mesaj+removeAsterisk;
//save user input in the inputline variable
DescriptionText = mesaj;

DescriptionControl.Visible = false;


            //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 = "|";


--- End code ---

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 + "*"


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


[0] Message Index

Go to full version