You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have tried my absolute best to reduce the problem-space and have provided the absolute smallest test-case possible.
I can always reproduce the issue with the provided description below.
Environment
Operating System version: Windows 10 x64
Game/AppID (with version if applicable): not applicable
Current SourceMod version: 1.12
Current SourceMod snapshot: 1.12.0.7030
Current Metamod: Source snapshot: not applicable
I have updated SourceMod to the latest version and it still happens.
I have updated SourceMod to the latest snapshot and it still happens.
I have updated SourceMM to the latest snapshot and it still happens.
Description
Could we have the ability to initialize vectors (i.e. float arrays of size 3) as NULL_VECTOR?
Using NULL_VECTOR to signify the variable hasn't yet received its proper value (or the proper value could not be calculated) is often convenient for vectors, since the default-initialized value of { 0.0, 0.0, 0.0 } (or other magic values) could overlap with a real value, and the IsNullVector check also spares the programmer from having to check all three of the X,Y,Z elements when that's not really what they semantically meant.
Problematic Code (or Steps to Reproduce)
Instead of:
voidfoo()
{
floatvec[3];
vec=NULL_VECTOR;
}
one could write:
// this does not compilevoidfoo()
{
// with array size specifiedfloatv1[3] =NULL_VECTOR; // "error 047: array sizes do not match, or destination array is too small"// or with implicit array size, evenfloatv2[] =NULL_VECTOR; // "error 047: array sizes do not match, or destination array is too small"
}
This gets particularly annoying when wanting to initialize a static variable in global scope as NULL_VECTOR:
// some_include.incstaticfloatmy_encapsulated_vec[3];
// because we can't touch "my_encapsulated_vec" from the main .sp filevoidInitTheThingsOfThisInclude()
{
my_encapsulated_vec=NULL_VECTOR;
}
The text was updated successfully, but these errors were encountered:
Rainyan
changed the title
[Feature Request] Initialize float[3] as NULL_VECTOR
[Feature Request] Ability to initialize float[3] as NULL_VECTOR
Jul 12, 2023
Rainyan
changed the title
[Feature Request] Ability to initialize float[3] as NULL_VECTOR
[Feature Request] Add ability to initialize float[3] as NULL_VECTOR
Jul 12, 2023
This specific usecase of assigning NULL_VECTOR to be used with IsNullVector won't work though. since IsNullVector checks if the passed parameter is a reference to the global NULL_VECTOR pubvar. Copying NULL_VECTOR to some other variable won't pass that check.
Ah, I just incorrectly assumed I would be able to use NULL_VECTOR like this. I guess the feature request still stands of wanting to use NULL_VECTOR assignment together with IsNullVector like this, although feel free to close as invalid, if you see fit 😅
(1) This assignment should work. I'm keeping the bug open for that.
(2) As @peace-maker explained, it wouldn't do what you want. SM could consider populating NULL_VECTOR with NaN values, and changing null vector tests to look at that. It could be a breaking change though.
This is a very complicated issue to fix given that the language doesn't have nullable types.
Help us help you
Environment
Description
Could we have the ability to initialize vectors (i.e. float arrays of size 3) as NULL_VECTOR?
Using NULL_VECTOR to signify the variable hasn't yet received its proper value (or the proper value could not be calculated) is often convenient for vectors, since the default-initialized value of
{ 0.0, 0.0, 0.0 }
(or other magic values) could overlap with a real value, and theIsNullVector
check also spares the programmer from having to check all three of the X,Y,Z elements when that's not really what they semantically meant.Problematic Code (or Steps to Reproduce)
Instead of:
one could write:
This gets particularly annoying when wanting to initialize a static variable in global scope as NULL_VECTOR:
when all of this could be a one-liner initialization, as with most primitive types:
The text was updated successfully, but these errors were encountered: