ZScript equivalent to dev/null
Moderator: GZDoom Developers
- Matt
- Posts: 9696
- Joined: Sun Jan 04, 2004 5:37 pm
- Preferred Pronouns: They/Them
- Operating System Version (Optional): Debian Bullseye
- Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
- Contact:
ZScript equivalent to dev/null
Can we please get a pointer to throw unused output into?
The specific example I've got in mind is the bool that is called by A_SpawnItemEx. Literally every time I've ever needed the output of this function it was to get the actor, and the likelihood of it being false (assuming I wasn't using SXF_NOCHECKPOSITION) was low enough that simply checking for that actor being null was sufficient.
Yet every single time I do this I need to go out of my way to define a new local variable that serves no purpose except to fulfil this requirement, or do some really gross hack involving a flag that I figure that particular calling actor would never use.
It's a minor thing, but it does lead to a lot of needless clutter.
The specific example I've got in mind is the bool that is called by A_SpawnItemEx. Literally every time I've ever needed the output of this function it was to get the actor, and the likelihood of it being false (assuming I wasn't using SXF_NOCHECKPOSITION) was low enough that simply checking for that actor being null was sufficient.
Yet every single time I do this I need to go out of my way to define a new local variable that serves no purpose except to fulfil this requirement, or do some really gross hack involving a flag that I figure that particular calling actor would never use.
It's a minor thing, but it does lead to a lot of needless clutter.
- Graf Zahl
- Lead GZDoom+Raze Developer
- Posts: 49067
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: ZScript equivalent to dev/null
Normally that shouldn't be necessary, but the return values for this function are definitely in the wrong order.
- Marisa the Magician
- Posts: 3886
- Joined: Fri Feb 08, 2008 9:15 am
- Preferred Pronouns: She/Her
- Operating System Version (Optional): (btw I use) Arch
- Graphics Processor: nVidia with Vulkan support
- Location: Vigo, Galicia
- Contact:
Re: ZScript equivalent to dev/null
Unfortunately we can't change that without breaking who knows how many mods.
-
-
- Posts: 374
- Joined: Mon Jun 27, 2016 7:26 pm
- Preferred Pronouns: He/Him
- Graphics Processor: nVidia with Vulkan support
- Contact:
Re: ZScript equivalent to dev/null
JavaScript ES6 destructuring assignment (see "Ignoring some returned values") syntax allows developers to discard unnecessary values.
For example, a line of code from paledit:
For example, a line of code from paledit:
Code: Select all
let [start,] = this.subRanges[subRangeIdx].sorted();
Re: ZScript equivalent to dev/null
Heh, I run into this all the time. It's "cosmetic," but a bit of a PITA.
A suggestion: since there's already precedent for deprecating+renaming functions (e.g. A_FireCustomMissile to A_FireProjectile, albeit that was for a more serious reason) and the name "A_SpawnItemEx" is pretty antiquated anyway ("Ex" suffix, plus it spawns any actor, not just an "Item"), perhaps let's make an "A_SpawnActor" that has the same parameters & functionality but returns the Actor only. Nice n' clean.
[Also yes, we could DIY this mostly by implementing a proxy function, but it'd be nice for everyone to not to have to. ;]
A suggestion: since there's already precedent for deprecating+renaming functions (e.g. A_FireCustomMissile to A_FireProjectile, albeit that was for a more serious reason) and the name "A_SpawnItemEx" is pretty antiquated anyway ("Ex" suffix, plus it spawns any actor, not just an "Item"), perhaps let's make an "A_SpawnActor" that has the same parameters & functionality but returns the Actor only. Nice n' clean.
[Also yes, we could DIY this mostly by implementing a proxy function, but it'd be nice for everyone to not to have to. ;]
- Chris
- Posts: 2942
- Joined: Thu Jul 17, 2003 12:07 am
- Graphics Processor: ATI/AMD with Vulkan/Metal Support
Re: ZScript equivalent to dev/null
C++11 has:
C++17 adds structured bindings:
(I think an empty name is okay for ignored elements, I forget).
Code: Select all
int ret;
std::tie(ret, std::ignore) = call_returns_a_pair_or_tuple_of_two();
Code: Select all
auto [ret, ] = call_returns_a_struct_or_array_of_two();
- Graf Zahl
- Lead GZDoom+Raze Developer
- Posts: 49067
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: ZScript equivalent to dev/null
Good suggestion. That's how I'd solve it.Xaser wrote:Heh, I run into this all the time. It's "cosmetic," but a bit of a PITA.
A suggestion: since there's already precedent for deprecating+renaming functions (e.g. A_FireCustomMissile to A_FireProjectile, albeit that was for a more serious reason) and the name "A_SpawnItemEx" is pretty antiquated anyway ("Ex" suffix, plus it spawns any actor, not just an "Item"), perhaps let's make an "A_SpawnActor" that has the same parameters & functionality but returns the Actor only. Nice n' clean.
[Also yes, we could DIY this mostly by implementing a proxy function, but it'd be nice for everyone to not to have to. ;]
For leaving out single arguments in such a case, unfortunately some more work on the parser and the code generation is needed, and right now I don't have time for that.
- Marisa the Magician
- Posts: 3886
- Joined: Fri Feb 08, 2008 9:15 am
- Preferred Pronouns: She/Her
- Operating System Version (Optional): (btw I use) Arch
- Graphics Processor: nVidia with Vulkan support
- Location: Vigo, Galicia
- Contact:
Re: ZScript equivalent to dev/null
Empty names for arguments and such sounds like a good idea to me. Unrealscript does that when you want to skip some arguments in function calls and leave them default.
- Matt
- Posts: 9696
- Joined: Sun Jan 04, 2004 5:37 pm
- Preferred Pronouns: They/Them
- Operating System Version (Optional): Debian Bullseye
- Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
- Contact:
Re: ZScript equivalent to dev/null
Is "A_Spawn" used for anything that could result in a conflict? I see only one instance of it in something about DEH aliases but I have no idea what the implications are.
Re: ZScript equivalent to dev/null
Yes, it's an MBF codepointer. See CreateSpawnFunc() in src/d_dehacked.cpp for the internal side of the implementation.Matt wrote:Is "A_Spawn" used for anything that could result in a conflict? I see only one instance of it in something about DEH aliases but I have no idea what the implications are.