Stencyl 3.4.0 is now out. Get it now!

Shift & Backspace When Typing in Name

NickamonPoppytail

  • *
  • Posts: 641
Hello,

I’m creating a scene where the player can name their character, but how do I get the backspace and shift keys to work?

I have currently got an “Any Key” event and have got “key code = key code of <whatever> key” in, but how do I get these keys to carry out their regular function?

Thank you!

merrak

  • *
  • Posts: 1688
You have to strip out the last character from the input string when the backspace key is struck. I attached an example I wrote, but mine is a bit more complex than is necessary (because I also have a cursor the user can move with the mouse and left/right arrows). It should illustrate the basic idea using the text manipulation blocks, though.

NickamonPoppytail

  • *
  • Posts: 641
You have to strip out the last character from the input string when the backspace key is struck. I attached an example I wrote, but mine is a bit more complex than is necessary (because I also have a cursor the user can move with the mouse and left/right arrows). It should illustrate the basic idea using the text manipulation blocks, though.

I have a game attribute "Name" and a number attribute "Character Count".

My code is "set Name to part of Name (start: ? end: Character Count - 1)". What should I put in the place of the question mark?

NickamonPoppytail

  • *
  • Posts: 641
Just looked up the "part of text" block in the Blocks Guide and I think I have the backspace key working now, but what about the shift key?

NickamonPoppytail

  • *
  • Posts: 641
Just looked up the "part of text" block in the Blocks Guide and I think I have the backspace key working now, but what about the shift key?

Never mind. Shift key works automatically.

merrak

  • *
  • Posts: 1688
You have to strip out the last character from the input string when the backspace key is struck. I attached an example I wrote, but mine is a bit more complex than is necessary (because I also have a cursor the user can move with the mouse and left/right arrows). It should illustrate the basic idea using the text manipulation blocks, though.

I have a game attribute "Name" and a number attribute "Character Count".

My code is "set Name to part of Name (start: ? end: Character Count - 1)". What should I put in the place of the question mark?

If you want to remove the last character in the string, put 0 in for the start and "length of text" - 1 for the end. The 'character count' attribute is needed for the cursor... but if you don't have a cursor then don't worry about keeping a character count.

NickamonPoppytail

  • *
  • Posts: 641
You have to strip out the last character from the input string when the backspace key is struck. I attached an example I wrote, but mine is a bit more complex than is necessary (because I also have a cursor the user can move with the mouse and left/right arrows). It should illustrate the basic idea using the text manipulation blocks, though.

I have a game attribute "Name" and a number attribute "Character Count".

My code is "set Name to part of Name (start: ? end: Character Count - 1)". What should I put in the place of the question mark?

If you want to remove the last character in the string, put 0 in for the start and "length of text" - 1 for the end. The 'character count' attribute is needed for the cursor... but if you don't have a cursor then don't worry about keeping a character count.

Thank you. I just figured that out.