Talk:IO type variant

From Valve Developer Community
Jump to navigation Jump to search

Uh, what does param=variant mean?
SirYodaJedi (talk) 18:47, 5 May 2025 (PDT)

It means the parameter is passed to the input without converting it first if I understood it correctly
from logicentities.cpp where logic_case is + comments
...
DEFINE_INPUTFUNC(FIELD_INPUT, "InValue", InputValue)
...
COutputVariant m_OnDefault;
...
void CLogicCase::InputValue( inputdata_t &inputdata )
{
	const char *pszValue = inputdata.value.String(); //the value gets converted here to string, if InValue was of type FIELD_STRING it wouldn't be able to take anything beside string or ehandle as other conversions aren't implemented, see warning on material_modify_control's page near SetMaterialVar input 
	for (int i = 0; i < MAX_LOGIC_CASES; i++)
	{
		if ((m_nCase[i] != NULL_STRING) && !stricmp(STRING(m_nCase[i]), pszValue))
		{
			m_OnCase[i].FireOutput( inputdata.pActivator, this );
			return;
		}
	}
	
	m_OnDefault.Set( inputdata.value, inputdata.pActivator, this ); //m_OnDefault is also variant and it passes the same value that was received
}
So for example lets say InValue input is called from output of type float (without parameter override being set so the outputs value is passed). It gets the float without change, inside it converts to string then compares that to its cases and if there is no match then OnDefault is fired also with type variant with the same float that was received and can be accepted only by other variant type inputs.
These should be all the output types types + COutputEvent which means nothing being passed
// useful typedefs for allowed output data types
typedef CEntityOutputTemplate<variant_t,FIELD_INPUT>		COutputVariant; //seems that only logic_case has this
typedef CEntityOutputTemplate<int,FIELD_INTEGER>			COutputInt;
typedef CEntityOutputTemplate<float,FIELD_FLOAT>			COutputFloat;
typedef CEntityOutputTemplate<string_t,FIELD_STRING>		COutputString;
typedef CEntityOutputTemplate<EHANDLE,FIELD_EHANDLE>		COutputEHANDLE;
typedef CEntityOutputTemplate<Vector,FIELD_VECTOR>			COutputVector;
typedef CEntityOutputTemplate<Vector,FIELD_POSITION_VECTOR>	COutputPositionVector; //doesn't seem used anywhere
typedef CEntityOutputTemplate<color32,FIELD_COLOR32>		COutputColor32;
--Nescius (talk) 23:37, 5 May 2025 (PDT)
Well it seems variant output just gets voided anyway. I don't understand the purpose of COutputVariant now.
This is from cbase.cpp. COutputVariant calls this with ftype FIELD_INPUT which just goes through the default case.
Don't see the point of InputValue function calling it like this m_OnDefault.Set( inputdata.value, inputdata.pActivator, this ); passing the inputdata.value if it gets just set to 0 and type void.
void variant_t::Set( fieldtype_t ftype, void *data )
{
	fieldType = ftype;

	switch ( ftype )
	{
	case FIELD_BOOLEAN:		bVal = *((bool *)data);				break;
	case FIELD_CHARACTER:	iVal = *((char *)data);				break;
	case FIELD_SHORT:		iVal = *((short *)data);			break;
	case FIELD_INTEGER:		iVal = *((int *)data);				break;
	case FIELD_STRING:		iszVal = *((string_t *)data);		break;
	case FIELD_FLOAT:		flVal = *((float *)data);			break;
	case FIELD_COLOR32:		rgbaVal = *((color32 *)data);		break;

	case FIELD_VECTOR:
	case FIELD_POSITION_VECTOR:
	{
		vecVal[0] = ((float *)data)[0];
		vecVal[1] = ((float *)data)[1];
		vecVal[2] = ((float *)data)[2];
		break;
	}

	case FIELD_EHANDLE:		eVal = *((EHANDLE *)data);			break;
	case FIELD_CLASSPTR:	eVal = *((CBaseEntity **)data);		break;
	case FIELD_VOID:		
	default:
		iVal = 0; fieldType = FIELD_VOID;	
		break;
	}
}
--Nescius (talk) 06:28, 7 May 2025 (PDT)