AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   Array (https://forums.alliedmods.net/showthread.php?t=332661)

MacL 05-26-2021 02:02

Array
 
how can i get array number? like:
PHP Code:

new somearray[][]={
"im 0",
"im 1",
"im 2"


And for example, we create a switch elsewhere in the plugin. like:
PHP Code:

 switch(my_vib)
         {
                case 
1:
                { 
                            
somearray[0]
                }
                case 
2:
                {
                            
somearray[1]
                }
                case 
3:
                {
                            
somearray[2]
                }
         } 

so now we need to get array number. how? like:
PHP Code:

 client_print(idprint_chat"hi %s"somearray[getnumber]); 


Celena Luna 05-26-2021 02:33

Re: Array
 
Maybe like this?
PHP Code:

somearray[my_vib


MacL 05-26-2021 03:59

Re: Array
 
Quote:

Originally Posted by Celena Luna (Post 2747841)
Maybe like this?
PHP Code:

somearray[my_vib


Is there another way?

Celena Luna 05-26-2021 06:44

Re: Array
 
Quote:

Originally Posted by MacL (Post 2747848)
Is there another way?

Create a global variable and save my_vib then use it on somearray when needed
PHP Code:

new g_vib

...

g_vib my_vib //Save your vib
switch(my_vib)
{
    case 
1:
    { 
        
somearray[0]
    }
    case 
2:
    {
        
somearray[1]
    }
    case 
3:
    {
        
somearray[2]
    }


...

client_print(idprint_chat"hi %s"somearray[g_vib]); 

Or there is dumber way is using for loop then comparing the string inside.
Once found the correct one then break the loop.

MacL 05-26-2021 08:48

Re: Array
 
Quote:

Originally Posted by Celena Luna (Post 2747857)
Create a global variable and save my_vib then use it on somearray when needed
PHP Code:

new g_vib

...

g_vib my_vib //Save your vib
switch(my_vib)
{
    case 
1:
    { 
        
somearray[0]
    }
    case 
2:
    {
        
somearray[1]
    }
    case 
3:
    {
        
somearray[2]
    }


...

client_print(idprint_chat"hi %s"somearray[g_vib]); 

Or there is dumber way is using for loop then comparing the string inside.
Once found the correct one then break the loop.

Thanks. i made a int and gave it a number in every case. then i used it inside client_print.

+ARUKARI- 05-27-2021 02:25

Re: Array
 
@celena
Code:

somearray[g_vib - 1]

Celena Luna 05-27-2021 04:41

Re: Array
 
^
Another dumb mistaken from me :(


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

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