Game Maker Studio Android Native extension – Input Text

Hi there!

Often we need the user to input some text for getting a nickname, age, friend number, any ID, or maybe a promotional code for unlocking some rewards.
Well, in these cases we can choose to create a soft keyboard by ourselves, which is a long and tedious process or to show the Android native keyboard and getting the input text from that.
And we oftern choose the latter.

But, Game Maker Studio does not actually have a function to show and get text from the Android native keyboard, and it’s exactly for this purpose that I’ve made my new extension.
It is called inputTextEx and it is totally FREE.

You can get inputTextEx HERE ON GAME MAKER MARKETPLACE.

This extension will open a popup for requesting the user to input some text and then call a social async event into Game Maker passing the input text can be used for getting usernames, promo codes, numbers etc etc

Here’s you can see the extension in action:
screen1screen3

 

 

 

 

 

 

 

 

 

Usage:

simply call

showInputText(String strTit,String strYes,String strNo)

from game maker
for opening the popup.
Example:

showInputText(“Title Text”, “OK”, “Cancel”)

and, in a social async event put some code like this:

var type = string(async_load[? “type”])
var data = string(async_load[? “data”])
//check for INPUTTEXT type of event
if type == “INPUTTEXT”
{
//Here you should receive the string containing the text written by the user
//which is stored inside the variable called “data”
var StringWrittenByUser = data
//now use it as you please
}
}
Note that:
We will receive “type” and “data” into the async event.
“type” received will be “INPUTTEXT”
“data” received will be the text input by the user

ADDITIONAL NOTE: the keyboard won’t never go fullscreen, and the function both works for PORTRAIT and LANDSCAPE orientations

That’s it!
Simple and effective: with just a few line of codes you can now get any information from the user and use them within your Game Maker Studio game.

Remember that I’m doing this totally for FREE! So to support me don’t forget to rate and review the extension on Game Maker Marketplace, or download my games from Google Play!

If you need help, support or anything else don’t hesitate to contact me or reply to this blog entry.

NOTE: as a final note, please keep in mind that this extension is designed for Android API 11 and above. So please set your Min SDK option to 11 (or above) within Global Game Settings > Android or you will get a lint error while compiling for Android.

That’s all, happy coding!

Comments

  • will have a basic example , I can not use it well

    tovidiJanuary 23, 2016
    • Hi Tovidi, thanks for the interest in my extension.

      The extension just works by following two simple steps:
      1: put this exact code in an event code block when you want the popup to be opened:

      showInputText(“Title Text”, “OK”, “Cancel”)

      This will make the popup open.

      2: In a Social Async event, put this exact code:

      var type = string(async_load[? “type”])
      var data = string(async_load[? “data”])
      if type == “INPUTTEXT”
      {
      //Here you should receive the string containing the text written by the user
      //which is stored inside the variable called “data”
      var StringWrittenByUser = data
      //now use it as you please
      }

      Be sure that the object in which you put this code is active in the room when the popup closes.

      Alright, I hope that this can help you!
      Let me know if you can make it work now! 🙂
      Happy coding!

      Mattia FortunatiJanuary 24, 2016
      • Thanks, everything is solved, the problem was “(the quotes the example), when he turned to writing and did not fix any errors and works very well

        tovidiJanuary 24, 2016
  • Hi

    showInputText(“Title Text”,“OK”,“Cancel”)

    ERROR at line1 pos 15: Unexpected symbol.

    _______________________________________________________________________________________________

    var type = string(async_load[? “type”])
    var data = string(async_load[? “data”])

    //check for INPUTTEXT type of event

    if type == “INPUTTEXT”
    {
    //Here you should receive the string containing the text written by the user
    //which is stored inside the variable called “data”
    var StringWrittenByUser = data
    //now use it as you please
    }

    ERROR at line1 pos 32: Unexpected symbol.

    thanks

    tovidiJanuary 24, 2016
  • Thanks, everything is solved, the problem was “(the quotes the example), when he turned to writing and did not fix any errors and works very well

    tovidiJanuary 24, 2016
  • hi mattia , sorry for this
    this extension very usefull for me and can help me to create android extension but ,
    i can’t download from market place !
    can you send to my mail but if you can’t send this to me , no problem very thanks .

    aminMarch 6, 2016
    • Hi Amin,
      I’m always glad to help my fellow developers 🙂
      I’ve just sent you an email with the latest version of my Input Text extension!
      Have a nice day!

      Mattia FortunatiMarch 6, 2016
  • hi,
    i can’t download from market place too.
    ¿Can you send to my mail?
    pliss
    I would really appreciate it.

    CristoApril 9, 2016
    • Hi Cristo,
      I’ve just sent it to you through email 🙂
      Have a nice day!

      Mattia FortunatiApril 9, 2016
  • Can you send me through email too? I’m having issues with the marketplace since the forums went down

    gregMay 12, 2016
    • Hi Greg,
      sure thing!
      I’ve just sent an email to you!
      Have a nice day!
      😀

      Mattia FortunatiMay 16, 2016
  • It does not work I could help with an example
    mi demo https://drive.google.com/file/d/0B4cR3S8865zrcmJETk9NeWNYMXM/view?usp=sharing

    pedroJune 20, 2016
    • Hi Pedro!
      Thanks for the interest in my extension!
      I’ve checked and tested your code and everything is working except for a thing:
      You wrote:

      //check for INPUTTEXT type of event if type == "INPUTTEXT" { var user="Input Text Received" }else var user="no recibe"

      The fact is that the variable “user” is already declared within the create event. It is not working because you are declaring it again within the social async event. The draw event actually draws the varible declared by the create event and not this new “user” variable declared within the social async event. Easy fix: remove the declaration! Simply remove “var”, like this:

      //check for INPUTTEXT type of event if type == "INPUTTEXT" { user="Input Text Received" }else user="no recibe"

      This way it is perfectly working for me on an actual Android device!

      Oh, let me suggest you another free extension that I’ve released
      http://www.mattiafortunati.com/game-maker-studio-android-native-extension-log-to-console/
      to help you debug your code more efficiently!

      I hope I’ve been helpful, have a nice day! 😀

      Mattia FortunatiJune 21, 2016
  • Thanks, works fine and was exactly what I needed. (Will list it in my credits btw)

    But one question, is it possible to check for which button was pressed – ok or cancel?

    TobiasJuly 18, 2016
    • Nice! Glad to hear that!
      And thanks for the mention in your credits!

      About the buttons: no, sorry, at the moment you can just choose what’s written in each one and just receive a callback when the “Ok” button is pressed. When the “Cancel” button is pressed, the dialog simply closes, going back to the game.

      Have a nice day! 🙂

      Mattia FortunatiJuly 18, 2016
  • Hello, I’ve been trying to use your extension, but when I try to test it I get this error message on the cmd window:

    I/yoyo (14003): Attempting to call extension function with no extensions loaded showInputText on class inputTextClass

    Any idea of what I’m doing wrong?

    Thanks,

    Glauber

    GlauberOctober 19, 2016
    • Hi Glauber!
      How are you testing your game?
      Remember that, since it’s an Android-only extension, it will only work if you build an actual apk.
      Testing it on windows or with YoYo runner won’t work.
      That’s because Android extensions are built along with the game only when creating an apk.

      Mattia FortunatiOctober 20, 2016
  • Hi Mattia
    I’m trying to use your great extension, and as what you said to Glauber (previous comment), I choosed the apk file build solution, but what no pop up showed up. When I tap on the object which is responsible to bring up the keyboard, this line adds to log :
    I/yoyo (14546): Exception thrown trying to call method showInputText on inputTextClass
    here is full log: http://pastebin.com/TFa0DDDG
    Thanks for any help!

    AliOctober 26, 2016
    • Hi,
      thanks for using my extension, and thanks for the full log details.

      I’ve tried my extension again, in a new project made from scratch, with just the popup showing on any tap release, and it is working correctly for me, I couldn’t reproduce the error.
      By investigating the log, it seems that in your case the extension is not found, not correclty installed or not built along with the game.

      Let’s see if I can give you some suggestions:
      -which version of GMS are you actually using? I’m using 1.4.1763
      -try to clean the target before building again.
      -try to uninstall the extension and re-install it again.
      -try to check once again your Android tabs within “File > Preferences” and “Global Game Settings”.
      -try to do as I did: create a new project and just add something like “showInputText(“Please, insert your PROMO CODE”,”Ok”, “Cancel”)” in a “Glob Left Release” Mouse Event as see if it works. If it still doesn’t work check the preferences and settings again.
      -finally, if you are using some Game Maker Early Access Build, in some cases, you need to add this: compile ‘com.android.support:appcompat-v7:+’ into the extension’s “inject to Gradle dependencies” box. I’ve never needed or tried it though.
      Thanks go to Tom http://roadhammergaming.blogspot.it/ for this suggestion.

      Sorry if a couple of these are just stupid, but they might work pretty well sometime! 🙂
      I hope this can be helpful to you! 😀

      Mattia FortunatiOctober 26, 2016
  • Hello,
    Thanks for the extention but whene I export to APK it said “abortOnError false”
    Here is more from the log:

    companyname.Project1:compileDebugJavaWithJavac UP-TO-DATE
    :com.companyname.Project1:compileLint
    :com.companyname.Project1:lint
    Ran lint on variant debug: 57 issues found
    Ran lint on variant release: 57 issues found
    Wrote HTML report to file:///Z:/com.companyname.Project1/build/outputs/lint-results-debug.html
    Wrote XML report to file:///Z:/com.companyname.Project1/build/outputs/lint-results-debug.xml
    :com.companyname.Project1:lint FAILED

    FAILURE: Build failed with an exception.

    * What went wrong:
    Execution failed for task ‘:com.companyname.Project1:lint’.
    > Lint found errors in the project; aborting build.

    Fix the issues identified by lint, or add the following to your build script to proceed with errors:

    android {
    lintOptions {
    abortOnError false
    }
    }

    * Try:
    Run with –stacktrace option to get the stack trace. Run with –info or –debug option to get more log output.

    BUILD FAILED

    Total time: 53.102 secs
    cmd /c “subst /d Z:”

    Lint Build report available at C:\Users\es32\Documents\GameMaker\Cache\Project1\Android\Default\com.companyname.Project1\build\outputs\lint-results.html
    Create finished: 8:48:24 AM

    Can You help please?

    IssamSaleemMarch 6, 2017
    • Hi,
      Since this extension is designed for Android API 11 and above, as first step set your Min SDK option to 11 (or above) within Global Game Settings > Android.
      And clean before another build.

      If the error still occurs, you can check what is causing it by checking the lint-results.html report, which in your case is here:
      “Lint Build report available at C:\Users\es32\Documents\GameMaker\Cache\Project1\Android\Default\com.companyname.Project1\build\outputs\lint-results.html”

      For more information about how to fix lint error in Game Maker you can also check my other blog post here:
      http://www.mattiafortunati.com/game-maker-studio-tutorial-how-to-fix-lint-errors-while-building-for-android/

      Cheers! 😀

      Mattia FortunatiMarch 6, 2017
  • Thanks for the replay,Its work and export depend on what you said,Now my problem is the typing page still repeat again and again,What I want to do is a text will change to printed one when we press.

    IssamSaleemMarch 6, 2017
    • Maybe you are calling it more than one time, like in a step event.
      Try to double-check your code.

      Call
      showInputText(“Title Text”, “OK”, “Cancel”)
      just one time like in a create event, or mouse event.

      Then, in the social async event, receive the text
      var data = string(async_load[? “data”])
      and use it to change the text you need.

      Check the code above in this blogpost for more information and the example code.

      Mattia FortunatiMarch 7, 2017
  • You are a legend 🙂 ,Very very thank you Mattia

    IssamSaleemMarch 7, 2017
  • hi mattia, I am really grateful for your extension but above all for your help in supporting the problems, seriously when I have the opportunity to reward you I will, you have saved me from big something

    DannyjptSeptember 4, 2017
  • Uhm,and how about to add this in a app developed with gms, but exported in apk using apktool (Reverse Engineering the YoYo Runner) … because it is not working, and i see that the extension is injecting to androidmanifest.xml, a code …

    I really need to know how to implement this in my game. If you teach me, you will appear on my credits 🙂 .

    EduardoSeptember 20, 2017
    • I’m sorry I don’t know how the building process you are using works.
      I suggest you to use the conventional building method provided by Game Maker Studio by default, to avoid incompatibilities and post-build issues/bugs.

      Mattia FortunatiSeptember 21, 2017

Leave a Reply to IssamSaleem Cancel reply

%d bloggers like this: