Problem with code

MolinwareMolinware Posts: 82Member
edited January 2013 in ODK (OUYA Developer Kit)
So I'm new at java programming, do you know if something is wrong in the syntax of this code: OuyaController c = OuyaController.getControllerByPlayer(Integer.parseInt(_default)); 
if (c.getButton(OuyaController.BUTTON_O) || c.getButton(OuyaController.BUTTON_U) || c.getButton(OuyaController.BUTTON_Y)|| c.getButton(OuyaController.BUTTON_A) || c.getButton(OuyaController.BUTTON_DPAD_UP) || c.getButton(OuyaController.BUTTON_DPAD_DOWN) || c.getButton(OuyaController.BUTTON_DPAD_LEFT) || c.getButton(OuyaController.BUTTON_DPAD_RIGHT) || c.getButton(OuyaController.BUTTON_L1) || c.getButton(OuyaController.BUTTON_R1)){ return _default; }else{ return "-1"; }
Post edited by Molinware on

Best Answer

  • theaceofthespadetheaceofthespade Posts: 21Member
    Answer ✓
    Ah - the control state doesn't work for a bunch of buttons.  It's a bug in odk as far as I know right now.

Answers

  • theaceofthespadetheaceofthespade Posts: 21Member
    presumably the problem is that you are trying to return "-1", which is a string.  To return the integer -1, loose the quotes.
  • MolinwareMolinware Posts: 82Member
    I need to return a string.
    Do I need to do anything before 
    OuyaController c = OuyaController.getControllerByPlayer(Integer.parseInt(_default)); 
    to have acess to the controls?
  • theaceofthespadetheaceofthespade Posts: 21Member
    if you need to return a string, then you will have to cast _default as a string.
  • MolinwareMolinware Posts: 82Member
    edited January 2013
    Thank you again. :D
    Must be the bug. :(
    Post edited by Molinware on
  • arcticdogarcticdog Posts: 235Member
    Molinware said:
    I need to return a string.
    Do I need to do anything before 
    OuyaController c = OuyaController.getControllerByPlayer(Integer.parseInt(_default)); 
    to have acess to the controls?
    While this might be considered "pre-optimization" by some developers, I'd keep in mind that parse and cast functions can be expensive if used in a game update/draw loop due to the amount of code those operations explode into when it gets compiled. A string will also take up more memory than an integer.  Since you're beginning Java, if there's a way to NOT use strings when you don't need to, I'd urge you to break that habit early. :-)
  • MolinwareMolinware Posts: 82Member
    I do need to use a string. It's kind of a hack to use multiple controllers with the the Game Maker IDE.
    I know all of this concepts, if I could return an integer, then I would. 
Sign In or Register to comment.