Raised This Month: $51 Target: $400
 12% 

Array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
MacL
Member
Join Date: May 2021
Old 05-26-2021 , 02:02   Array
Reply With Quote #1

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]); 

Last edited by MacL; 05-27-2021 at 04:44.
MacL is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 05-26-2021 , 02:33   Re: Array
Reply With Quote #2

Maybe like this?
PHP Code:
somearray[my_vib
__________________
My plugin:
Celena Luna is offline
MacL
Member
Join Date: May 2021
Old 05-26-2021 , 03:59   Re: Array
Reply With Quote #3

Quote:
Originally Posted by Celena Luna View Post
Maybe like this?
PHP Code:
somearray[my_vib
Is there another way?
MacL is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 05-26-2021 , 06:44   Re: Array
Reply With Quote #4

Quote:
Originally Posted by MacL View Post
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.
__________________
My plugin:

Last edited by Celena Luna; 05-26-2021 at 06:46.
Celena Luna is offline
MacL
Member
Join Date: May 2021
Old 05-26-2021 , 08:48   Re: Array
Reply With Quote #5

Quote:
Originally Posted by Celena Luna View Post
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.
MacL is offline
+ARUKARI-
AlliedModders Donor
Join Date: Jul 2004
Location: Japan
Old 05-27-2021 , 02:25   Re: Array
Reply With Quote #6

@celena
Code:
somearray[g_vib - 1]
__________________
GitHub
SteamWishlist

六四天安門事件
+ARUKARI- is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 05-27-2021 , 04:41   Re: Array
Reply With Quote #7

^
Another dumb mistaken from me
__________________
My plugin:

Last edited by Celena Luna; 05-27-2021 at 04:41.
Celena Luna is offline
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 18:14.


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