Burgershot
  • Home
  • Members
  • Team
  • Help
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Burgershot SA-MP Pawn Scripting [Pawn] tag mismatch?

 
  • 0 Vote(s) - 0 Average
Pawn tag mismatch?
mr_sacrimoni
Offline

Burgershot Member
Posts: 16
Threads: 3
Joined: Apr 2019
Reputation: 1
#1
2019-04-25, 02:07 PM
PHP Code:
482: if(isequal(operator_str, "+")) {
483:     if(int_check == 1) PlayerInfo[playerid][pInfo:id] += strval(str_split[1]);
484:     else if(int_check == 2) PlayerInfo[playerid][pInfo:id] += floatstr(str_split[1]);
485: }
486: else {
487:     if(int_check == 1) PlayerInfo[playerid][pInfo:id] = strval(str_split[1]);
488:     else if(int_check == 2) PlayerInfo[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?
Ihnify
Offline

Burgershot Member
Posts: 8
Threads: 0
Joined: Apr 2019
Reputation: 0
Location: Ukraine
#2
2019-04-25, 05:51 PM (This post was last modified: 2019-04-25, 05:52 PM by Ihnify.)
What type of str_split array?

iSpark
Offline

Burgershot Member
Posts: 10
Threads: 2
Joined: Apr 2019
Reputation: 0
Location: India
#3
2019-04-25, 07:36 PM
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?
mr_sacrimoni
Offline

Burgershot Member
Posts: 16
Threads: 3
Joined: Apr 2019
Reputation: 1
#4
2019-04-25, 09:14 PM (This post was last modified: 2019-04-25, 09:14 PM by mr_sacrimoni.)
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.
hual
Offline

King

Posts: 106
Threads: 3
Joined: Feb 2019
Reputation: 7
Location: Bulgaria
#5
2019-04-25, 09:26 PM
Maybe because += isn't a valid operator for Float therefore it gets called for _?
Y_Less
Offline

Administrator

Posts: 323
Threads: 16
Joined: Feb 2019
Reputation: 90
#6
2019-04-27, 06:43 AM
`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.
mr_sacrimoni
Offline

Burgershot Member
Posts: 16
Threads: 3
Joined: Apr 2019
Reputation: 1
#7
2019-04-27, 09:53 AM (This post was last modified: 2019-04-27, 09:55 AM by mr_sacrimoni.)
(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?
iSpark
Offline

Burgershot Member
Posts: 10
Threads: 2
Joined: Apr 2019
Reputation: 0
Location: India
#8
2019-04-27, 12:53 PM (This post was last modified: 2019-04-27, 12:54 PM by iSpark.)
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?
mr_sacrimoni
Offline

Burgershot Member
Posts: 16
Threads: 3
Joined: Apr 2019
Reputation: 1
#9
2019-04-28, 05:32 PM (This post was last modified: 2019-04-28, 05:34 PM by mr_sacrimoni.)
(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.
Y_Less
Offline

Administrator

Posts: 323
Threads: 16
Joined: Feb 2019
Reputation: 90
#10
2019-05-01, 10:09 AM
(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.
mr_sacrimoni
Offline

Burgershot Member
Posts: 16
Threads: 3
Joined: Apr 2019
Reputation: 1
#11
2019-05-01, 04:54 PM
(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?
Y_Less
Offline

Administrator

Posts: 323
Threads: 16
Joined: Feb 2019
Reputation: 90
#12
2019-05-02, 09:15 AM
You can add a cast, yes.
« Next Oldest | Next Newest »



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Burgershot - Powered by our Community and MyBB Original Theme by Emerald

Linear Mode
Threaded Mode