Tags in enums, passing to functions
#1

http://pastebin.com/NKvGABJU

See line 18 and 19. The if() statements always evaluate as true (both of them - which is impossible). It fixes if I prefix them with Float: like so:

pawn Код:
if(Float:PlayerStats[playerid][stat] > 100) PlayerStats[playerid][stat] = 100; // First line in question
if(Float:PlayerStats[playerid][stat] < 0) PlayerStats[playerid][stat] = 0; // Second line in question
Other than using the Float: tag, how can I fix this? They print out fine as floats in printf, they ARE floats, they have float tags, so why do I need to put another Float: tag? :/

P.S. This isn't a script I'm making to use, I'm just playing around.
Reply
#2

Maybe the compiler doesn't recognise the variable as a float, I am pretty sure about it
So the code uses the integer value of the float but that doesnt explain why both checks execute

To fix the problem you need to add on on side a float or use float values on the right (100.0, 0.0)
Reply
#3

I guess the problem is that the tag of 'stat' is 'E_PLAYER_STAT' and not 'Float'. Any other way to fix this though?

I need the tag of PlayerStats[playerid][stat] to be Float: not E_PLAYER_STATS: D:
Reply
#4

halp pls how fix him
Reply
#5

I THINK this is a compiler bug, sorry if I couldn't help, maybe ****** knows something about this. As he did help make the compiler >.<.

You might have to make a separate function for floats and integers and even play around with _: (tag removal)
Reply
#6

Well I don't think it's a 'bug' so to speak, as the tag of 'stat' is E_PLAYER_STATS, not Float:, so I understand why it's happening, I was just wondering if there's an alternative solution rather than prefixing it with the Float: tag.
Reply
#7

I may misunderstood it, anyways if the problem is that it does not compare the floats correct then why don't you use floatcmp instead? Float comparison.
pawn Код:
if( floatcmp( PlayerStats[playerid][stat], 100.0 ) == 1 )
{
    // PlayerStats[playerid][stat] is bigger than 100.0
}
EDIT: I think I misunderstood.. I just saw the post above.
Reply
#8

Quote:
Originally Posted by ******
Посмотреть сообщение
That's probably because "stat" is a variable so can represent any part of the enum at all. Imagine the case where you have multiple tags in the enum - suddenly your simple "if" becomes far more complex determining what the tag of the dynamically selected slot is and calling the correct comparison function for the given tag. Not only is this very hard but offset tags are not stored in the compiled amx. The fact that all of your enum slots are Float: is just a special case that COULD be detected but isn't.

This is actually made entirely impossible to resolve by the fact that you can have multiple names for the same enum slot, each with different tags (like a "union" in C). In that case, which tag should be used when dynamically selecting a slot as you are? Better to just have a default unless told otherwise as you do.
I don't wholly understand this. The tag of 'stat' is E_PLAYER_STATS, right? But what it represents (pStat_respect) is a Float. So it's basically a float being represented with E_PLAYER_STATS tag? If so, how can I 'keep' the original Float: tag to use it in if()?

What do you mean by this:

Quote:

This is actually made entirely impossible to resolve by the fact that you can have multiple names for the same enum slot,

?

Do you mean this?

pawn Код:
enum E_PLAYER_STATS // Percentages (between 0 - 100)
{
    pStat_something = 0,
    Float:pStat_somethingElse = 0
};
Where one has a Float: tag and one doesn't?

Okay, so what's my best course of action to get around this, apart from storing the types of variables in an array?
Reply
#9

Because this was just a simple test, now I'm wondering about how it'd work with an enum that has floats and integers.
Reply
#10

So would ChangePlayerIntStat/ChangePlayerFloatStat be the best method to 'get around' this? Or is there an alternative method?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)