How do I read commands from text box input?

0 favourites
  • 3 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • Hello!

    I am currently working on a game where the player sprite moves according to commands that I type into a text box.

    What I could achieve was simple text comparison. For example, if I enter "go" move 50 pixels to the right.

    But what I want is something to analyse different parts of the input command, so for example if I enter "right50" it will recognize "right" and the number after it and move according to what I entered.

    Its simply like in programming languages where you have a command and some stuff after it to explain how the command should be done, like in Python where for example print("hello") "print()" was the command and "hello" was the "stuff" or in C++ cout << "hello" "cout" was the command and " << 'hello' " was the "stuff".

    I hope I explained as much as you need to understand what I mean

    Thank you

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I think, the easiest way is with 'tokenat'. If you have more complex command you have to use Regex.

    from the manual:

    "tokenat(src, index, separator)

    Return the Nth token from src, splitting the string by separator. For example, tokenat("apples|oranges|bananas", 1, "|") returns oranges."

    I made a little example with tokenat:

    the commands are: left, right, up, down, and the amount of pixels to move.

    left 50 for example

  • Thank you so much! Just what I needed!

    Looked confusing at first and took me a little while to understand how it works but eventually I got it thanks to the example you gave.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)