How can I make a simple text input?

Fayabella

  • Posts: 221
Heya,

I need a simple text input for my game, where the player types something and it's saved as an attribute, or used as a command.

I tried the text input extension but couldn't get it to work. All I need is 2 things: when the player presses a key, it opens the text, and doesn't let the player's controls work until they are done (typing W won't move the player up). That's for ingame commands. But also, I need some text boxes that when the player clicks on them, they can type in them. These are for player name/world generator seed.

What's the simplest way to do this?

CmdrWhitey13

  • Posts: 503



A simple implementation of a text-field behavior.

Should give you a starting point.
Hope it helps.

Biiiscoito

  • Posts: 21
Such a pity that you couldn't get the Text Input Extension to work for you  :(. It's the extension I had the least amount
of trouble with. Are you sure it is enabled?
I'm attaching the piece of code I used it into, in case it helps you give it a second chance.
The When Drawing events just work to draw some rectangles where the text field will be so it actually looks like a place
where the player can type.
As for "not allowing the player to move or press other commands if he's typing"-problem, I suggest using a boolean.
Like, if you use the Text Input Extension, you can check if that text-box exists or is not null, and then turn on another boolean that renders the other commands invalid.
I usually have a GA Disable Movement that handles these situations. The codes where my key-is-pressed are always start with "if not Disable Movement", and it saves me from more trouble.

//Added a printscreen of the result from this code.
"Qual é o seu nome?" translates to "What is your name?" and "Meu nome" translates to "My name" :>

« Last Edit: May 28, 2019, 11:09:04 pm by Biiiscoito »

vicevicebingo

  • Posts: 60
pause game

this actor can't be paused
who helps input the texts

enter the name

unpause game

or you just create a fake player
with no controls lol

« Last Edit: May 29, 2019, 02:18:10 am by vicevicebingo »

Fayabella

  • Posts: 221
Such a pity that you couldn't get the Text Input Extension to work for you  :(. It's the extension I had the least amount
of trouble with. Are you sure it is enabled?
I'm attaching the piece of code I used it into, in case it helps you give it a second chance.
The When Drawing events just work to draw some rectangles where the text field will be so it actually looks like a place
where the player can type.
As for "not allowing the player to move or press other commands if he's typing"-problem, I suggest using a boolean.
Like, if you use the Text Input Extension, you can check if that text-box exists or is not null, and then turn on another boolean that renders the other commands invalid.
I usually have a GA Disable Movement that handles these situations. The codes where my key-is-pressed are always start with "if not Disable Movement", and it saves me from more trouble.

//Added a printscreen of the result from this code.
"Qual é o seu nome?" translates to "What is your name?" and "Meu nome" translates to "My name" :>

Ah, okay, I'll set up a game attribute.

I tried using your setup for the name thing, and I have two problems:
One, I can't load my custom font. I put the .ttf in the 'extras' folder of the game and when I try to load it, I get this error:
Code: [Select]
TypeError: Error #1034: Type Coercion failed: cannot convert __ASSET__assets_data_coders_crux_2_ttf@10d73d41 to lime.text.Font.
at lime.utils::AssetLibrary/loadFont()
at lime.utils::AssetLibrary/loadAsset()
at lime.utils::Assets$/loadAsset()
at lime.utils::Assets$/loadFont()
at openfl.utils::Assets$/loadFont()
at Tin$/loadfontfromassets()[E:\Stencyl Steffimiwhetsets\stencylworks\engine-extensions\Text Input\Tin.hx:125]
at scripts::SceneEvents_2/init()[E:\Stencyl Steffimiwhetsets\stencylworks\games-generated\Forest\Source\scripts\SceneEvents_2.hx:1184]
at com.stencyl.behavior::Behavior/initScript()[C:\Program Files (x86)\Stencyl\plaf\haxe\lib\stencyl\1,00\com\stencyl\behavior\Behavior.hx:107]
at com.stencyl.behavior::BehaviorManager/initScripts()[C:\Program Files (x86)\Stencyl\plaf\haxe\lib\stencyl\1,00\com\stencyl\behavior\BehaviorManager.hx:97]
at com.stencyl::Engine$/initBehaviors()[C:\Program Files (x86)\Stencyl\plaf\haxe\lib\stencyl\1,00\com\stencyl\Engine.hx:1255]
at com.stencyl::Engine/loadScene()[C:\Program Files (x86)\Stencyl\plaf\haxe\lib\stencyl\1,00\com\stencyl\Engine.hx:1154]
at com.stencyl::Engine/begin()[C:\Program Files (x86)\Stencyl\plaf\haxe\lib\stencyl\1,00\com\stencyl\Engine.hx:947]
at com.stencyl::Engine()[C:\Program Files (x86)\Stencyl\plaf\haxe\lib\stencyl\1,00\com\stencyl\Engine.hx:736]
at Universal/preloaderComplete()[C:\Program Files (x86)\Stencyl\plaf\haxe\lib\stencyl\1,00\Universal.hx:408]
at lime.app::_Event_Void_Void/dispatch()
at scripts::StencylPreloader/unload()[E:\Stencyl Steffimiwhetsets\stencylworks\games-generated\Forest\Source\scripts\StencylPreloader.hx:339]
at scripts::StencylPreloader/onLoaded()[E:\Stencyl Steffimiwhetsets\stencylworks\games-generated\Forest\Source\scripts\StencylPreloader.hx:308]
at lime.app::_Event_Void_Void/dispatch()
at lime.utils::Preloader/start()
at lime.utils::Preloader/updateProgress()
at lime.utils::Preloader/current_onEnter()
And when I use a default font, it works, until I click on it to type and I get this:
Code: [Select]
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MethodInfo-9926()[E:\Stencyl Steffimiwhetsets\stencylworks\games-generated\Forest\Source\scripts\SceneEvents_2.hx:1216]
at com.stencyl::Engine/update()[C:\Program Files (x86)\Stencyl\plaf\haxe\lib\stencyl\1,00\com\stencyl\Engine.hx:2505]
at com.stencyl::Engine/postUpdate()[C:\Program Files (x86)\Stencyl\plaf\haxe\lib\stencyl\1,00\com\stencyl\Engine.hx:2799]
at com.stencyl::Engine/onUpdate()[C:\Program Files (x86)\Stencyl\plaf\haxe\lib\stencyl\1,00\com\stencyl\Engine.hx:2791]

And one more thing- when I do the commands, I want it to be so that the player doesn't click on a textbox. If they hit the / key, it shows up and they type. Does the textbox extension only work with clicking?

Fayabella

  • Posts: 221
I figured out the clicking error. I had a 'click' event for my game itself, used fr placing items/destroying them. The level hadn't been generated yet when I clicked the text.

I still have the problem with getting my custom font.

Biiiscoito

  • Posts: 21
Sorry for the super late response.
For the font, make sure it is .ttf if you set it up like that on the game, or .otf if you set it like it.
The names need to be exactly equal. Even capital letters.
I see your font has a '-' between two words. Have you tried renaming it to another name? Stencyl trips on custom characters like mad. Unfortunately, that's as far as my knowledge goes, I'm afraid. I've used Stencyl for a very short time in comparisson to other experienced members "^-^

Fayabella

  • Posts: 221
Hmm...

I renamed it to something simpler, and even tried using other fonts, but it still gave the same error.

It seems to have a problem with this:
Code: [Select]
Tin.create("Name"); {Tin.loadfontfromassets("Crux.ttf");
How odd. I don't know why it's not working.

vicevicebingo

  • Posts: 60
Hmm...

I renamed it to something simpler, and even tried using other fonts, but it still gave the same error.

It seems to have a problem with this:
Code: [Select]
Tin.create("Name"); {Tin.loadfontfromassets("Crux.ttf");
How odd. I don't know why it's not working.

what use of 'extras' folder? maybe
billscoito doesn't use extras folder

Fayabella

  • Posts: 221
Where should I put the files, then?

Fayabella

  • Posts: 221
I put the ttf file in multiple places in the game workspace folder but still got the same error. I think it's supposed to be in ''extras."

Is there a thread somewhere for questions about the extension?