Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

so I am using Guide.BeginShowKeyboardInput to get the user to enter their username. I would like this to be limited to 20 characters, and it seems to break expected behaviour to let them input whatever they like and trim it later - so how would I go about limiting what they can input in the text box itself? I have the following code:

public string GetKeyboardInput(string title, string description, string defaultText, int maxLength)
    {
        if (input.CheckCancel())
        {
            useKeyboardResult = false;
            KeyboardResult = null;
        }

        if (KeyboardResult == null && !Guide.IsVisible)
        {
            KeyboardResult = Guide.BeginShowKeyboardInput(PlayerIndex.One, title,
                                                          description, defaultText, null, null);
            useKeyboardResult = true;
        }
        else if (KeyboardResult != null && KeyboardResult.IsCompleted)
        {
            string result = Guide.EndShowKeyboardInput(KeyboardResult);
            KeyboardResult = null;
            if (result == null)
            {
                useKeyboardResult = false;
                return null;
            }

            if (useKeyboardResult)
            {
                KeyboardResult = null;
                return result;
            }
        }
        else //the user is still entering inputs
        {

        }

        return null;
    } 

I assume the code I need would go in that final, empty else{} block, but I can't see any way to do this. Does anyone know how?

share|improve this question
    
There doesn't seem to be a way to do this. What you see in the Guide class API is what you get. –  Andrew Russell Jun 2 at 10:14
    
Well that's a shame. Any thoughts on another way to do what I want then? –  simonalexander2005 Jun 2 at 13:56
    
Probably have to implement your own keyboard. –  Andrew Russell Jun 2 at 14:48
    
Can't you just parse the string returned from Guide.EndShowKeyboardInput to remove disallowed characters? –  Brian Gradin Jun 5 at 13:23
    
Or I guess if you're going for maximum length, trim however many characters over 20 they've entered? –  Brian Gradin Jun 5 at 13:24
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.