Raised This Month: $ Target: $400
 0% 

Making functions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
harbu
Senior Member
Join Date: Aug 2004
Location: Finland
Old 02-10-2005 , 12:08   Making functions
Reply With Quote #1

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?
harbu is offline
Send a message via MSN to harbu
Geesu
Veteran Member
Join Date: Mar 2004
Location: Cincinnati, OH
Old 02-10-2005 , 13:01  
Reply With Quote #2

I'm assuming are you talking about like creating amx natives? Like creating a module? Or actually just writing a function in small?
__________________
Need war3ft help? DO NOT PM ME... Check the forums
Geesu is offline
Send a message via AIM to Geesu Send a message via MSN to Geesu
harbu
Senior Member
Join Date: Aug 2004
Location: Finland
Old 02-10-2005 , 13:03  
Reply With Quote #3

Function in small
harbu is offline
Send a message via MSN to harbu
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 02-10-2005 , 13:09  
Reply With Quote #4

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.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
xeroblood
BANNED
Join Date: Mar 2004
Location: Toronto, Canada
Old 02-10-2005 , 16:24  
Reply With Quote #5

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..
xeroblood is offline
Send a message via MSN to xeroblood
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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