Raised This Month: $ Target: $400
 0% 

switch with Strings


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 06-23-2014 , 12:06   switch with Strings
Reply With Quote #1

Hello there,

Just a quick question, is there a better and / or better looking way to do this?
Is there something like switch for integers for strings?
PHP Code:
if(equal(szPos"Start1"))
{
    
g_iStart1Pos[0] = str_to_num(iOrigin[0])
    
g_iStart1Pos[1] = str_to_num(iOrigin[1])
    
g_iStart1Pos[2] = str_to_num(iOrigin[2])
}
else if(
equal(szPos"Start2"))
{
    
g_iStart2Pos[0] = str_to_num(iOrigin[0])
    
g_iStart2Pos[1] = str_to_num(iOrigin[1])
    
g_iStart2Pos[2] = str_to_num(iOrigin[2])
}
else if(
equal(szPos"Finish1"))
{
    
g_iFinish1Pos[0] = str_to_num(iOrigin[0])
    
g_iFinish1Pos[1] = str_to_num(iOrigin[1])
    
g_iFinish1Pos[2] = str_to_num(iOrigin[2])
}
else if(
equal(szPos"Finish2"))
{
    
g_iFinish2Pos[0] = str_to_num(iOrigin[0])
    
g_iFinish2Pos[1] = str_to_num(iOrigin[1])
    
g_iFinish2Pos[2] = str_to_num(iOrigin[2])

__________________
Kia is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 06-23-2014 , 12:33   Re: switch with Strings
Reply With Quote #2

Possible to use one global var with enum, and assocating string to enum constants, then you would need just Trie native + 3 lines.
__________________
Arkshine is offline
GuskiS
Veteran Member
Join Date: Aug 2007
Location: Latvia
Old 06-23-2014 , 15:54   Re: switch with Strings
Reply With Quote #3

You could make szPos names something like this - endstart1 endstart2 and so on, after that check last integer num. When you have it, make it 2D array with some enums.
__________________
Finished mods:
Trouble in Terrorist Town
MurderMod
The Hidden
Cowboys vs Indians
JailBreak Supreme
Survival Madness
GuskiS 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 21:09.


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