Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Quote:
|
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
thanks everyone patiently anser, i got point that unique is important,
although it is a bit unsightly code to use, but i tend to use like this PHP Code:
|
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
I recently realized cleaning entity index trackers was also an option (from OnEntityDestroyed) and lately used that approach instead of entity references system, for just one entity as max. in my case. However, cleaning the appropiate variable can become inconvenient once handling enough amount of possible tracked entities, as it requires conditioning to match against the appropiate variable each case.
But as long as you handle few entity tracking variables, storing indices is perfectly adequate and efficient in terms of a gameplay session (vs. calling EntRefToEntIndex continuatedly) as long as you clear the variables at OnEntityDestroyed (aka assigning them to e.g. INVALID_ENT_REFERENCE). Obviously this approach is unproductive if perfoming extra checks other than entity != INVALID_ENT_REFERENCE for validating. |
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
AdRiAnIlloO, same mistake as I described above. Those entity can be replaced very soon. So, your kind of check will return "entity exists and valid", however, that is other entity, not the one you initially tracked. As a result you will target (and perhaps, further delete) someone else's entity, causing hard-to-trace bug. EntIndexToEntRef guarantee the index become unique and will not be replaced with another one newly created entity having same ref index.
|
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Citing your own quote.
Quote:
Or, is it that OnEntityDestroyed could be called after engine assigned the passed index to a new entity? From the SDK, entities are usually totally removed one frame after requested, for security reasons, during which I wonder if engine could free their index (haven't reached to confirm it). But basically what he is saying is the same than you and me pointed, why not to use the OnEntityDestroyed approach when it seems perfectly valid (if not loosing productivity, as I explained) against ent ref checks. |
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Well, I already explained. But, ok, show me code example of a real task according to your suggestion and I'll tell you why.
|
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Sorry for the delay, was busy. Here goes the parts of interest for my entity-tracking variable (which aims to refer to an env_sprite):
Code:
int gKingSprite = INVALID_ENT_REFERENCE; // Global scope declarationNote SM should always pass entity indices for networked (edict-full) entities (and internal entrefs for non-networked entities instead) to the entity forwards. PS: Also, I've confirmed OnEntityDestroyed only gets called upon total entity destruction (that is, after the security game frame happens originated from the common entity destroy requests from Source games): CGlobalEntityList::NotifyRemoveEntity -> SDKHooks::OnEntityDeleted, but it seems the edict (and thus, index) should be destroyed right after. |
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Yeah, in such way it is safe.
I don't remember which one case I told above, sorry. |
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Quote:
|
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Which is faster, FormatEx or strcopy?
|
| All times are GMT -4. The time now is 22:27. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.