02.03.2016, 05:37
Suppose I have these:
I want to make them a single function that accepts both integer arguments and float arguments. I started with this, but it crashes the compiler:
I already know about the compiler bug that causes "case (tagof(Float)" to crash, which is why I used "case ((tagof(Float))" (as ****** suggested somewhere a long time ago).
1. What am I doing wrong?
2. How do I fix it?
Never really used tagof before in something like this.
pawn Код:
stock range(...)
{
new mini = getarg(0), maxi = mini;
for(new i = numargs() - 1; i != 1; i--) {
if(getarg(i) > maxi)
maxi = getarg(i);
if(getarg(i) < mini)
mini = getarg(i);
}
return maxi - mini;
}
stock Float:frange(Float:...)
{
new Float:mini = Float:getarg(0), Float:maxi = mini;
for(new i = numargs() - 1; i != 1; i--) {
if(Float:getarg(i) > maxi)
maxi = Float:getarg(i);
if(Float:getarg(i) < mini)
mini = Float:getarg(i);
}
return maxi - mini;
}
pawn Код:
stock Float:xrange({Float, _}:...)
{
new Float:mini, Float:maxi, tag = tagof(getarg(0));
switch(tag) {
case ((tagof(Float:))): {
mini = Float:getarg(0);
maxi = mini;
}
default: {
mini = getarg(0);
maxi = mini;
}
}
// That's how far I got...
}
1. What am I doing wrong?
2. How do I fix it?
Never really used tagof before in something like this.