AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Need explanations about forward declaration (https://forums.alliedmods.net/showthread.php?t=62890)

Arkshine 11-06-2007 19:44

Need explanations about forward declaration
 
What's the purpose using 'forward' ?
For example:

Code:

forward bool:isnominated(map[]);
forward public handle_nominate(id,map[]);

[...]

bool:isnominated(map[])
{
    //
}

public handle_nominate(id,map[]
{
      //
}

It's a more faster way?

Wilson [29th ID] 11-07-2007 03:45

Re: Need explanations about forward declaration
 
Well, as I'm sure you've noticed, the latter of the two provides the 'id' parameter. This requires it being a public function so as to pass such as parameter, which you should use if you need the soldier who nominated it's id.

The former of the two is simpler and quicker. It's not even public. But it doesn't pass the id parameter, which may be disadvantageous.

I'd imagine they do the same exact thing, and the only difference is whether or not you need the id parameter. It's odd that someone made both, but eh.

Twilight Suzuka 11-07-2007 03:56

Re: Need explanations about forward declaration
 
forward is a keyword that indicates the function may be called from the outside, ie, another plugin or the core.

it is more of a useful hint to the programmer than anything else.

purple_pixie 11-07-2007 05:34

Re: Need explanations about forward declaration
 
But called how?

This would be very useful for me.

Wilson [29th ID] 11-07-2007 08:06

Re: Need explanations about forward declaration
 
Jesus, I'm sorry, I totally misread your question.

Twilight Suzuka explained it pretty straightforward...if you want an example, go check out WeaponMod from SpaceHead productions...they create forwards in one plugin and use the forward in another.

Brad 11-07-2007 08:41

Re: Need explanations about forward declaration
 
Or ATAC from the same place.

purple_pixie 11-07-2007 09:15

Re: Need explanations about forward declaration
 
Thanks, people.

I have weaponmod ... I'm impressed I didn't notice that.

EDIT: OK ... now I'm just very confused. I might use natives instead. Still confused though.

Twilight Suzuka 11-07-2007 09:41

Re: Need explanations about forward declaration
 
The forward keyward DOES NOTHING. It is a HINT to the PROGRAMMER that the function should probably be public, and will most likely be called from an outside source.

It is also used for some other things (such as forbidding operations on tags) but you will never ever see it used for that ever. Usually it is only used as a hint to the programmer that, hey, some other plugin is going to call this function.

NOTHING ELSE.

Nothing confusing at all.

purple_pixie 11-07-2007 09:55

Re: Need explanations about forward declaration
 
I meant the whole forwards concept.

As in "CreateMultiForward" et c.

But now I think I get it.
I haven't got my natives to work yet, but I wrote a teeny plugin and made a plugin for my plugin with forwards.

EDIT: Scrap that, I'm fairly sure I get both now.
I was confused again until I realised you have to register them *before* plugin_init() ...

Arkshine 11-07-2007 11:46

Re: Need explanations about forward declaration
 
Thanks. :)


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

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