   now I understand why programmers prefer graphics over gameplay coding
  I have started coding a strategy game, because I have so many cool ideas inside my head as to want to put in this game, that they just can''t stay in there... they are bursting out! Problem is, I am a total rookie, so my coding sucks, and I have to read a tutorial for each function I want to use...I am almost finished with the graphics now, though, and the rest is just using the same functions again on other items... so no problems there.So now I have started building the classes and structures I will need to create cities and armies and move them around, and my god, is there more things you need to code, than I first anticipated... the worst thing is, there is nothing to show for those 10 hours I sat and coded today... nothing new, visually. Every hour while I was coding the graphics, I could see some progress when I compiled the shit. So I finally begin to understand why many programmers put more effort into graphics than gameplay in todays games... even though I will not suffer that fate, knowing that my graphics sux anyhow.I have a real noob question btw.Is there any difference betweenif(myinteger==1)//do somethingif(myinteger==2)//do something elseif(myinteger==3)//do something thirdand switch(myinteger){case 1://do somethingbreak;case 2://do something elsebreak;case 3://do something thirdbreak;default://do nothingbreak;}as far as I can tell they do exactly the same, so is there a performance gain or anything, or can I do one or the other as I fell like it???I should say that I have really really many "if"''s in my program, so if there is even a small gain one way or the other, I will take it... 
  I''d venture to say that switch is faster... most probably the same damn speed however on any decent compiler.but switch is WAY WAY WAY clearer.  ;  First, never do this:if(myinteger==1)//do somethingif(myinteger==2)//do something elseif(myinteger==3)//do something thirdInstead do this:if(myinteger==1)//do somethingelse if(myinteger==2)//do something elseelse if(myinteger==3)//do something thirdThe reason is:  if myinteger is 1, the code doesn''t have to check if it equals 2 or 3 (you only have to do 3 ifs if myinteger equals 3.Typically a switch statement can be optimized into a jump table (when it''s compiled).  Something like this:999:   ADDR = 1000 + myinteger1000:  jump to ADDR1001:  // do something and jump to 10041002:  // do something else and jump to 10041003:  // do something third 1004: Where the numbers you can think of as addresses in your code.  Above is only "pseudo-code" only...Regards,Jeff;  The difference is when the "do something" messes with myinteger.  In the if version, doing that could cause myinteger==1 to be true, then you change it to 2 and myinteger==2 becomes true also.So if you use the switch option, you are making it clear that the expression''s decision only allows 1 of the 3 sections of code to execute.  This is also true with the else-if method proposed by nypyr for a simple myinteger type of expression (as long as the expression itself isn''t doing assignment on the terms).I''m guessing the switch gets better optimization, due to jump table implementation, as mentioned. ;  ok, so if I think that if and switch serves the program equally well... then use switch... got it! Gotta remember that thing about, if the first one is true, and then changes it... I don''t think I have any of that yet though... But I have something that I can''t figure out how to fit into a switch... but I bet you guys have some clever way...if (keys[''1'']==true ){//order retreatkeyreleased=0;finitOrder=true;}if (keys[''2'']==true ){//order stand groundkeyreleased=0;finitOrder=true;}if (keys[''3'']==true ){//order assaultkeyreleased=0;finitOrder=true;}if (keys[''4'']==true ){//order mass suicide, wtf...keyreleased=0;finitOrder=true;}I guess I could just go with the if/else method to make it better...   --------------------------------------------------------------What''s the problem? I don''t got a problem, I got fuckin'' problems!-Tim Roth, Four Rooms ;  well i tried...too bad this doesn''t workint x;switch(keys[x] == true){case 1://whatever goes herebreak;...}[\code]maybe some variation i can''t think of... on compilation it seems to skip the switch... doesn''t even recognize it lol   ;  well i tried...too bad this doesn''t workint x;switch(keys[x] == true){case 1://whatever goes herebreak;...}  maybe some variation i can''t think of... on compilation it seems to skip the switch... doesn''t even recognize it lol ;  This is not a switch occasion.With a switch, you must have a variable which will act as the map for your answer.  That means each state of the variable can have only one different value.  The problem here is that you actually have 4 different values.  There are two ways to handle this.A) Find a way to place an integer representing the key was pressed into an integer variable, then switch on that variable with the cases of 1,2,3 and 4.B) Turn this into an if, else if statement to save as much time as possible. ;  Let's consider just the 1st 2:if (keys['1']==true ){//order retreatkeyreleased=0;finitOrder=true;}if (keys['2']==true ){//order stand groundkeyreleased=0;finitOrder=true;}When the user presses 1 and 2 simultaneously in the same frame, then your ifs will handle both keys.Changing it to an else-if is bad, because the 1 keypress will blind the program from seeing the 2 keypress.A way to do this with else-if or switch:In the keypress event, insert the char into a stack or queue.In the place where you are checking the keys, something like this: // this is assuming you have a written notempty() and popkey() functions to implement your stack// an OOP version would be quite differentwhile( notempty(mykeystack) ){    switch( nextkey=popkey(mykeystack) )    {  case '1': // etc etc... break;  case '2': // etc etc... break;  //...  default: // etc...    }}Where you benefit form this method is when no keys are pressed the stack is empty and the while doesn't do any checking.  When a key is pressed, the while only checks for that 1 key.  And if more than 1 is pressed, then it only does a check for each one. [edited by - 5010 on August 1, 2003 1:15:35 PM];quote:Original post by heat511  well i tried...too bad this doesn''t workint x;switch(keys[x] == true){case 1://whatever goes herebreak;...}[\code]maybe some variation i can''t think of... on compilation it seems to skip the switch... doesn''t even recognize it lolThink about it...The == expression in your switch computes to a boolean that is true or false, so you can have case true: and case false: but nothing else makes any sense. 