AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   set_task help ! (passing arguments to a function) (https://forums.alliedmods.net/showthread.php?t=107825)

turshija 10-30-2009 18:39

set_task help ! (passing arguments to a function)
 
Hello ...
I need help with passing arguments to a function when there are more than 1 arguments ...
for example, when I want to call function something(id) i do:
set_task(0.1, "something", id) and that works perfectly ...

but how do I call function something(id, number) ?
set_task(0.1, "something", id, number) <- doesn't work
it passes only first argument ...

any help ? :)

fysiks 10-30-2009 18:42

Re: set_task help ! (passing arguments to a function)
 
Like this I believe (off the top of my head):

PHP Code:

new param[1]
param[0] = number
set_task
(fTime"cmdFunction"idparamsizeof(param))

public 
cmdFunction(idthisparam[])
{
    
number thisparam[0]
    
    
// Stuff here.


Or, depending on what you are using it for, you might be able to use a global variable.

Xellath 10-30-2009 18:42

Re: set_task help ! (passing arguments to a function)
 
Call the function directly instead of setting a task:

Code:
something( id, value, whatever );

fysiks 10-30-2009 18:46

Re: set_task help ! (passing arguments to a function)
 
Quote:

Originally Posted by Xellath (Post 976356)
Call the function directly instead of setting a task:

Code:
something( id, value, whatever );

Yeah, I didn't think of that. You would call it directly if you intend on using it "immediately". You would only need a task if it needs delayed a significant amount of time.

turshija 10-30-2009 18:46

Re: set_task help ! (passing arguments to a function)
 
i need to do it delayed, so thats why I can't call it directly ...
thanks fysiks, I'll try that and say how it works ...
btw, I need to pass a string, so hopefully that will work ...
function(id, message)

turshija 10-30-2009 18:51

Re: set_task help ! (passing arguments to a function)
 
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 ...

Xellath 10-30-2009 18:51

Re: set_task help ! (passing arguments to a function)
 
A 0.1 second delay is almost like executing it directly. Just more inefficient.

turshija 10-30-2009 18:53

Re: set_task help ! (passing arguments to a function)
 
Quote:

Originally Posted by turshija (Post 976362)
because I maybe wont be using 0.1 delay (maybe more)

I've just put an example with 0.1 sec ...
I will most likely use something around 5 seconds ...

Xellath 10-30-2009 18:58

Re: set_task help ! (passing arguments to a function)
 
How many parameters do you need to pass?

turshija 10-30-2009 19:02

Re: set_task help ! (passing arguments to a function)
 
2
id and message ...
int + string ...


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

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