Wintermute Engine Forum

Wintermute Engine => Technical forum => Topic started by: VEn0m on May 19, 2012, 02:50:05 PM

Title: Editor Filter
Post by: VEn0m on May 19, 2012, 02:50:05 PM
Is there any way to make editor filter?

e.g. "Player's name" must contain only letters A-z, but now player can imput any sign including #$@ etc.
Title: Re: Editor Filter
Post by: Mnemonic on May 20, 2012, 07:33:41 AM
You can try catching the change to editor text and change the text programatically.
For example, if the editor is called "textBox", in your window script add something like:

Code: WME Script
  1. on "textBox"
  2. {
  3.   var textBox = this.GetControl("textBox");
  4.   var someText = new String(textBox.Text);
  5.  
  6.   // ...do some processing of the text and assign it back to the editor
  7.  
  8.   textBox.Text = someText;
  9.  
  10. }
  11.  
Title: Re: Editor Filter
Post by: VEn0m on May 23, 2012, 11:06:31 AM
Thanx a lot. That helps :)
Title: Re: Editor Filter
Post by: hex on June 02, 2012, 11:42:51 AM
Hello Venom, were you able to filter character input? If so, how? I don't want the player to submit only a blank "space" without letters.
Title: Re: Editor Filter
Post by: VEn0m on June 30, 2012, 09:43:16 PM
Hello Venom, were you able to filter character input? If so, how? I don't want the player to submit only a blank "space" without letters.

this is the "draft" of the filter

Code: [Select]
  var NewEditorText =new String(Editor.Text);
 
  if ((key >= 65 && key <=90) || (key >= 97 && key <= 122)) // A-Z or a-z
  {
  Editor.Text = NewEditorText;
  }
  else
  {
if (key!=8) //backspace
{
var lenght = NewEditorText.Length;
var ClearText = NewEditorText.Substr(0,lenght-1); //remove last digit
Editor.Text = ClearText;
}
  }
 
Title: Re: Editor Filter
Post by: hex on July 01, 2012, 06:30:51 AM
Ah, I see what Mnemonic meant by catching the change to the editor. Didn't realize that was possible. Very helpful, thanks :)

For anyone needing this filter, append an equal sign to the operators to capture the letters Aa and Zz: <=, >=
Title: Re: Editor Filter
Post by: VEn0m on July 01, 2012, 06:41:40 AM
Ah, I see what Mnemonic meant by catching the change to the editor. Didn't realize that was possible. Very helpful, thanks :)

For anyone needing this filter, append an equal sign to the operators to capture the letters Aa and Zz: <=, >=


ooops, my bad :) Thnx for fixing!