Raised This Month: $ Target: $400
 0% 

Maximum of global strings?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
dutchmeat
Senior Member
Join Date: Sep 2006
Old 05-02-2007 , 04:32   Maximum of global strings?
Reply With Quote #1

Hey is there a maximum of global strings?

when I store a global variable, it's empty when I use the variable in another function.

Basicly I only have to pass a string on to another function using set_task, but the params argument also fails.

example:

Code:
new string[33] function1(id){ new params[2] copy(string[id],29,"DEBUG") console_print(id,"'%s'",string[id]) //prints 'DEBUG' params[0] = id set_task(3.0,"function2",1111+id,params) } function2(params[]){ new id = params[0] console_print(id,"'%s'",string[id]) //prints '' }
__________________
before you criticize someone, you should walk a mile in their shoes. that way, when you criticize them, you're a mile away and you have their shoes.
dutchmeat is offline
dutchmeat
Senior Member
Join Date: Sep 2006
Old 05-02-2007 , 16:11   Re: Maximum of global strings?
Reply With Quote #2

Or, what is the best way to pass on strings with set_task ?
__________________
before you criticize someone, you should walk a mile in their shoes. that way, when you criticize them, you're a mile away and you have their shoes.
dutchmeat is offline
_Master_
Senior Member
Join Date: Dec 2006
Old 05-02-2007 , 16:32   Re: Maximum of global strings?
Reply With Quote #3

Why would you do this ?
PHP Code:
console_print(id,"'%s'",string[id]) 
Don't pass STRING[index] if you format it as array (%s). Tho not illegal it WILL lead to bugs (doh).
Going further with this... you passed string[id] (id meaning the player index), but you did this first
PHP Code:
copy(string[id],29,"DEBUG"
meaning:
string[0] = 'D'
string[1] = 'E'
string[2] = 'B'
string[3] = 'U'
string[4] = 'G'
string[5] = '/0'

if "id" is, lets say 7, then it WILL show an empty string (because when doing "new string[33]" all positions will be set to '/0').

Also: be mindfull of "Index out of bounds" !!!

Last edited by _Master_; 05-02-2007 at 16:47.
_Master_ is offline
dutchmeat
Senior Member
Join Date: Sep 2006
Old 05-02-2007 , 17:09   Re: Maximum of global strings?
Reply With Quote #4

but why do I see 'DEBUG' in function1, but not in function2 ?
__________________
before you criticize someone, you should walk a mile in their shoes. that way, when you criticize them, you're a mile away and you have their shoes.
dutchmeat is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 05-02-2007 , 17:16   Re: Maximum of global strings?
Reply With Quote #5

Code:
set_task(3.0,"function2",1111+id,params) } function2(params[]){

Should be:

Code:
set_task(3.0, "function2", 1111+id, params, 1) // 1 is params' len } function2(params[], taskid){ // taksid is equal to 1111+id from above
stupok is offline
_Master_
Senior Member
Join Date: Dec 2006
Old 05-02-2007 , 17:31   Re: Maximum of global strings?
Reply With Quote #6

Also.. you see "DEBUG" in function1 because of copy(string[id],29,"DEBUG") - this could lead to bugs.

In my prevoius post I've made a mistake....
Quote:
string[0] = 'D'
string[1] = 'E'
string[2] = 'B'
string[3] = 'U'
string[4] = 'G'
string[5] = '/0'
should be
Code:
string[id] = 'D'
string[id+1] = 'E'
string[id+2] = 'B'
string[id+3] = 'U'
string[id+4] = 'G'
string[id+5] = '/0'

Last edited by _Master_; 05-02-2007 at 17:39.
_Master_ is offline
dutchmeat
Senior Member
Join Date: Sep 2006
Old 05-03-2007 , 05:52   Re: Maximum of global strings?
Reply With Quote #7

'taskid' isn't necessary, i am only using 1111+id to stop the task if I need to(using multiple tasks at once).
So, how can I forward a string in the params variable to function2 ?
__________________
before you criticize someone, you should walk a mile in their shoes. that way, when you criticize them, you're a mile away and you have their shoes.
dutchmeat is offline
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 05-03-2007 , 08:36   Re: Maximum of global strings?
Reply With Quote #8

IMO, it's generally a good idea to only pass integers via the params variable. I would store your string globally and then, if your string is in a 2 or 3D array, since the index into that array via the params variable.
__________________
Brad is offline
dutchmeat
Senior Member
Join Date: Sep 2006
Old 05-03-2007 , 08:42   Re: Maximum of global strings?
Reply With Quote #9

Yes, that's what i'm trying to do here, how do I store a string in a global variable ?
The variable must be like this:

new sound[playerindex][number][string]
__________________
before you criticize someone, you should walk a mile in their shoes. that way, when you criticize them, you're a mile away and you have their shoes.
dutchmeat is offline
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 05-03-2007 , 08:51   Re: Maximum of global strings?
Reply With Quote #10

That's a 3D array, which is rarely ever needed. What does the 2nd dimension represent, the "number"?

Are you just trying to store a single sound for each player?
__________________
Brad is offline
Reply


Thread Tools
Display Modes

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 06:35.


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