Registering a custom command

edited January 2013 in Help request
Hey. Can someone give me an example of how to register a custom command? My function will have only one variable and no optional variables. It will accept an orx object ID, and will return nothing.

The thing I'm hung up on is how the parameter lists are supposed to work.

Can someone help me? The sooner, the better. I got lazy and stopped working on it for a while, and want to get development rolling again. Thanks guys!

Comments

  • edited January 2013
    Hey sonicbhoc, nice to see you around! :)

    First of all, you need to return something from your command. Worst case you can return 0 or the same GUID you got as parameter which allows easy re-stacking in a timeline.

    Well, here's an example of such a command registration:
    orxCOMMAND_VAR_DEF stResult = {"ReturnGUID", orxCOMMAND_VAR_TYPE_U64};
    orxCOMMAND_VAR_DEF stParam = {"ObjectGUID", orxCOMMAND_VAR_TYPE_U64};
    
    orxCommand_Register("MyCommandName", MyCommandFunction, 1, 0, &stParamList, &stResult);
    

    Now that being said, I get lazy when working on my own games in those cases. I usually simply use inputs to communicate back to the code.
    Something like:
    [MyCommandTrack]
    0 = Config.SetValue RunTime ObjectParam ^ # ; Stores the object GUID in config
        Input.SetValue MyCommandInput 1         ; Triggers the input
    

    And in code I'd then test for the input MyCommandInput to be triggered and would fetch the object GUID from console with
    orxConfig_PushSection("RunTime"); orxConfig_GetU64("ObjectParam"); orxConfig_PopSection();
    
  • edited January 2013
    Oh, and for the command function itself, here's how it works:
    void orxFASTCALL MyCommandFunction(orxU32 _u32ArgNumber, const orxCOMMAND_VAR *_astArgList, orxCOMMAND_VAR *_pstResult)
    {
      orxOBJECT *poObject;
    
      // Gets object
      poObject = orxOBJECT(orxStructure_Get(_astArgList[0].u64Value));
    
      // Do something with the object
      // ...
    
      // Updates result
      _pstResult->u64Value = _astArgList[0].u64Value;
    }
    
Sign In or Register to comment.