AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   set_task parameter confusion (https://forums.alliedmods.net/showthread.php?t=339531)

deprale 09-15-2022 00:54

set_task parameter confusion
 
Suppose I have a function that requires an integer as a parameter.

PHP Code:

public Pause(const iSeconds)
{
//blablabla


How would I set a task that passes an integer?

PHP Code:

set_task(1.0"Pause"_my_variable_

results into ->>
PHP Code:

ERROR [112]: argument type mismatch (argument 4

Might be an extremely dumb question, but I couldn't figure it out for the life of me so I just made another function that called my other function with the parameter I wanted... needless to say it is extremely scuffed so hopefully someone can help me understand it ( I tried searching but none of the previous questions answered mine )

fysiks 09-15-2022 01:32

Re: set_task parameter confusion
 
This is the easiest way

PHP Code:

set_task(1.0"Pause"my_variable

However, this also sets the task ID to this value so it depends on if you need to reference the task later or if you have other tasks that have the same ID.

The data parameter is treated like a string so there are ways to use it but if you can get away with just using the ID then that should work just fine.

deprale 09-15-2022 02:22

Re: set_task parameter confusion
 
Quote:

Originally Posted by fysiks (Post 2788874)
This is the easiest way

PHP Code:

set_task(1.0"Pause"my_variable

However, this also sets the task ID to this value so it depends on if you need to reference the task later or if you have other tasks that have the same ID.

The data parameter is treated like a string so there are ways to use it but if you can get away with just using the ID then that should work just fine.

Yeah, I was actually trying not to use it like this thinking it's the wrong way to use it - whatever works I guess.

Celena Luna 09-15-2022 04:21

Re: set_task parameter confusion
 
If you want to use the "parameter" then it should be like this

PHP Code:

new iArgs ];
iArgs ] = iSeconds;

set_task1.0"Pause"_iArgs sizeofiArgs )); 

and the fuction would be like this
PHP Code:

public Pause(iParams[])
{
new 
seconds iParams[0];
//blablabla



deprale 09-15-2022 04:50

Re: set_task parameter confusion
 
Quote:

Originally Posted by Celena Luna (Post 2788880)
If you want to use the "parameter" then it should be like this

PHP Code:

new iArgs ];
iArgs ] = iSeconds;

set_task1.0"Pause"_iArgs sizeofiArgs )); 

and the fuction would be like this
PHP Code:

public Pause(iParams[])
{
new 
seconds iParams[0];
//blablabla



Thanks

Natsheh 09-15-2022 07:37

Re: set_task parameter confusion
 
You can also use enumerations helps with the readibilty...

PHP Code:

enum FUNC_PARAMS
{
    
FP_ID,
    
FP_TIME
}

new 
aParams[FUNC_PARAMS]
set_task(1.0"task_function"0aParamssizeof aParams);

public 
task_function(aParams[FUNC_PARAMS])
{
    new 
seconds aParams[FP_TIME]



Bugsy 09-15-2022 22:12

Re: set_task parameter confusion
 
If you want to pass a task ID and array of data

PHP Code:

new arrData] = { 33 44 55 };
new 
iTaskID 3434434;
    
set_task1.0 "TaskFunc" iTaskID arrData sizeofarrData ) );

public 
TaskFunc( const arrData] , iTaskID )
{
    



DJEarthQuake 09-16-2022 08:35

Re: set_task parameter confusion
 
num_to_str pre-task then str_to_num post-task when doing a single number for pause. Showing the actual code is beneficial so one gets apropos answer for the case.

Quote:

Originally Posted by deprale (Post 2788870)
Suppose I have a function that requires an integer as a parameter.

PHP Code:

public Pause(const iSeconds)
{
//blablabla


How would I set a task that passes an integer?

PHP Code:

set_task(1.0"Pause"_my_variable_

results into ->>
PHP Code:

ERROR [112]: argument type mismatch (argument 4

Might be an extremely dumb question, but I couldn't figure it out for the life of me so I just made another function that called my other function with the parameter I wanted... needless to say it is extremely scuffed so hopefully someone can help me understand it ( I tried searching but none of the previous questions answered mine )



All times are GMT -4. The time now is 03:00.

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