open.mp forum
[Pawn] tag mismatch? - Printable Version

+ open.mp forum (https://forum.open.mp)
-- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3)
--- Forum: Pawn Scripting (https://forum.open.mp/forumdisplay.php?fid=10)
--- Thread: [Pawn] tag mismatch? (/showthread.php?tid=462)



tag mismatch? - mr_sacrimoni - 2019-04-25

PHP Code:
482: if(isequal(operator_str"")) {

483:? ? ?if(int_check == 1PlayerInfo[playerid][pInfo:id] = strval(str_split[1]);

484:? ? ?else if(int_check == 2PlayerInfo[playerid][pInfo:id] = floatstr(str_split[1]);

485: }

486:?else {

487:? ? ?if(int_check == 1PlayerInfo[playerid][pInfo:id] = strval(str_split[1]);

488:? ? ?else if(int_check == 2PlayerInfo[playerid][pInfo:id] = floatstr(str_split[1]);

489:? ? ?else format(PlayerInfo[playerid][pInfo:id], 256"%s"str_split[1]);

490: } 



.pwn(488) : warning 213: tag mismatch



It's funny because lines 484 and 488 are basically the same, just the different operator and yet I get an error on 488. Why?


RE: tag mismatch? - Ihnify - 2019-04-25

What type of str_split array?


RE: tag mismatch? - iSpark - 2019-04-25

I'm not getting this. In some cases you're treating str_split as string and in some as numerical datatype.



Could you clarify what you're trying to execute in this block?


RE: tag mismatch? - mr_sacrimoni - 2019-04-25

Depending on the datatype of variable I change string value to an actual value (int, float or string).

I'm just interested in why floatstr gives warning in one case, don't really need help with the code itself.


RE: tag mismatch? - hual - 2019-04-25

Maybe because = isn't a valid operator for Float therefore it gets called for _?


RE: tag mismatch? - Y_Less - 2019-04-27

`pinfo:id` must be an integer, rather than a float, but you are adding a float to it. That's the problem - you can only add an integer to a float if the result is also a float.


RE: tag mismatch? - mr_sacrimoni - 2019-04-27

(2019-04-27, 06:43 AM)Y_Less Wrote: `pinfo:id` must be an integer, rather than a float, but you are adding a float to it. ?That's the problem - you can only add an integer to a float if the result is also a float.

ID is a numerical representation of memory place inside of an enum.

For example if I have an enum:

PHP Code:
enum pInfo {
? ?
ID, (0)
? ?
Admin, (1)
? ?
Level, (2)
? ?
Float:Health (3)
}; 

pInfo:3 would hit Health, making it a float?


RE: tag mismatch? - iSpark - 2019-04-27

Shouldn't it be strfloat?
This is a guess that I'm making because I have no idea what you're trying to accomplish based on the snippet that you've provided. But judging by the fact that you used strval in the previous lines. Are you sure you wanted to use floatstr which changes a float to a string rather than strfloat?


RE: tag mismatch? - mr_sacrimoni - 2019-04-28

(2019-04-27, 12:53 PM)iSpark Wrote: Shouldn't it be strfloat?
This is a guess that I'm making because I have no idea what you're trying to accomplish based on the snippet that you've provided. But judging by the fact that you used strval in the previous lines. Are you sure you wanted to use floatstr which changes a float to a string rather than strfloat?

https://wiki.sa-mp.com/wiki/Floatstr

(2019-04-25, 09:26 PM)hual Wrote: Maybe because = isn't a valid operator for Float therefore it gets called for _?

Warning is on the line using '=' operator, not the = one.


RE: tag mismatch? - Y_Less - 2019-05-01

(2019-04-27, 09:53 AM)mr_sacrimoni Wrote:
(2019-04-27, 06:43 AM)Y_Less Wrote: `pinfo:id` must be an integer, rather than a float, but you are adding a float to it. ?That's the problem - you can only add an integer to a float if the result is also a float.



ID is a numerical representation of memory place inside of an enum.



For example if I have an enum:



PHP Code:
enum pInfo {

? ?
ID, (0)

? ?
Admin, (1)

? ?
Level, (2)

? ?
Float:Health (3)

}; 



pInfo:3 would hit Health, making it a float?



That's not how enums work. There's no run-time tag representation, so the VM doesn't know that `pinfo:3` is a float, nor does it know that `id` will be `3` and thus to use float operations. `Health` has tag `Float`, so if you explicitly use exactly that constant, the tags will work. Anything else and the tag information is lost.


RE: tag mismatch? - mr_sacrimoni - 2019-05-01

(2019-05-01, 10:09 AM)Y_Less Wrote:
(2019-04-27, 09:53 AM)mr_sacrimoni Wrote:
(2019-04-27, 06:43 AM)Y_Less Wrote: `pinfo:id` must be an integer, rather than a float, but you are adding a float to it. ?That's the problem - you can only add an integer to a float if the result is also a float.



ID is a numerical representation of memory place inside of an enum.



For example if I have an enum:



PHP Code:
enum pInfo {

? ?
ID, (0)

? ?
Admin, (1)

? ?
Level, (2)

? ?
Float:Health (3)

}; 



pInfo:3 would hit Health, making it a float?



That's not how enums work. ?There's no run-time tag representation, so the VM doesn't know that `pinfo:3` is a float, nor does it know that `id` will be `3` and thus to use float operations. ?`Health` has tag `Float`, so if you explicitly use exactly that constant, the tags will work. ?Anything else and the tag information is lost.



I am aware of that, but the logic stands. Could I just cast 'pinfo:3' to float avoiding the warning that way?


RE: tag mismatch? - Y_Less - 2019-05-02

You can add a cast, yes.