AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Can't get rid of a tag mismatch (https://forums.alliedmods.net/showthread.php?t=75553)

danielkza 08-07-2008 18:20

Can't get rid of a tag mismatch
 
This is my code
PHP Code:

stock GetArgColor(arg_num,{Float,_}:color[3],tag tagof(color))
{
    new 
arg[32]
    
read_argv(arg_num,arg,charsmax(arg))
    
    if(!
strlen(arg))
        return 
false
        
    
new sizeof(AMX_SUPER_COLORS_NAME)
    while(
i-- > && !equali(AMX_SUPER_COLORS_NAME[i],arg,charsmax(arg))) {}
    
    if(
>= 0)
    {
        if(
tag == tagof(float))
        {
            
color[0] = float(AMX_SUPER_COLORS_VALUE[i][0])
            
color[1] = float(AMX_SUPER_COLORS_VALUE[i][1])
            
color[2] = float(AMX_SUPER_COLORS_VALUE[i][2])
        }
        else
        {
            
// I tried to do a direct copy here,but I got a tag mismatch even when overriding both tags.
            
color AMX_SUPER_COLORS_VALUE[i]
        }
        
        return 
true
    
}
    else if(!
is_str_num(arg))
        return 
false
        
    
new temp_color[3]
    
temp_color[0] = str_to_num(arg)
    
    if(!
read_argv(++arg_num,arg,charsmax(arg)) || !is_str_num(arg))
        return 
false
    temp_color
[1] = str_to_num(arg)
    
    if(!
read_argv(++arg_num,arg,charsmax(arg)) || !is_str_num(arg))
        return 
false
    temp_color
[2] = str_to_num(arg)
    
    if(
tag == tagof(float))
        
IVecFVec(temp_color,color)
    else
        
temp_color _:color
        
    
return true


I get a tag mismatch error on line
PHP Code:

color AMX_SUPER_COLORS_VALUE[i

I tried overring the tag in left value,in right value,or in both,and I still get a tag mismatch error. Any idea why?

Emp` 08-07-2008 22:01

Re: Can't get rid of a tag mismatch
 
I forget the reason but you can't do {Float,_}:color[3]. Just do Float:color[3] and convert it to a float or just make another function to get it as an int.

danielkza 08-08-2008 12:35

Re: Can't get rid of a tag mismatch
 
Quote:

Originally Posted by Emp` (Post 666220)
I forget the reason but you can't do {Float,_}:color[3]. Just do Float:color[3] and convert it to a float or just make another function to get it as an int.

I find out a workaround. I'm create a temp_color array(int), use IVecFVec if it's a float, and copyc(_:color,3,temp_color,-1), and get no erros.
Complete code:
PHP Code:

stock GetArgColor(arg_num,{Float,_}:color[3],tag tagof(color))
{
    
// Read first argument
    
new arg[32]
    
read_argv(arg_num,arg,charsmax(arg))
    
    
// Failed, return
    
if(!strlen(arg))
        return 
false
    
    
// Get the size of the color array
    
new sizeof(AMX_SUPER_COLORS_NAME)
    
// Loop decrementing the counter, and break on color found
    // If no color was found, i == -1
    
while(i-- > && !equali(AMX_SUPER_COLORS_NAME[i],arg,charsmax(arg))) {}
    
    new 
temp_color[3]
    
    
// We found our color,copy values to temp array
    
if(>= 0)
        
temp_color AMX_SUPER_COLORS_VALUE[i]
    
    
// Color not found, check for RGB values
    // Argument not a number,fail
    
else if(!is_str_num(arg))
        return 
false

    
else
    {
        
// Copy the first number to the temp array
        
temp_color[0] = clamp(str_to_num(arg),0,255)
        
        
// Read next argument and increment argument counter
        
read_argv(++arg_num,arg,charsmax(arg))
        
        
// Error reading argument or it's not a number,fail
        
if(!strlen(arg) || !is_str_num(arg))
            return 
false
        temp_color
[1] = clamp(str_to_num(arg),0,255)
        
        
// Read next argument and increment argument counter
        
read_argv(++arg_num,arg,charsmax(arg))
        
        
// Error reading argument or it's not a number,fail
        
if(!strlen(arg) || !is_str_num(arg))
            return 
false
        temp_color
[2] = clamp(str_to_num(arg),0,255)
    }
    
    
// Return is a Float:, convert temp array
    
if(tag == tagof(float))
        
IVecFVec(temp_color,color)
    else
        
// This workaround is needed because normal copying(=) would give a tag mismatch warning,no matter what I did
        
copyc(_:color,3,temp_color,256)
        
    return 
true



Emp` 08-09-2008 00:32

Re: Can't get rid of a tag mismatch
 
Quote:

Originally Posted by danielkza (Post 666512)
I find out a workaround. I'm create a temp_color array(int), use IVecFVec if it's a float, and copyc(_:color,3,temp_color,-1), and get no erros.
Complete code:
PHP Code:

stock GetArgColor(arg_num,{Float,_}:color[3],tag tagof(color))
{
    
// Read first argument
    
new arg[32]
    
read_argv(arg_num,arg,charsmax(arg))
    
    
// Failed, return
    
if(!strlen(arg))
        return 
false
    
    
// Get the size of the color array
    
new sizeof(AMX_SUPER_COLORS_NAME)
    
// Loop decrementing the counter, and break on color found
    // If no color was found, i == -1
    
while(i-- > && !equali(AMX_SUPER_COLORS_NAME[i],arg,charsmax(arg))) {}
    
    new 
temp_color[3]
    
    
// We found our color,copy values to temp array
    
if(>= 0)
        
temp_color AMX_SUPER_COLORS_VALUE[i]
    
    
// Color not found, check for RGB values
    // Argument not a number,fail
    
else if(!is_str_num(arg))
        return 
false

    
else
    {
        
// Copy the first number to the temp array
        
temp_color[0] = clamp(str_to_num(arg),0,255)
        
        
// Read next argument and increment argument counter
        
read_argv(++arg_num,arg,charsmax(arg))
        
        
// Error reading argument or it's not a number,fail
        
if(!strlen(arg) || !is_str_num(arg))
            return 
false
        temp_color
[1] = clamp(str_to_num(arg),0,255)
        
        
// Read next argument and increment argument counter
        
read_argv(++arg_num,arg,charsmax(arg))
        
        
// Error reading argument or it's not a number,fail
        
if(!strlen(arg) || !is_str_num(arg))
            return 
false
        temp_color
[2] = clamp(str_to_num(arg),0,255)
    }
    
    
// Return is a Float:, convert temp array
    
if(tag == tagof(float))
        
IVecFVec(temp_color,color)
    else
        
// This workaround is needed because normal copying(=) would give a tag mismatch warning,no matter what I did
        
copyc(_:color,3,temp_color,256)
        
    return 
true



it might compile fine, but it won't work (I've tried something similar before)

danielkza 08-09-2008 11:58

Re: Can't get rid of a tag mismatch
 
Quote:

Originally Posted by Emp` (Post 666802)
it might compile fine, but it won't work (I've tried something similar before)

I tested it and it works absolutely fine. I see no reason why it wouldn't work. In pawn integers and chars are the same tag(none), so it will make no difference. Also, since all the values are clamped beetween 0 and 255,-1 will never appear. By limiting the length I make sure only the correct part will be copied. Don't see the problem here.


All times are GMT -4. The time now is 05:34.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.