• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] tag mismatch?
#1
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?
  Reply
#2
What type of str_split array?


  Reply
#3
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?
  Reply
#4
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.
  Reply
#5
Maybe because = isn't a valid operator for Float therefore it gets called for _?
  Reply
#6
`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.
  Reply
#7
(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?
  Reply
#8
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?
  Reply
#9
(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.
  Reply
#10
(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.
  Reply
#11
(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?
  Reply
#12
You can add a cast, yes.
  Reply


Forum Jump: