02.02.2014, 18:02
Hello everyone!
I've been programming PAWN for several years now, so this question may surprise you, the question is why do we return a value when we use callbacks? I understand why we use it in functions, to return a value obviously. I have provided two examples below of when I would and wouldn't use them in functions.
Now what I don't understand is why we use them in callbacks, it's not like we're using them to perform calculations, right?
I mean, what's the difference between this...
...this...
...or this?
When I create callbacks I always feel the need to add 'return 1' at the end, since every other callback has them.
Can anyone explain why we need to do this? And if we don't actually have to do it, could you please explain why the standard callbacks return a value? Thank you very much.
I've been programming PAWN for several years now, so this question may surprise you, the question is why do we return a value when we use callbacks? I understand why we use it in functions, to return a value obviously. I have provided two examples below of when I would and wouldn't use them in functions.
pawn Код:
// When I WOULD use 'return' in a function
stock AddNumbers(num1, num2)
{
return num1 + num2;
}
// When I WOULDN'T use 'return' in a function
new bool:someBool;
stock ToggleBool()
{
if (someBool)
{
someBool = false;
}
else
{
someBool = true;
}
}
I mean, what's the difference between this...
pawn Код:
public OnGameModeInit()
{
print("Script has been initialised!");
return 1;
}
pawn Код:
public OnGameModeInit()
{
print("Script has been initialised!");
return 0;
}
pawn Код:
public OnGameModeInit()
{
print("Script has been initialised!");
}
pawn Код:
forward MyCallback();
public MyCallback()
{
print("Hello there!");
return 1;
}