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

warning 226, why?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Blowst
Senior Member
Join Date: Feb 2011
Location: Korea, Republic of
Old 06-18-2015 , 02:22   warning 226, why?
Reply With Quote #1

I got a warning while compile a script, but idk y the compiler did.

Code:
test.sp(229) : warning 226: a variable is assigned to itself (symbol "startrdm")
definition of startrdm:
PHP Code:
bool startrdm[3] = false
and the line 229:
PHP Code:
startrdm[0] = !startrdm[0]; 
when i edit this like below, the compiler does own work without any warning.
PHP Code:
bool startrdm false;
startrdm = !startrdm
Did I anything wrong?


EDIT1: the version of compiler is 1.7.3-dev+5209
__________________
Sorry about my poor English


Last edited by Blowst; 06-22-2015 at 10:26.
Blowst is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 06-18-2015 , 02:48   Re: warning 226, why?
Reply With Quote #2

Quote:
Originally Posted by Blowst View Post
PHP Code:
startrdm[0] = !startrdm[0]; 
This can't be right. You are assigning the value of startrdm to startrdm.

Post the full code for the plugin.
__________________
Spirit_12 is offline
Blowst
Senior Member
Join Date: Feb 2011
Location: Korea, Republic of
Old 06-18-2015 , 03:05   Re: warning 226, why?
Reply With Quote #3

Quote:
Originally Posted by Spirit_12 View Post
This can't be right. You are assigning the value of startrdm to startrdm.

Post the full code for the plugin.
It means 'Invert a boolean' via assigning the inverted value of itself.

and the compiler warn this method when the boolean is in an array.

it don't warn when the variable is single boolean.

PHP Code:
#include <sourcemod>
#include <sdktools>

bool startrdm[3] = false;
bool startrd[3] = false;
bool testbool false;

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_atest2"AngleTest2);

    
testbool = !testbool;
    
PrintToServer("testbool = !testbool\ntestbool: %s"testbool "True":"False");
}

public 
Action AngleTest2(int clientint args)
{    
    
Menu menu = new Menu(selection2);
    
menu.SetTitle("Angles Test Menu2");
    
    if(!
startrdm[0])
            
menu.AddItem("""Start [0]");
    else    
menu.AddItem("""End [0]");
    
    if(!
startrd[0])
            
menu.AddItem("""[0]++");
    else    
menu.AddItem("""[0]--");
    
    if(!
startrdm[1])
            
menu.AddItem("""Start [1]");
    else    
menu.AddItem("""End [1]");
    
    if(!
startrd[1])
            
menu.AddItem("""[1]++");
    else    
menu.AddItem("""[1]--");
    
    if(!
startrdm[2])
            
menu.AddItem("""Start [2]");
    else    
menu.AddItem("""End [2]");
    
    if(!
startrd[2])
            
menu.AddItem("""[2]++");
    else    
menu.AddItem("""[2]--");
    
    
menu.Display(clientMENU_TIME_FOREVER);
}

public 
int selection2(Menu menuMenuAction actionint clientint item)
{
    if(
action == MenuAction_Select)
    {
        if(
item == 0)
        {
            
startrdm[0] = !startrdm[0];
        }
        else if(
item == 1)
        {
            
startrd[0] = !startrd[0];
        }
        else if(
item == 2)
        {
            
startrdm[1] = !startrdm[1];
        }
        else if(
item == 3)
        {
            
startrd[1] = !startrd[1];
        }
        else if(
item == 4)
        {
            
startrdm[2] = !startrdm[2];
        }
        else if(
item == 5)
        {
            
startrd[2] = !startrd[2];
        }
            
        
AngleTest2(client0);
    }
    else if(
action == MenuAction_End)
    {
        
delete menu;
    }

__________________
Sorry about my poor English


Last edited by Blowst; 06-18-2015 at 03:06. Reason: #
Blowst is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 06-18-2015 , 03:15   Re: warning 226, why?
Reply With Quote #4

Quote:
Originally Posted by Spirit_12 View Post
You are assigning the value of startrdm to startrdm.
Incorrect. Please note the exclamation mark in front of the variable name on the right side of the = sign.
__________________

Last edited by ddhoward; 06-18-2015 at 03:15.
ddhoward is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 06-18-2015 , 06:33   Re: warning 226, why?
Reply With Quote #5

I just tried this with the old 1.5.4 compiler to see if this was introduced with the new syntax update. It wasn't, it issues the same error. Still, this should work and looks like a bug to me.

Tip for op
__________________

Last edited by Impact123; 06-18-2015 at 06:35.
Impact123 is offline
Blowst
Senior Member
Join Date: Feb 2011
Location: Korea, Republic of
Old 06-19-2015 , 00:13   Re: warning 226, why?
Reply With Quote #6

Quote:
Originally Posted by Impact123 View Post
Tip for op
yes, right. i did it just for tests

but question, it still initialize by default? not keep a garbage value?

'decl' is not used in SM1.7+ syntax :S
__________________
Sorry about my poor English


Last edited by Blowst; 06-22-2015 at 10:28.
Blowst is offline
RedSword
SourceMod Plugin Approver
Join Date: Mar 2006
Location: Quebec, Canada
Old 06-19-2015 , 00:43   Re: warning 226, why?
Reply With Quote #7

Yes, by default anything declared will have its default value (for instance an array of char will be zero'ed (0='\0'). There are no 1.7 way to quickly declare without initializing.

Red
__________________
My plugins :
Red Maze
Afk Bomb
RAWR (per player/rounds Awp Restrict.)
Kill Assist
Be Medic

You can also Donate if you appreciate my work
RedSword 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 05:04.


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