SA-MP Forums Archive
-1 - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: -1 (/showthread.php?tid=544945)



-1 - BoU3A - 05.11.2014

0 is false and 1 is true, what about this -1 and if there is more tell me pls


Re: -1 - Pottus - 05.11.2014

Whatever you want it to be usually this is used to denote an invalid value when adding an element to an dynamic array for example the array was full so you return -1 since 0 is a valid value.


Re: -1 - renegade334 - 05.11.2014

If you are testing for truth, 0 is "false", and anything other than zero is "true".

Код:
if (0) {
    /*
        this code does not run, since 0 is a "false" value
        ...
    */
}

if (-1) {
    /*
        this code *does* run, since -1 is a "true" value
        ...
    */
}
If you want to do a different test, you need to specify it. To take Pottus's example above, if you have a function that returns a value greater than or equal to 0 on success, and returns -1 on failure:

Код:
if (myFunction() > -1) {
    // this will run if the function is successful
}
It all depends on the context.