StrongJoshua / libgdx-inGameConsole

A LibGdx library that allows a developer to add a console (similar to how it is featured in Source games) to their game.
https://www.strongjoshua.net/projects/games/libgdx-ingame-console
Apache License 2.0
132 stars 34 forks source link

Illegal argument exception for boolean type #18

Closed ThaBalla1148 closed 8 years ago

ThaBalla1148 commented 8 years ago

Creating a command with a boolean as an argument does not work.

Example:

public class MyCommandExecutor extends CommandExecutor {
        public void test(boolean t) {
            console.log(String.valueOf(t));
        }
    }
ThaBalla1148 commented 8 years ago

This part of exeCommand(String command) does not account for a boolean:

// attempt to convert arguments to numbers. If the conversion does not work, keep the argument as a string.
        Object[] args = null;
        if (sArgs != null) {
            args = new Object[sArgs.length];
            for (int i = 0; i < sArgs.length; i++) {
                String s = sArgs[i];
                try {
                    int j = Integer.parseInt(s);
                    args[i] = j;
                } catch (NumberFormatException e) {
                    try {
                        float f = Float.parseFloat(s);
                        args[i] = f;
                    } catch (NumberFormatException e2) {
                        args[i] = s;
                    }
                }
            }
        }

I'm actually looking into rewriting and fixing this code.

ThaBalla1148 commented 8 years ago

Fixed in pull request #19