Thread: IF Statement and Switch

Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1 IF Statement and Switch 
    Registered Member
    Join Date
    Dec 2009
    Posts
    253
    Thanks given
    5
    Thanks received
    0
    Rep Power
    3
    Which way is more efficient and better to use for setting weapon timers, weapon attacking/defending emotes and such things ?

    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;
    				}
    			}
    or something like:
    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;
    
    		}
    ??
    Reply With Quote  
     

  2. #2  
    Super Donator

    Batukka's Avatar
    Join Date
    Oct 2011
    Posts
    2,433
    Thanks given
    86
    Thanks received
    342
    Rep Power
    496
    if state switch it's good if you have more than 1. use case only when you're adding only 1 item.
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Dec 2009
    Posts
    253
    Thanks given
    5
    Thanks received
    0
    Rep Power
    3
    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
    Reply With Quote  
     

  4. #4  
    Super Donator

    Batukka's Avatar
    Join Date
    Oct 2011
    Posts
    2,433
    Thanks given
    86
    Thanks received
    342
    Rep Power
    496
    Quote Originally Posted by addinol View Post
    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
    check your godsword attack method and use like it. else speed = 1 etc.
    Reply With Quote  
     

  5. #5  
    Respected Member


    Join Date
    Jan 2009
    Posts
    5,743
    Thanks given
    1,162
    Thanks received
    3,603
    Rep Power
    5000
    switch is compiled to if / else statements anyway... Allot easier and cleaner to use switch though!
    Reply With Quote  
     

  6. #6  
    Super Donator

    Batukka's Avatar
    Join Date
    Oct 2011
    Posts
    2,433
    Thanks given
    86
    Thanks received
    342
    Rep Power
    496
    Quote Originally Posted by 1776 View Post
    switch is compiled to if / else statements anyway... Allot easier and cleaner to use switch though!
    true.
    Reply With Quote  
     

  7. #7  
    Banned

    Join Date
    Mar 2011
    Posts
    4,062
    Thanks given
    194
    Thanks received
    689
    Rep Power
    0
    Quote Originally Posted by 1776 View Post
    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
    Reply With Quote  
     

  8. #8  
    Banned

    Join Date
    Mar 2011
    Posts
    4,062
    Thanks given
    194
    Thanks received
    689
    Rep Power
    0
    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;
    			}
    Reply With Quote  
     

  9. #9  
    Registered Member
    thim slug's Avatar
    Join Date
    Nov 2010
    Age
    28
    Posts
    4,132
    Thanks given
    1,077
    Thanks received
    1,137
    Rep Power
    5000
    Use xml for all your weapon data: attack anim, defend anim, run anim, walk anim, sounds, etc
    Reply With Quote  
     

  10. #10  
    Registered Member
    Join Date
    Dec 2009
    Posts
    253
    Thanks given
    5
    Thanks received
    0
    Rep Power
    3
    Thank you all.

    Quote Originally Posted by Jaba View Post
    check your godsword attack method and use like it. else speed = 1 etc.
    I'm not having godswords, dark bow etc. in my server
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. need switch statement help
    By sigmą in forum Help
    Replies: 4
    Last Post: 08-12-2010, 12:15 PM
  2. Use the switch statement ...
    By Jonas++ in forum Tutorials
    Replies: 14
    Last Post: 08-31-2008, 12:04 PM
  3. The Switch Statement
    By × Zenzie × in forum Tutorials
    Replies: 20
    Last Post: 06-06-2008, 09:31 PM
  4. Switch statement.
    By 42 in forum Application Development
    Replies: 5
    Last Post: 05-11-2008, 02:45 AM
  5. Switch Statement
    By × Se×pert × in forum Tutorials
    Replies: 16
    Last Post: 12-31-2007, 07:35 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •