AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Maximum of global strings? (https://forums.alliedmods.net/showthread.php?t=54715)

dutchmeat 05-02-2007 04:32

Maximum of global strings?
 
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 '' }

dutchmeat 05-02-2007 16:11

Re: Maximum of global strings?
 
Or, what is the best way to pass on strings with set_task ?

_Master_ 05-02-2007 16:32

Re: Maximum of global strings?
 
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" !!! :)

dutchmeat 05-02-2007 17:09

Re: Maximum of global strings?
 
but why do I see 'DEBUG' in function1, but not in function2 ?

stupok 05-02-2007 17:16

Re: Maximum of global strings?
 
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

_Master_ 05-02-2007 17:31

Re: Maximum of global strings?
 
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'


dutchmeat 05-03-2007 05:52

Re: Maximum of global strings?
 
'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 ?

Brad 05-03-2007 08:36

Re: Maximum of global strings?
 
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.

dutchmeat 05-03-2007 08:42

Re: Maximum of global strings?
 
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]

Brad 05-03-2007 08:51

Re: Maximum of global strings?
 
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?


All times are GMT -4. The time now is 06:35.

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