Thread: multiple cases (1-20000) in switch statement

Results 1 to 7 of 7
  1. #1 multiple cases (1-20000) in switch statement 
    Registered Member
    Join Date
    Nov 2013
    Posts
    107
    Thanks given
    22
    Thanks received
    0
    Rep Power
    11
    is there any way to make a switch statement that has over 20000 cases in minimal typing? Like for example would it be possible to somehow do:

    Code:
    case 1-20000:
    return = true;
    break;
    case 500:(possible to exclude a case from above without getting a repetition error?)
    case 9000:
    return = false;
    break;
    I would need this to declare every item in the game a non member item except for some of them. If theres another way (if this isn't possible, or a better way) to do it i'd be great full. Thanks!
    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    Oct 2010
    Posts
    20
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    Quote Originally Posted by igpxnaruto4 View Post
    is there any way to make a switch statement that has over 20000 cases in minimal typing? Like for example would it be possible to somehow do:

    Code:
    case 1-20000:
    return = true;
    break;
    case 500:(possible to exclude a case from above without getting a repetition error?)
    case 9000:
    return = false;
    break;
    I would need this to declare every item in the game a non member item except for some of them. If theres another way (if this isn't possible, or a better way) to do it i'd be great full. Thanks!
    Lol a for loop?
    Code:
     
    // for every single item
    for (int itemID = 0; itemID < 20000; itemID++;) {
    			
    	// by default true for all
    	items[itemID].nonMember = true;
    			
    	if (itemID == 4151 || itemID == 6050) {
    
    		// this is non :D
    		items[itemID].nonMember = false;
    	}
    }
    You could also create a array[] that holds all the values.
    Reply With Quote  
     

  3. #3  
    q.q


    Join Date
    Dec 2010
    Posts
    6,519
    Thanks given
    1,072
    Thanks received
    3,535
    Rep Power
    4752
    don't use a switch statement

    just have the default set to true

    then you can either use a switch or an int array and a for loop

    e.g
    Code:
    int[] memberItems = new int[] { 500, 9000, etc, etc };
    
    for (int i =0; i < memberItems.length; i++) {
        items[memberItems[i]].isNonMember = false; 
    }
    Reply With Quote  
     

  4. #4  
    Community Veteran

    mige5's Avatar
    Join Date
    Aug 2008
    Posts
    5,528
    Thanks given
    573
    Thanks received
    1,410
    Rep Power
    2114
    just load itemdef.. (same as in client), if u want different items to be member just change the data in there.
    Number of page #1 releases with most views & posts: (Updated: 2023)
    RS2 server section: 1
    RS2 client section: 2
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Nov 2013
    Posts
    107
    Thanks given
    22
    Thanks received
    0
    Rep Power
    11
    Quote Originally Posted by mige5 View Post
    just load itemdef.. (same as in client), if u want different items to be member just change the data in there.
    Problem is most items are member items, which i would like to take off. I looked at the code, and found this
    for(int j = 0; j < 10; j++)
    if(cache[j].id == i)
    return cache[j];
    ItemDef itemDef = new ItemDef();
    itemDef.id = i;
    itemDef.setDefaults();
    itemDef.readNewValues(new es(itemDatas[i]));
    if(itemDef.certTemplateID != -1)
    itemDef.toNote();
    if (xxxxxxxxxxxxxxxxxxxx) {
    itemDef.description = "bla bla bla bla bla".getBytes();
    itemDef.groundActions = null;
    itemDef.actions = null;
    itemDef.team = 0;
    }
    int[] memberItems = new int[] { 500, 9000};
    Which is defining the items as member objects, now im stuck because for the xxxxxxxxxx part im not sure how to define it. i tried if (i == memberItems) and other things but i really dont know how to make this work. If anybody has any clue... Thanks!
    Reply With Quote  
     

  6. #6  
    Registered Member
    Mylyn's Avatar
    Join Date
    Dec 2012
    Posts
    1,536
    Thanks given
    602
    Thanks received
    278
    Rep Power
    119
    Isnt there something like boolean ismember or something like that in itemdef?
    Reply With Quote  
     

  7. #7  
    Banned

    Join Date
    Oct 2011
    Age
    27
    Posts
    2,566
    Thanks given
    1,027
    Thanks received
    1,168
    Rep Power
    0
    Quote Originally Posted by igpxnaruto4 View Post
    is there any way to make a switch statement that has over 20000 cases in minimal typing? Like for example would it be possible to somehow do:

    Code:
    case 1-20000:
    return = true;
    break;
    case 500:(possible to exclude a case from above without getting a repetition error?)
    case 9000:
    return = false;
    break;
    I would need this to declare every item in the game a non member item except for some of them. If theres another way (if this isn't possible, or a better way) to do it i'd be great full. Thanks!
    Code:
    case 500:
    case 9000:
    return = false;
    break;
    default:
    return = true;
    break;
    Reply With Quote  
     


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. Replies: 10
    Last Post: 08-14-2013, 09:47 PM
  2. Replies: 4
    Last Post: 06-28-2012, 11:15 PM
  3. "Cheap hack" to use string's in switch statements
    By Zee Best in forum Tutorials
    Replies: 12
    Last Post: 07-03-2009, 05:38 AM
  4. The Switch Statement
    By × Zenzie × in forum Tutorials
    Replies: 20
    Last Post: 06-06-2008, 09:31 PM
  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
  •