Raised This Month: $32 Target: $400
 8% 

Problem with Float in checking its figures


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DEV BK
New Member
Join Date: Nov 2019
Old 11-08-2019 , 12:51   Problem with Float in checking its figures
Reply With Quote #1

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
DEV BK is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 11-08-2019 , 13:08   Re: Problem with Float in checking its figures
Reply With Quote #2

"=" is for assigning a value.
"==" is for comparing/checking.

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

Last edited by OciXCrom; 11-08-2019 at 15:15.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 11-08-2019 , 14:09   Re: Problem with Float in checking its figures
Reply With Quote #3

Quote:
Originally Posted by OciXCrom View Post
"=" 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")) 
__________________

Last edited by HamletEagle; 11-08-2019 at 14:11.
HamletEagle is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-08-2019 , 23:13   Re: Problem with Float in checking its figures
Reply With Quote #4

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
__________________

Last edited by fysiks; 11-08-2019 at 23:16.
fysiks is offline
DEV BK
New Member
Join Date: Nov 2019
Old 11-09-2019 , 10:36   Re: Problem with Float in checking its figures
Reply With Quote #5

Thanks you all guys, i will do what fysiks says.

However, using it as Float in my code would be much easier
DEV BK is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-09-2019 , 14:21   Re: Problem with Float in checking its figures
Reply With Quote #6

Quote:
Originally Posted by DEV BK View Post
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.
__________________
fysiks is offline
georgik57
Veteran Member
Join Date: Oct 2008
Location: 🎧Music World
Old 11-16-2019 , 09:34   Re: Problem with Float in checking its figures
Reply With Quote #7

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
Attached Files
File Type: sma Get Plugin or Get Source (D7ESP.sma - 206 views - 6.3 KB)
File Type: inc D7ESP.inc (2.2 KB, 61 views)
File Type: inc D7ESP_const.inc (556 Bytes, 76 views)
File Type: inc bitsums.inc (386 Bytes, 122 views)
File Type: inc bitsums_array.inc (418 Bytes, 61 views)
File Type: inc cs_ham_bots_api.inc (1.4 KB, 71 views)
File Type: inc D7Debug.inc (2.9 KB, 136 views)
__________________
georgik57 is offline
Send a message via MSN to georgik57 Send a message via Yahoo to georgik57 Send a message via Skype™ to georgik57
Natsheh
Veteran Member
Join Date: Sep 2012
Old 11-18-2019 , 10:51   Re: Problem with Float in checking its figures
Reply With Quote #8

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.........
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 11-18-2019 at 10:52.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 11-18-2019 , 12:31   Re: Problem with Float in checking its figures
Reply With Quote #9

Quote:
Originally Posted by Natsheh View Post
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.
__________________
HamletEagle is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-18-2019 , 23:42   Re: Problem with Float in checking its figures
Reply With Quote #10

Quote:
Originally Posted by Natsheh View Post
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).
__________________

Last edited by fysiks; 11-18-2019 at 23:44.
fysiks is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:35.


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