I am just playing around with the "case" statement. I have not used this statement before so this is my first time. And I found this statement really useful.
Anyway, I am using this script which has a case statement.
Code Snippet
Plaintext
main { place1 = getEnt("place1","targetname"); place1 thread place_weapons("m9"); }
EDIT: Really i'd just suggest an if statement instead of a case statement for what your trying to do. Case statements are primarily used as a way to return values, not do lengthy code.
Last Edit: May 11, 2014, 02:10:19 pm by daedra descent
EDIT: Really i'd just suggest an if statement instead of a case statement for what your trying to do. Case statements are primarily used as a way to return values, not do lengthy code.
Okey thank you, that seems to have fixed it. Now an another error pops up. The script compile error is saying, "missing case statement" And developer 1 says that it is something regarding those first three lines you often have in scripts.
Code Snippet
Plaintext
#include, etc
Is it an another file I need to include there? If so which one?
No, nothing wrong with that more than likely. But make sure you add a default case statement. Most likely why that is happening is there is a value being returned that is not listed down.
var = undefined; //the variable has to be set before the actual script
switch(var){ // var is the variable case "1": // what the first option the variable could be
break; // how to end a case
case "2": // what the second option the variable could be
break; }
this is used instead of lots of if else statements. you use this when the variable is set before this script. I used undefined to show that it has to be set before.
No, nothing wrong with that more than likely. But make sure you add a default case statement. Most likely why that is happening is there is a value being returned that is not listed down.
Hmm, well I still don't know exactly what I need to do, what value? I'm a noob.
The sound of God is the screech of tires, lights and magnets, bolts and wires. Strayed from the road, this very one, still to come. The sound of tires is the sound of God, the electric version.
Well, then I have no idea what's wrong. I don't know how I should correct the script myself. D: I can't see anything wrong with it.
Like said, it 'switches' to the value returned and executes the code. Let's say you have the case for 'm9' and 'thompson'. If you carry any other gun, presumably it'd pop out an error or do nothing. If it IS popping out an error, you have to add a default case so that if it isn't one of the listed guns it's execute the code in the default case.
Like said, it 'switches' to the value returned and executes the code. Let's say you have the case for 'm9' and 'thompson'. If you carry any other gun, presumably it'd pop out an error or do nothing. If it IS popping out an error, you have to add a default case so that if it isn't one of the listed guns it's execute the code in the default case.
because it switches to the m9 inside of the function itself?
Hmm, that can't be the issue as this script works in other cases. This time I am making it with the case statement, but it just doesn't takes the weapon.