Raised This Month: $ Target: $400
 0% 

Transfer string arguments in set_task


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Empowers
BANNED
Join Date: Feb 2009
Location: Ukraine
Old 04-04-2009 , 13:54   Re: Transfer string arguments in set_task
Reply With Quote #1

Quote:
Originally Posted by Emp` View Post
I doubt you can pass a two-dimensional array through. Index the first dimension (targetname[0])
but when we pass one-dimensional arrays

we do it like this
PHP Code:
new param[10]
set_task(10.0,"task",_,param
but not like this
PHP Code:
new param[10]
set_task(10.0,"task",_,param[])

//or this
set_task(10.0,"task",_,param[1]) 
OR if i wanna pass somethink like this..
PHP Code:
new param[10][32]

param[1] = "string1"
param[2] = "string2"
           
...
param[9] = "string9"

//so what index should we write?
set_task(1.0,"go",_,param[or or 3]) // ????

set_task(1.0,"go",_,param[]) // <------ I thougth that this is nice 
//but it doesn't work 

Last edited by Empowers; 04-04-2009 at 14:00.
Empowers is offline
Send a message via ICQ to Empowers
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-04-2009 , 17:01   Re: Transfer string arguments in set_task
Reply With Quote #2

To pass a string do as arkshine said:

PHP Code:
new szString[33];

get_user_nameid szString 32 );

set_task1.0 "DoSomething" _szString 33 );

public 
DoSomethingszString[33] )
{
    
client_printprint_chat "hello %s" szString );

To my knowledge you cannot pass multi-dimensional arrays through a set_task. To pass multiple strings, you can make them have a defined size and put them all into one array. If you use this method be sure to allow 1 extra character per string as a null terminator. If you do not do this then whichever string goes over the size limit will be attached to the following string in the array. Untested

PHP Code:

new szData[50];

formatexszData[0] , 10 "Hello" );
formatexszData[10] , 10 "my" );
formatexszData[20] , 10 "name" );
formatexszData[30] , 10 "is" );
formatexszData[40] , 10 "blah" );

set_task1.0 "DoSomething" _szString 50 );

public 
DoSomethingszString[50] )
{
    
client_printprint_chat "word1=%s" szString[0] );
    
client_printprint_chat "word2=%s" szString[10] );    
    
client_printprint_chat "word3=%s" szString[20] );
    
client_printprint_chat "word4=%s" szString[30] );
    
client_printprint_chat "word5=%s" szString[40] );

__________________

Last edited by Bugsy; 04-04-2009 at 17:05.
Bugsy is offline
Empowers
BANNED
Join Date: Feb 2009
Location: Ukraine
Old 04-05-2009 , 02:07   Re: Transfer string arguments in set_task
Reply With Quote #3

Quote:
Originally Posted by Bugsy View Post
To pass a string do as arkshine said:

PHP Code:
new szString[33];

get_user_nameid szString 32 );

set_task1.0 "DoSomething" _szString 33 );

public 
DoSomethingszString[33] )
{
    
client_printprint_chat "hello %s" szString );

wow great! it works thx to U & Arkshine, crashes was bzc in my function I wrote
not
PHP Code:
public DoSomethingszString[33] ) 
but this
PHP Code:
public DoSomethingszString[ ] ) 
SOLVED
Empowers is offline
Send a message via ICQ to Empowers
Dores
Veteran Member
Join Date: Jun 2008
Location: You really don't wanna k
Old 04-05-2009 , 08:57   Re: Transfer string arguments in set_task
Reply With Quote #4

... I was wrong twice! :O

Anyways, you should fix this:

PHP Code:
set_task1.0 "DoSomething" _szString 33 );

--->

set_task1.0 "DoSomething" _szString 32 ); 
__________________
O o
/Ż________________________
| IMMA FIRIN' MAH LAZOR!!!
\_ŻŻŻ
Dores is offline
Old 04-04-2009, 20:14
Dores
This message has been deleted by Dores. Reason: hmm...
Dores
Veteran Member
Join Date: Jun 2008
Location: You really don't wanna k
Old 04-04-2009 , 20:32   Re: Transfer string arguments in set_task
Reply With Quote #6

@Bugsy: I'm pretty sure that you've handled the task function wrong, it should be:
Code:
public DoSomething( szString[] ) {     client_print( 0 , print_chat , "word1=%s" , szString[0] );     client_print( 0 , print_chat , "word2=%s" , szString[10] );         // ... }

According to what you(Empowers) need, you should try this:
PHP Code:
new targetname[2][32];
// If you want more:
// new targetname[3][32];
pev(entpev_targetnametargetname[0], 31);
// pev(ent2, pev_targetname, targetname[1], 31);

set_task(0.1"restore_targetname"_targetname1);
// set_task(0.1, "restore_targetname", _, targetname, 2);

[...]

public 
restore_targetname(Params[])
{
    
// Debug.
    
client_print(0print_chat"targetname[0] = %s"Params[0]);
    
// If you want more:
    // client_print(0, print_chat, "targetname[1] = %s", Params[1]);

Also, if you don't need any delay, you can call the function directly:
PHP Code:
new targetname[1][32];
pev(entpev_targetnametargetname[0], 31);

restore_targetname(targetname[0]); 
__________________
O o
/Ż________________________
| IMMA FIRIN' MAH LAZOR!!!
\_ŻŻŻ

Last edited by Dores; 04-04-2009 at 20:38.
Dores is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-04-2009 , 21:12   Re: Transfer string arguments in set_task
Reply With Quote #7

Quote:
Originally Posted by Dores View Post
@Bugsy: I'm pretty sure that you've handled the task function wrong, it should be:
[small]
@@public DoSomething( szString[] )
{
client_print( 0 , print_chat , "word1=%s" , szString[0] );
client_print( 0 , print_chat , "word2=%s" , szString[10] );
[/php]
That is incorrect. You can specify the size of the array param for safety. In this instance, since we are working with fixed-size strings, it is a good idea to specify the inputted array size to the function. However, either way will work without errors\warnings.
__________________

Last edited by Bugsy; 04-04-2009 at 21:36.
Bugsy is offline
Empowers
BANNED
Join Date: Feb 2009
Location: Ukraine
Old 04-05-2009 , 02:00   Re: Transfer string arguments in set_task
Reply With Quote #8

Quote:
Originally Posted by Dores View Post

According to what you(Empowers) need, you should try this:
PHP Code:
new targetname[2][32];
// If you want more:
// new targetname[3][32];
pev(entpev_targetnametargetname[0], 31);
// pev(ent2, pev_targetname, targetname[1], 31);

set_task(0.1"restore_targetname"_targetname1);
// set_task(0.1, "restore_targetname", _, targetname, 2);

[...]

public 
restore_targetname(Params[])
{
    
// Debug.
    
client_print(0print_chat"targetname[0] = %s"Params[0]);
    
// If you want more:
    // client_print(0, print_chat, "targetname[1] = %s", Params[1]);

before posting code please try to compile it it gives an error on line where is set_task.
Array dimensions do not match
Empowers is offline
Send a message via ICQ to Empowers
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 02:27.


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