Split Return value into 2 parts

Everything else that doesn't fall into one of the other PB categories.
AZJIO
Addict
Addict
Posts: 1298
Joined: Sun May 14, 2017 1:48 am

Split Return value into 2 parts

Post by AZJIO »

Split Return value into 2 parts:
Success: not 0
Failure: 0
This is short compared to the long wording: "Nonzero if the menu was successfully created, zero otherwise.". Often you need to understand what is returned when a failure or vice versa with success and for this you have to read a long text.
BarryG
Addict
Addict
Posts: 3268
Joined: Thu Apr 18, 2019 8:17 am

Re: Split Return value into 2 parts

Post by BarryG »

Is it such a big deal? Zero means failure/error for all returned commands. It's not hard to remember, is it? Zero = nothing, like nothing worked.
AZJIO
Addict
Addict
Posts: 1298
Joined: Sun May 14, 2017 1:48 am

Re: Split Return value into 2 parts

Post by AZJIO »

There are many functions in which 0 cannot be used as an error, for example, the index of the gadget list starts with 0, and the error is -1, more precisely, not a function execution error, but the absence of a result. In mathematical functions, where 0 is a valid result.
BarryG
Addict
Addict
Posts: 3268
Joined: Thu Apr 18, 2019 8:17 am

Re: Split Return value into 2 parts

Post by BarryG »

Gadget lists start with index 0, not error 0. There's a difference.
AZJIO
Addict
Addict
Posts: 1298
Joined: Sun May 14, 2017 1:48 am

Re: Split Return value into 2 parts

Post by AZJIO »

BarryG wrote: Sun Sep 26, 2021 1:30 pm Gadget lists start with index 0, not error 0. There's a difference.
I said the same thing.

Example
Returns nonzero on success and zero on failure. If #PB_Any was used as the #Gadget parameter then the return-value is the auto-generated gadget number on success.
Success: not 0. If #PB_Any was used as the #Gadget parameter then the return-value is the auto-generated gadget number on success.
Failure: 0

Here it is logically clear that the failure is always zero 0 under all conditions. That is, you do not need to read further to find out whether the failure may turn out to be a different value.
Post Reply