Raised This Month: $ Target: $400
 0% 

set_task help ! (passing arguments to a function)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
turshija
Member
Join Date: Jan 2009
Old 10-30-2009 , 19:02   Re: set_task help ! (passing arguments to a function)
Reply With Quote #1

2
id and message ...
int + string ...
turshija is offline
Xellath
Veteran Member
Join Date: Dec 2007
Location: Sweden
Old 10-30-2009 , 19:07   Re: set_task help ! (passing arguments to a function)
Reply With Quote #2

Just do what fysiks said then:

Code:
new param[ 2 ]; param[ 0 ] = id; param[ 1 ] = message; set_task( 0.1, "cmdFunction", id, param, sizeof( param ) ) public cmdFunction( param[ ] ) {     id = param[ 0 ];     message = param[ 1 ];         // Stuff here. }
__________________
Achievements API - a simple way for you to create your OWN custom achievements!
Xellath is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-30-2009 , 19:33   Re: set_task help ! (passing arguments to a function)
Reply With Quote #3

For passing id and a string to the called function:
PHP Code:
public testid )
{
    new 
szString[] = "Hello there";

    
set_task1.0 "YourFunction" id szString sizeofszString ) );
}

public 
YourFunctionszString[] , id )
{
    
client_printid print_chat "%s" szString );

To pass id and however many integers. Be careful when using this method because if you try to access a non-existant array element in your called function you will get garbage data. Example, if you tried to access iData[ 22 ] in YourFunction(); 17408 was returned in my test.
PHP Code:
public testid )
{
    new 
iIntegers];
    
iIntegers] = 55;
    
iIntegers] = 11;
    
iIntegers] = 1232;

    
set_task1.0 "YourFunction" id iIntegers sizeofiIntegers ) );
}

public 
YourFunctioniData[] , id )
{
    
client_printid print_chat "%d %d %d" iData] , iData] , iData] );

__________________

Last edited by Bugsy; 10-30-2009 at 19:42.
Bugsy is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-30-2009 , 20:28   Re: set_task help ! (passing arguments to a function)
Reply With Quote #4

Quote:
Originally Posted by turshija View Post
Code:
new message[192]
message = "test";

new param[1]
param[0] = message                    // this is line 72
set_task(0.1, "function", id, param, sizeof(param))
doesn't work ... :S
Error: Must be assigned to an array on line 72

and I can't put it as global variable because I maybe wont be using 0.1 delay (maybe more) so it can be possible that global variable gets changed by someone else before the function is called ...
You never said anything about a string before. That changes things. Do as Bugsy said.

Quote:
Originally Posted by Xellath View Post
Just do what fysiks said then:

Code:
new param[ 2 ]; param[ 0 ] = id; param[ 1 ] = message; set_task( 0.1, "cmdFunction", id, param, sizeof( param ) ) public cmdFunction( param[ ] ) {     id = param[ 0 ];     message = param[ 1 ];         // Stuff here. }
A string will not work this way. He said "num" so I assumed that meant "number" which seems reasonable lol .
__________________
fysiks is offline
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 17:36.


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