Raised This Month: $51 Target: $400
 12% 

Solved possibly unintended assignment


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 04-25-2022 , 13:51   possibly unintended assignment
Reply With Quote #1

I have this piece of code
PHP Code:
static anim

if(anim g_models[index][draw2])
{
    switch(
random_num(1DRAW2_CHANCE))
    {
        case 
DRAW2_CHANCEplay_anim(idanim)
        default: 
play_anim(id3)
    }

I like how it looks. It even compiles but compile.exe throws me a warn 211: possibly unintended assignment.
Do I have to change it (to code below) or not?
PHP Code:
static animanim g_models[index][draw2]

if(
anim)
{
    switch(
random_num(1DRAW2_CHANCE))
    {
        case 
DRAW2_CHANCEplay_anim(idanim)
        default: 
play_anim(id3)
    }

__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951

Last edited by kww; 04-26-2022 at 01:42.
kww is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-25-2022 , 14:13   Re: possibly unintended assignment
Reply With Quote #2

Use () around the expression.
__________________
HamletEagle is offline
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 04-25-2022 , 18:08   Re: possibly unintended assignment
Reply With Quote #3

Quote:
Originally Posted by HamletEagle View Post
Use () around the expression.
which one? Don't understand
__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951
kww is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-25-2022 , 18:55   Re: possibly unintended assignment
Reply With Quote #4

The if statement expects a conditional expression which generally is an expression to compare two or more values. A common conditional expression is to compare equality of two values using the "==" comparison symbol. So, when you try to assign a value to a variable instead of doing a typical conditional expression, it thinks that you might have mistakenly forgot to add the second equal sign.

So, to suppress the warning, you need to put your variable assignment in parentheses so that it tells the compiler that you are intentionally doing a variable assignment instead of having a typo in your conditional expression.

Example:
PHP Code:
static anim

if( (anim g_models[index][draw2]) )
{
    switch(
random_num(1DRAW2_CHANCE))
    {
        case 
DRAW2_CHANCEplay_anim(idanim)
        default: 
play_anim(id3)
    }

__________________

Last edited by fysiks; 04-25-2022 at 18:57.
fysiks is offline
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 04-26-2022 , 01:37   Re: possibly unintended assignment
Reply With Quote #5

Quote:
Originally Posted by fysiks View Post
The if statement expects a conditional expression which generally is an expression to compare two or more values. A common conditional expression is to compare equality of two values using the "==" comparison symbol. So, when you try to assign a value to a variable instead of doing a typical conditional expression, it thinks that you might have mistakenly forgot to add the second equal sign.

So, to suppress the warning, you need to put your variable assignment in parentheses so that it tells the compiler that you are intentionally doing a variable assignment instead of having a typo in your conditional expression.

Example:
PHP Code:
static anim

if( (anim g_models[index][draw2]) )
{
    switch(
random_num(1DRAW2_CHANCE))
    {
        case 
DRAW2_CHANCEplay_anim(idanim)
        default: 
play_anim(id3)
    }

That makes sense. Thanks
__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951
kww is offline
Reply



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 09:55.


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