ZScript equivalent to dev/null

Remember, just because you request it, that doesn't mean you'll get it.

Moderator: GZDoom Developers

User avatar
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

Post by Matt »

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.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript equivalent to dev/null

Post by Graf Zahl »

Normally that shouldn't be necessary, but the return values for this function are definitely in the wrong order.
User avatar
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

Post by Marisa the Magician »

Unfortunately we can't change that without breaking who knows how many mods.
Talon1024
 
 
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

Post by Talon1024 »

JavaScript ES6 destructuring assignment (see "Ignoring some returned values") syntax allows developers to discard unnecessary values.

For example, a line of code from paledit:

Code: Select all

let [start,] = this.subRanges[subRangeIdx].sorted();
User avatar
Xaser
 
 
Posts: 10772
Joined: Sun Jul 20, 2003 12:15 pm
Contact:

Re: ZScript equivalent to dev/null

Post by Xaser »

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. ;]
User avatar
Chris
Posts: 2940
Joined: Thu Jul 17, 2003 12:07 am
Graphics Processor: ATI/AMD with Vulkan/Metal Support

Re: ZScript equivalent to dev/null

Post by Chris »

C++11 has:

Code: Select all

int ret;
std::tie(ret, std::ignore) = call_returns_a_pair_or_tuple_of_two();
C++17 adds structured bindings:

Code: Select all

auto [ret, ] = call_returns_a_struct_or_array_of_two();
(I think an empty name is okay for ignored elements, I forget).
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript equivalent to dev/null

Post by Graf Zahl »

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. ;]
Good suggestion. That's how I'd solve it.
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.
User avatar
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

Post by Marisa the Magician »

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.
User avatar
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

Post by Matt »

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.
Gez
 
 
Posts: 17833
Joined: Fri Jul 06, 2007 3:22 pm

Re: ZScript equivalent to dev/null

Post by Gez »

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.
Yes, it's an MBF codepointer. See CreateSpawnFunc() in src/d_dehacked.cpp for the internal side of the implementation.
Post Reply

Return to “Feature Suggestions [GZDoom]”