Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Author Topic: Asterisks while typing  (Read 6698 times)

0 Members and 1 Guest are viewing this topic.

mihaipuiucernea

  • Lurker
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 41
  • Currently working on Colors on Canvas
    • View Profile
Asterisks while typing
« 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"
{

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
Logged

eborr

  • Regular poster
  • ***
  • Karma: 4
  • Offline Offline
  • Posts: 196
    • View Profile
Re: Asterisks while typing
« Reply #1 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 + "*"

   endwhile
endwhile

static.text = " "
continue processing somestring

not tested - but that would be my start point
     
Logged

mihaipuiucernea

  • Lurker
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 41
  • Currently working on Colors on Canvas
    • View Profile
Re: Asterisks while typing
« Reply #2 on: January 01, 2019, 07:30:55 AM »

Thank you for replyinh. Will have a try.

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

Page created in 0.021 seconds with 20 queries.