if state switch it's good if you have more than 1. use case only when you're adding only 1 item.
|
Which way is more efficient and better to use for setting weapon timers, weapon attacking/defending emotes and such things ?
or something like:Code:if(name.contains("scimitar") || name.contains("shortsword") || name.contains("dagger") || name.contains("whip")) { speed = 4; }else if(name.contains("longsword")){ speed = 5; }else if(name.contains("battleaxe")){ speed = 6; }else if (name.contains("2h") || name.contains("greataxe")) { speed = 7; } if (name.contains("bow")) { if (name.contains("short")) { speed = 4; }else if (name.contains("long")) { speed = 6; } }
??Code:switch (weapon.getId()) { case 4734 :// Karils cross speed = 3; break; case 4151 :// Whip case 1291 :// Scimitars case 1321 : case 1323 : case 1325 : case 1327 : case 1329 : case 6611 : case 1333 : case 6739 : case 4587 : speed = 4; break; case 1373 : speed = 6; break; case 1319 : speed = 7; }
So what should I use now, I have both, where I've few weapons with same timers and one weapon (Karil's crossbow) which is 3ticks.
Also is it OK to set weapon timers like this for ranged weapons, even if I'm not checking fighting style, as if it's rapid the every timer tick should decrease by 1
switch is compiled to if / else statements anyway... Allot easier and cleaner to use switch though!
yh, but in this case the if statement would be better because its checking the items name and if it contains for example "battleaxe" then it would make every battleaxe have that emote but if you did it in switch statements you would have to get every id and write case ####:, so imo here the if statement would be best
wouldnt look messy if you added conventions xD
Code:if(name.contains("scimitar") || name.contains("shortsword") || name.contains("dagger") || name.contains("whip")) speed = 4; else if(name.contains("longsword")) speed = 5; else if(name.contains("battleaxe")) speed = 6; else if (name.contains("2h") || name.contains("greataxe")) speed = 7; if (name.contains("bow")) { if (name.contains("short")) speed = 4; else if (name.contains("long")) speed = 6; }
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |