Let's take in in depth look at what you're asking.
Code:
if (id == ####)
do this
if (id == ####)
do that
So what you're doing is for EACH if statement, you are checking if the Id is equal to your number. Even if you have already found the correct statement, it will still keep checking against the IDs. You never want to do this.
Code:
else if (id == ####)
do this
else if (id == ####)
do that
This is the better way, in which that once your ID is matched, it does NOT keep checking your ID against others in the statements and skips the rest altogether.
Code:
else {
switch (id)
case ####:
}
This is the same thing as above, HOWEVER case statements can be compiled to much faster code because you are guaranteeing that you will only be checking against primitive integers for all of your statements. This is generally faster.
You're asking, which is the correct way? The answer is NONE OF THEM! You are using if statements for the wrong thing. This is a very bad programming practice if you are working with large sets of IDs (such as in RSPS) where you could have 10,000 different statements. What IS the correct way? Well there is no single answer, but I can give you a few examples.
The most efficient way (in terms of CPU cycles) would be to create an array of some Interface which allows you to not do ANY if statements and go directly to the code you want to execute. Some psuedocode:
You would have a general interface such as this:
Code:
interface Foo {
void doAction();
}
Also you would have an array with length of the maximum ID of the object you will be accessing.
Code:
Foo[] foos = new Foo[MAX_OBJECT_ID];
Next you need an implementation class such as thi
Code:
class DoorFoo implements Foo {
void doAction() {
openThe****ingDoor();
}
}
Now at server initialization, you would do something like this:
Code:
foos[THE_OBJECT_ID] = new DoorFoo();
Now, all you have to do to access the action is ONE operation! no if statements at all!
Code:
foos[objectClickedId].doAction();
This is not "THE" proper way to do it, but if you're concerned with processing time such as in an RSPS, it's the way to go.
Hope I helped you learn something!