Skip to content

[ALL] Resolve vscript naming conflict between CBaseCombatWeapon and CBaseEntity GetName by adding GetTargetname for CBaseEntity #1220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

FlaminSarge
Copy link

Description

CBaseEntity defines vscript function GetName which returns the targetname. CBaseCombatWeapon defines vscript function GetName which returns the classname, overriding this. Workarounds are needed to get targetname for CBaseCombatWeapons.

This PR creates GetTargetname for CBaseEntity, while maintaining all existing behavior for GetName for both entities for backwards compatibility.

@FlaminSarge FlaminSarge force-pushed the getname branch 3 times, most recently from 073e37f to ce8b68d Compare April 27, 2025 06:04
…tity GetName by adding GetTargetname for CBaseEntity

This remains fully backwards compatible.
@FlaminSarge
Copy link
Author

FlaminSarge commented Apr 27, 2025

Other potential changes:

  • Add GetWeaponName for CBaseCombatWeapon to fully differentiate it from GetName/GetTargetname
  • Name the func GetEntityName instead of GetTargetname

@FlaminSarge FlaminSarge marked this pull request as ready for review April 27, 2025 06:13
@TeamSpen210
Copy link

I don’t think it makes sense to change CBaseEntity here. Entity names are far more prevalent (It’s very likely to be used somewhere in any slightly complex VScript), I don’t think it’s tenable to change that or imply that’s wrong.

@FlaminSarge
Copy link
Author

FlaminSarge commented Apr 27, 2025

I don’t think it makes sense to change CBaseEntity here. Entity names are far more prevalent (It’s very likely to be used somewhere in any slightly complex VScript), I don’t think it’s tenable to change that or imply that’s wrong.

Unfortunately, in order to maintain full backwards compatibility, GetName()'s behavior has to stay exactly the same here (returning classname for CBaseCombatWeapon and targetname for all other CBaseEntitys) as we have no way of knowing where someone would be relying on the existing behavior.
If we enforce that 100% backwards compatibility, only remaining solution is to create a new function for CBaseEntity that returns Targetname at all times, to provide a substitute GetName's bugged behavior of returning classname on CBaseCombatWeapons (and to avoid the current direct m_iName workaround).

As in my other comment, creating a copy of CBaseCombatWeapon.GetName with a more specific function name is also on the table, but in either case we would have to maintain the existing GetName functionality to ensure compatibility. Many other VScript functions in CBaseEntity remain as legacy names because of backcompat issues (look for anything with !!!LEGACY FOR COMPAT!!! in it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants