HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

cases and switches in jass

08-05-2006, 05:53 AM#1
Linera
Is it possible to do a case thing and switch in jass?

For example this from c++:
Code:
double getConColor(int playerlvl, int moblvl)
{
	if(playerlvl + 5 <= moblvl) {
		if(playerlvl + 10 <= moblvl) {
			return 5;
		}
		else {
			return 4;
		}
	}
	else {
		switch(moblvl - playerlvl)
		{
			case 4:
			case 3:
			return 3;
			break;
			case 2:
			case 1:
			case 0:
			case -1:
			case -2:
			return 2;
			break;
			default:
			// More adv formula for grey/green lvls:
			if(playerlvl <= 5) {
				return 1; //All others are green.
			}
			else {
				if(playerlvl <= 39) {
					if(moblvl <= (playerlvl - 5 - floor(playerlvl/10))) {
						// Its below or equal to the 'grey level':
						return 0;
					}
					else {
						return 1;
					}
				}
				else {
					//player over lvl 39:
					if(moblvl <= (playerlvl - 1 - floor(playerlvl/5))) {
						return 0;
					}
					else {
						return 1;
					}
				}
			}
		}
	}
}
also what is a double function in c++?
08-05-2006, 05:57 AM#2
PipeDream
I'm guessing that what you want is the syntax, in which case the answer is not today. If you just want the speed of a jump table, you could use an array of triggers or strings to ExecuteFunc. But it looks like the cases you want could be written quite simply as a few if/then/else range checks...
08-05-2006, 06:15 AM#3
Linera
what does that double function mean?

could you also tell me what a floor is?

how could it be rewritten into jass?
08-05-2006, 06:18 AM#4
PipeDream
double is a type. it means real with extra precision. floor means round to the integer below. floor(1.5) = 1.0; floor(-1.5) = -2.0. Similar to R2I, except there is no conversion to an integer type. And I think R2I is trunc, where -1.5 ->-1, but don't quote me on that.

Further questions would be better directed to the programming forum.
08-05-2006, 06:29 AM#5
Linera
so a floor can be:

Collapse JASS:
R2I(I2R(1.5))

or would it be best to write a function for this?
08-05-2006, 06:54 AM#6
PipeDream
yes, that will do the job, at least for positive numbers. a separate function is not needed. I would only recommend that if we had a good way of inlining.
08-05-2006, 06:59 AM#7
Blade.dk
You know you can put integers everywhere that it takes real arguments without problems (note: there is an exception to this, returns), so there's no need for the I2R.

And what the hell is up with that piece of code Real to integer ( integer to real ( 1.5) )!! 1.5 is not an integer. Just use R2I(real) to floor a real.
08-05-2006, 07:03 AM#8
Linera
opps

my bad
i meant
I2R(R2I(1.5))

I need to keep it as a real for the return
08-05-2006, 07:04 AM#9
PipeDream
Haha, that just goes to show you why automatic type casting is a NASTY bug.
08-05-2006, 07:16 AM#10
Linera
Quote:
Originally Posted by PipeDream
Haha, that just goes to show you why automatic type casting is a NASTY bug.

ummm, HUH?