AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Problem with Float in checking its figures (https://forums.alliedmods.net/showthread.php?t=319569)

DEV BK 11-08-2019 12:51

Problem with Float in checking its figures
 
Hello, i have this code (i can't post it all for some reason's) :

Code:

new Float:WallStatus[33][3]

public plugin_init() {
        register_plugin(PLUGIN, VERSION, AUTHOR)
       
        register_clcmd("say /wallhack", "WallOnOff")

        // ....
}

public client_disconnect(id) {

        WallStatus[id][1] = 0.0
}
public WallOnOff(id)
{
        if((WallStatus[id][1] = 0.0))
        {
                WallStatus[id][1] = 1.0;
               
               
        }
        else
        {
                WallStatus[id][1] = 0.0;
        }
}

public Wallhack(id, walls)
{
        if(is_user_alive(id) && (WallStatus[id][1] = 1.0))
        {
                // ...
        }
}

The problem its cannot check if WallStatus[id][1] is 1.0 or 0.0, i tested the code without /wallhack switch and its worked with no problems but nothing happen when use this client command : /wallhack

what i missing?? please help :cry::cry::cry:

OciXCrom 11-08-2019 13:08

Re: Problem with Float in checking its figures
 
"=" is for assigning a value.
"==" is for comparing/checking.

So using "=" with "if" is not what you would do here.

HamletEagle 11-08-2019 14:09

Re: Problem with Float in checking its figures
 
Quote:

Originally Posted by OciXCrom (Post 2672371)
"=" is for assigning a value.
"==" is for comparing/checking.

So using "=" with "if" is invalid.

Actually it is valid.
PHP Code:

if((5)) 

will assign 5 to a and return 5. Of course, this is not how you would want "if" to behave in most cases and most likely not what OP intended.

A case where this is useful(read as "works as you want") is:
PHP Code:

new target = -1
while((target find_ent_by_class(target"something")) 


fysiks 11-08-2019 23:13

Re: Problem with Float in checking its figures
 
Also note that a floating point value can never exactly represent a value of 1.0. Since you're using the variable as a boolean value, define it as a boolean tag.

Code:

new bool:WallStatus[33][3]
WallStatus[id][1] = true


DEV BK 11-09-2019 10:36

Re: Problem with Float in checking its figures
 
Thanks you all guys, i will do what fysiks says.

However, using it as Float in my code would be much easier

fysiks 11-09-2019 14:21

Re: Problem with Float in checking its figures
 
Quote:

Originally Posted by DEV BK (Post 2672457)
However, using it as Float in my code would be much easier

Based on the code that you've given, that is definitely NOT true.

georgik57 11-16-2019 09:34

Re: Problem with Float in checking its figures
 
7 Attachment(s)
Hope this saves you some effort.
Sorry I can't post the main sma here(either attached or as code). For some reason, the forum sees it as some kind of potential attack and blocks it.
https://pastebin.com/8vHufWEX

Natsheh 11-18-2019 10:51

Re: Problem with Float in checking its figures
 
it really depends on how smart the compiler is, for AMXX its stupid, if(a = 5) since its in a if statement it should be comparing and since pawn in amxx doesnt support data types there are no reason for double equal chars for comparing....

also beside pawn uses only unsign data type.........

HamletEagle 11-18-2019 12:31

Re: Problem with Float in checking its figures
 
Quote:

Originally Posted by Natsheh (Post 2673338)
it really depends on how smart the compiler is, for AMXX its stupid, if(a = 5) since its in a if statement it should be comparing and since pawn in amxx doesnt support data types there are no reason for double equal chars for comparing....

That sounds like BS.

fysiks 11-18-2019 23:42

Re: Problem with Float in checking its figures
 
Quote:

Originally Posted by Natsheh (Post 2673338)
it really depends on how smart the compiler is, for AMXX its stupid, if(a = 5) since its in a if statement it should be comparing and since pawn in amxx doesnt support data types there are no reason for double equal chars for comparing....

also beside pawn uses only unsign data type.........

Umm . . no. One equal sign is assignment, two is for comparison. The compiler should not promote bad coding practices and should tell you that you might be doing it wrong. If a language did do that, I'd consider it a poorly designed language.

Also, when used as integers (e.g. untagged variables) are signed integers. How else are you going to get -1? I never seen a mechanism to force them to be unsigned (granted, I've never search for it either).


All times are GMT -4. The time now is 02:46.

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