ZScript equivalent to dev/null

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

Moderator: GZDoom Developers

ZScript equivalent to dev/null

Postby Matt » Thu May 03, 2018 1:50 pm

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
Matt
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: ZScript equivalent to dev/null

Postby Graf Zahl » Thu May 03, 2018 2:41 pm

Normally that shouldn't be necessary, but the return values for this function are definitely in the wrong order.
User avatar
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: ZScript equivalent to dev/null

Postby Marisa Kirisame » Thu May 03, 2018 5:12 pm

Unfortunately we can't change that without breaking who knows how many mods.
User avatar
Marisa Kirisame
ZScript Magician
 
 
 
Joined: 08 Feb 2008
Location: Vigo, Galicia
Discord: Marisa Kirisame#1666
Twitch ID: magusmarisa
Github ID: OrdinaryMagician
Operating System: Other Linux 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: ZScript equivalent to dev/null

Postby Talon1024 » Thu May 03, 2018 5:47 pm

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 allExpand view
let [start,] = this.subRanges[subRangeIdx].sorted();
Talon1024
 
 
 
Joined: 27 Jun 2016
Github ID: Talon1024
Operating System: Debian-like Linux (Debian, Ubuntu, Kali, Mint, etc) 64-bit
Graphics Processor: nVidia with Vulkan support

Re: ZScript equivalent to dev/null

Postby Xaser » Thu May 03, 2018 6:20 pm

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
Xaser
anarchivist
 
 
 
Joined: 20 Jul 2003

Re: ZScript equivalent to dev/null

Postby Chris » Thu May 03, 2018 6:33 pm

C++11 has:
Code: Select allExpand view
int ret;
std::tie(ret, std::ignore) = call_returns_a_pair_or_tuple_of_two();

C++17 adds structured bindings:
Code: Select allExpand view
auto [ret, ] = call_returns_a_struct_or_array_of_two();

(I think an empty name is okay for ignored elements, I forget).
User avatar
Chris
 
Joined: 17 Jul 2003

Re: ZScript equivalent to dev/null

Postby Graf Zahl » Fri May 04, 2018 1:27 am

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
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: ZScript equivalent to dev/null

Postby Marisa Kirisame » Fri May 04, 2018 5:54 am

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
Marisa Kirisame
ZScript Magician
 
 
 
Joined: 08 Feb 2008
Location: Vigo, Galicia
Discord: Marisa Kirisame#1666
Twitch ID: magusmarisa
Github ID: OrdinaryMagician
Operating System: Other Linux 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: ZScript equivalent to dev/null

Postby Matt » Fri May 04, 2018 1:16 pm

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.
User avatar
Matt
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: ZScript equivalent to dev/null

Postby Gez » Fri May 04, 2018 2:23 pm

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.
Gez
 
 
 
Joined: 06 Jul 2007


Return to Feature Suggestions

Who is online

Users browsing this forum: No registered users and 0 guests