How does "return" work?
Hey, so I started coding with Pawn like 3-4 weeks, and I think that I'm pretty good for that small amount of time, but there is one thing that I don't really understand.
How does return work actually work? So if I set like PLUGIN_HANDLED in else statement, it said it would disable from going to other plugins, how does that "go" to other plugins. In this code here, made by OciXCrom, what is returning, and where does it go (sorry if I sound like a total dumbass), and what does "?" mean? PHP Code:
And how I can be useful. Sorry if a thread like this already exists. |
Re: How does "return" work?
In general, a return value is the value returned by the function. If the function is being called from a hook provided by a module then there are special constants to signify to the hooking module what do do. This depends on the module for what the different values do. For AMX Mod X module, you have PLUGIN_* constants then for fakemeta you have FMRES_* constants and for Hamsandwich you have HAM_* constants.
Each of the modules have their own meaning for the return values and you can look at return value definitions (in their include file for constants, usually *_const.inc) and if that isn't enough, you can search specifically for the one you want on the forum (I've seen threads that talk about most of them if not all). For Fakemeta and Hamsandwich, if you hook a function as a pre-hook then certain return values will allow you to modify the function before it is sent to the game engine or prevent the function from occurring at all. For example, if you hook Ham_TakeDamage as pre, you can change how much damage the engine thinks was taken by a player. Here is one such explanation of PLUGIN_* values which is basically what it says in amxconst.inc. The question mark is the ternary operator. Search for it online (and I'm sure it's been explained here as well). |
Re: How does "return" work?
It's a bit weird you are able to do private work but ask basic questions. Don't get me wrong, there is absolutely nothing wrong with asking basic questions and trying to learn, but if you do private work you should at least know the basics. Anyway, none of my business.
There are 2 different things happening with return. First, if it is used in a function then it stops the execution of the function right there. PHP Code:
The other use of return is with certain forwards, like the ones from ham for example. You can return a certain value to tell the module what to do. For example, if in a ham hook you return HAM_SUPERCEDE 2 things will happen: your function(the one registered in the ham hook) will stop and the actual event that you hooked will be blocked too. On the other hand, if you returned HAM_IGNORED, your function will stop because it hits a return(obviously), but the underlying event will still happen and plugins loaded after yours will be able to catch it too. Concrete example: you hooked Ham_TakeDamage like this PHP Code:
PHP Code:
PHP Code:
|
Re: How does "return" work?
Quote:
|
Re: How does "return" work?
I don't think you are experienced enough to be providing help.
|
Re: How does "return" work?
And how did you get to that conclusion :stupid:
|
Re: How does "return" work?
Quote:
|
Re: How does "return" work?
Quote:
|
Re: How does "return" work?
Quote:
|
All times are GMT -4. The time now is 20:20. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.