AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Making functions (https://forums.alliedmods.net/showthread.php?t=10171)

harbu 02-10-2005 12:08

Making functions
 
How do i make functions with values that are not neccearly need to be defined for example get_user_aiming ( index, &id, &body, [ distance ] ).
You don't have to specifiy a distance if you dont want to.. How do i make my own functions like that, how about strings?

Geesu 02-10-2005 13:01

I'm assuming are you talking about like creating amx natives? Like creating a module? Or actually just writing a function in small?

harbu 02-10-2005 13:03

Function in small

XxAvalanchexX 02-10-2005 13:09

From what Twilight has told me, public functions cannot have default values, but stocks can. An example would be:

Code:
stock functionname(param1,param2,param3 = 5) {   // so-and-so! }

This makes the default value of param3 as 5. You can then call it as "functionname(7,2)" for example, and param3 will be 5 since you didn't define it.

Note that stock functions aren't evaluated by the compiler unless you use them. So all of the code inside of functionname could be totally crappy and not even Small and it would compile fine unless you use it in your script. I could be wrong, but I don't think it will evaluate it if you call it via a set_task, I think you have to call it directly.

xeroblood 02-10-2005 16:24

Quote:

Originally Posted by XxAvalanchexX
I could be wrong, but I don't think it will evaluate it if you call it via a set_task, I think you have to call it directly.

That is right, any function that is to be called by AMXX must be declared public, if however it is only called locally in your script it may be declared as stock..

A perfect example is the set_task() function that accepts the name of a public function as a parameter, and is later called by AMXX in the set amount of time..


All times are GMT -4. The time now is 19:25.

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