Wintermute Engine Forum

Wintermute Engine => Technical forum => Topic started by: mihaipuiucernea on December 19, 2018, 04:12:39 PM

Title: Asterisks while typing
Post 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:
Code: [Select]
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 = "|";


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
Title: Re: Asterisks while typing
Post by: eborr on December 28, 2018, 12:27:24 AM
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
Title: Re: Asterisks while typing
Post by: mihaipuiucernea on January 01, 2019, 07:30:55 AM
Thank you for replyinh. Will have a try.

Cheers and Happy New Year! ::rock ::beer