Author Topic: return 0 or return nil?  (Read 1504 times)

0 Members and 1 Guest are viewing this topic.

Offline VidFamne

  • Triple Ace
  • **
  • Posts: 173
  • Karma: +2/-0
return 0 or return nil?
« on: 01 October, 2004, 01:02:49 »
As the subject said, whats the diff?
I.e;
Code: [Select]
function some()
    if something then
    do something
    else
    return 0 --( or return nil)
    end
end

PtokaX forum

return 0 or return nil?
« on: 01 October, 2004, 01:02:49 »

Offline Meka][Meka

  • Double Ace
  • *
  • Posts: 111
  • Karma: +5/-1
(No subject)
« Reply #1 on: 01 October, 2004, 01:04:25 »
return 0

will be returned as (0) nil wil be returned as ()
« Last Edit: 01 October, 2004, 01:04:43 by Meka][Meka »
Do you know what \'nemesis\' means? A righteous infliction of retribution manifested by an appropriate agent. Personified in this case by an \'orrible cunt... me.



Offline VidFamne

  • Triple Ace
  • **
  • Posts: 173
  • Karma: +2/-0
(No subject)
« Reply #2 on: 01 October, 2004, 01:16:50 »
Yes, I can see that, but is there any difference in how
Ptokax handle this?
You can return 0, 1, -1, and nil
but I havent get a grip on what the difference is, between it.
I'm wondering this because I want to optimize the script
and thought it would be better to return nil instead of return 0. (Saving memory, that is  :D )
« Last Edit: 01 October, 2004, 01:34:21 by VidFamne »

Offline Meka][Meka

  • Double Ace
  • *
  • Posts: 111
  • Karma: +5/-1
(No subject)
« Reply #3 on: 01 October, 2004, 01:38:02 »
Quote
Originally posted by VidFamne
Yes, I can see that, but is there any difference in how
Ptokax handle this?
You can return 0, 1, -1, and nil
but I havent get a grip on what the difference is, between it.
I'm wondering this because I want to optimize the script
and thought it would be better to return nil instead of return 0. (Saving memory, that is  :D )

well return nil is probably better, its what i prefere, u can return anything... not just 0 1 -1, even return "name"

ptokax uses 0 as let, for the rest they are sent to the calling function

edit: nil also i reckon also -1 will all be let numbers, if a functions receives nil, 0 it wont bother returning it will just carry on til it ends... return 1 or other will close the function and return it
« Last Edit: 01 October, 2004, 01:45:03 by Meka][Meka »
Do you know what \'nemesis\' means? A righteous infliction of retribution manifested by an appropriate agent. Personified in this case by an \'orrible cunt... me.



PtokaX forum

(No subject)
« Reply #3 on: 01 October, 2004, 01:38:02 »