Raised This Month: $ Target: $400
 0% 

Setting Strings


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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 15:33.


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