Thread: Setting Strings
View Single Post
Author Message
MrPickles
Senior Member
Join Date: Aug 2022
Location: Colombia
Old 09-27-2022 , 23:31   Setting Strings
Reply With Quote #1

Hello, I have a question, I need to place many names, which would be faster/efficient, declare the names in the same function, or create a variable with the list of names and then call them, here are differents ways

First Way:

PHP Code:
stock SetNameType__int_EntityType )
{
    switch(
Type)
    {
           case 
1:
           {
               
entity_set_string(__int_Entity,EV_SZ_classname,"Rogue");
           }
           case 
2:
           {
               
entity_set_string(__int_Entity,EV_SZ_classname,"Warrior");
           }
           case 
3:
           {
               
entity_set_string(__int_Entity,EV_SZ_classname,"Wizzard");
           } 
// And a few more
      
}

Second Way:

PHP Code:

new const Names[][] = // Global
{
       
"Warrior",
       
"Rogue",
       
"Wizzard"
}
stock SetNameType__int_EntityType )
{        
    switch(
Type)
    {
           case 
1:
           {
              
entity_set_string(__int_Entity,EV_SZ_classname,Names[0]);
           }
           case 
2:
           {
             
entity_set_string(__int_Entity,EV_SZ_classname,Names[1]);
           }
           case 
3:
           {
             
entity_set_string(__int_Entity,EV_SZ_classname,Names[2]);
           } 
// And a few more
      
}

i can set it directly like this:

PHP Code:

new Names[][] = // Global
{
       
"Warrior",
       
"Rogue",
       
"Wizzard"
}
stock SetNameType__int_EntityType )
{        
         
entity_set_string(__int_Entity,EV_SZ_classname,Names[Type]);

But i need to use other switch for other purpose, but, what is better, set the string directly, or with a global variable( Way 1 or 2 );

Last edited by MrPickles; 09-27-2022 at 23:35. Reason: Grammatic
MrPickles is offline