Eventdef System Does Not Like Optional Args: Difference between revisions

From The DarkMod Wiki
Jump to navigationJump to search
No edit summary
 
No edit summary
Line 13: Line 13:
  EVENT( EV_TDM_PropSound,        idEntity::Event_PropSound )
  EVENT( EV_TDM_PropSound,        idEntity::Event_PropSound )
  EVENT( EV_TDM_PropSoundMod,        idEntity::Event_PropSound )
  EVENT( EV_TDM_PropSoundMod,        idEntity::Event_PropSound )
 
  // ...
  // ...
 
  void idEntity::Event_PropSoundMod( const char *sndName, float VolModIn = 0.0f );
  void idEntity::Event_PropSoundMod( const char *sndName, float VolModIn = 0.0f );



Revision as of 16:16, 11 September 2006

Originally written by Ishtvan on http://forums.thedarkmod.com/topic/3359

Just wanted to give people a heads up, the Event system for linking script events to functions doesn't like being linked to functions with optional arguments, and not filling in the arguments for some things.

For example, I defined these two events:

const idEventDef EV_TDM_PropSoundMod( "propSoundMod", "sf" );
// I don't think scripting supports optional argument, so I must do this
const idEventDef EV_TDM_PropSound( "propSound", "s" );

I tried linking both of them to an Event_PropSound function with an optional float argument, like so:

EVENT( EV_TDM_PropSound,        idEntity::Event_PropSound )
EVENT( EV_TDM_PropSoundMod,        idEntity::Event_PropSound )

// ...

void idEntity::Event_PropSoundMod( const char *sndName, float VolModIn = 0.0f );

Apparently the Event system can't handle this. When propSound was called, and tried to call Event_PropSound without a float argument, instead of using the default float value in Event_PropSound, it crashed. dry.gif Apparently the number of args in the EventDef have to match the args in the linked function exactly, and it will not automatically fill in default values for optional args in the function you link to.

I was hoping it would act like a normal C++ function call where if you don't specify an optional argument, it uses the default, rather than having to match exactly the arguments you pass to the scriptevent and all args of the called function, even if they are option. Apparently not.