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 , 18:39   set_task help ! (passing arguments to a function)
Reply With Quote #1

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 ?
turshija is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-30-2009 , 18:42   Re: set_task help ! (passing arguments to a function)
Reply With Quote #2

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.
__________________

Last edited by fysiks; 10-30-2009 at 18:49.
fysiks is offline
Xellath
Veteran Member
Join Date: Dec 2007
Location: Sweden
Old 10-30-2009 , 18:42   Re: set_task help ! (passing arguments to a function)
Reply With Quote #3

Call the function directly instead of setting a task:

Code:
something( id, value, whatever );
__________________
Achievements API - a simple way for you to create your OWN custom achievements!
Xellath is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-30-2009 , 18:46   Re: set_task help ! (passing arguments to a function)
Reply With Quote #4

Quote:
Originally Posted by Xellath View Post
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.
__________________
fysiks is offline
turshija
Member
Join Date: Jan 2009
Old 10-30-2009 , 18:46   Re: set_task help ! (passing arguments to a function)
Reply With Quote #5

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 is offline
Xellath
Veteran Member
Join Date: Dec 2007
Location: Sweden
Old 10-30-2009 , 18:51   Re: set_task help ! (passing arguments to a function)
Reply With Quote #6

A 0.1 second delay is almost like executing it directly. Just more inefficient.
__________________
Achievements API - a simple way for you to create your OWN custom achievements!
Xellath is offline
turshija
Member
Join Date: Jan 2009
Old 10-30-2009 , 18:51   Re: set_task help ! (passing arguments to a function)
Reply With Quote #7

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 ...
turshija is offline
turshija
Member
Join Date: Jan 2009
Old 10-30-2009 , 18:53   Re: set_task help ! (passing arguments to a function)
Reply With Quote #8

Quote:
Originally Posted by turshija View Post
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 ...
turshija is offline
Xellath
Veteran Member
Join Date: Dec 2007
Location: Sweden
Old 10-30-2009 , 18:58   Re: set_task help ! (passing arguments to a function)
Reply With Quote #9

How many parameters do you need to pass?
__________________
Achievements API - a simple way for you to create your OWN custom achievements!
Xellath is offline
turshija
Member
Join Date: Jan 2009
Old 10-30-2009 , 19:02   Re: set_task help ! (passing arguments to a function)
Reply With Quote #10

2
id and message ...
int + string ...
turshija 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