AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   What is differance ? (https://forums.alliedmods.net/showthread.php?t=85624)

senecas 02-13-2009 19:31

What is differance ?
 
public fw_playerprethink(id)
{
if(!is_user_alive(id)) return

blabla code
}

or

public fw_playerprethink(id)
{
if(!is_user_alive(id)) return FMRES_IGNORED

blabla code
return FMRES_IGNORED
}


what is differance btw 'return' and 'return FMRES_IGNORED'
samething ?

anakin_cstrike 02-13-2009 19:48

Re: What is differance ?
 
FMRES_* - in fakemeta forwards. (no only fm, can work in ham fw)
PLUGIN_* - in engine forwards or publics.

return - is equal to return PLUGIN_CONTINUE or return 0

Quote:

  • FMRES_HANDLED --> Something was done in this function, but call the one in the DLL / Engine anyways.
  • FMRES_SUPERCEDE --> Prevent function in DLL / Engine from being called.
  • FMRES_IGNORED --> Call original function.
  • FMRES_OVERRIDE --> Call original function, but change return value.

More info
PS: search before

senecas 02-13-2009 19:59

Re: What is differance ?
 
but if I change first code to

public fw_playerprethink(id)
{
if(!is_user_alive(id)) return PLUGIN_CONTINUE

blabla code
}

like this , but this code is wrong.
I dont think "return" is exactly same "return PLUGIN_CONTINUE"
It shoud be

public fw_playerprethink(id)
{
if(!is_user_alive(id)) return

blabla code
return PLUGIN_CONTINUE <--
}

right ?
So I asked this things.
once I use return FMRES_IGNORED or return P LUGIN_CONTINUE at top of code,
there shoud be return FMRES_IGNORED or return PLUGIN_CONTINUE at bottom of code.

I want to know diiferance or benefit.

jim_yang 02-13-2009 22:24

Re: What is differance ?
 
in a fakemeta forward hook, you'd better always use the FMRES_ type as the return value.
return is not equal to return 0, return is just return nothing
code below will get a warning, although it get 0 as result
Code:

public test(id) //a command
{
    console_print(id, "%d", func())
    return PLUGIN_HANDLED
}
public func()
{
    return
}

you can do return nothing in a fm forward because the fakemeta use the default return value(FMRES_IGNORED) if the return value you provide is smaller than it.
so if you only return FMRES_IGNORED in a fm forward, you can use return;
other than that, you should always use FMRES_*
so for your case, the difference depend on the blabla code, if there is no other return type than FMRES_IGNORED, then your two case is the same thing. otherwise your first code is wrong, because in a function you can't use return; and return something; at the same time.

anakin_cstrike 02-14-2009 07:42

Re: What is differance ?
 
Quote:

return is not equal to return 0, return is just return nothing
Opsss...i've made a mistake because i saw a long time ago a post wich said "return 0 or just return;"

YamiKaitou 02-14-2009 10:06

Re: What is differance ?
 
Quote:

Originally Posted by jim_yang (Post 761214)
return is not equal to return 0, return is just return nothing

This is incorrect. Returning nothing assumes PLUGIN_CONTINUE by the engine.


All times are GMT -4. The time now is 17:01.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.