[User error] Zscript: Using flags in if statements changes flag

Bugs that have been investigated and resolved somehow.

Moderator: GZDoom Developers

Zscript: Using flags in if statements changes flag

Postby Night Falls » Fri Oct 08, 2021 3:31 pm

If you have an if statement that checks whether or not a flag is true, it will actually set the flag to whatever you're checking it for. Tested in the latest dev build.

Example ("friendly" imp):
Code: Select allExpand view
class testimp : DoomImp
{
   Default
   {
      +Friendly
   }
   override void Tick ()
   {
      super.Tick();   
      if(bFriendly = false)//this will actually set Friendly to false
      {A_Log("test");}
   }
}


Workaround until it's fixed (this imp is unfriendly by default for demonstration purposes):
Code: Select allExpand view
class testimp : DoomImp
{
   Default
   {
      -Friendly //if you set Friendly to true then it will log "yay", if you set set it to false it won't, just as intended.
   }
   override void Tick ()
   {
      super.Tick();   
      if(a_CheckFlag("Friendly","null"))//This won't print anything because Friendly is false
      {A_Log("Yay");}
   }
}
User avatar
Night Falls
 
Joined: 09 Mar 2020
Location: A hole in the bottom of the sea
Operating System: Windows 10/8.1/8/201x 64-bit

Re: Zscript: Using flags in if statements changes flag

Postby Graf Zahl » Fri Oct 08, 2021 4:12 pm

This is a user error.

'=' is the assignment operator. The equality comparison operator is '=='.
The code performs exaxtly what it's supposed to do.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: Zscript: Using flags in if statements changes flag

Postby Night Falls » Fri Oct 08, 2021 4:50 pm

That's actually kinda a relief, so I don't have to use the depreciated workaround. Good to know
User avatar
Night Falls
 
Joined: 09 Mar 2020
Location: A hole in the bottom of the sea
Operating System: Windows 10/8.1/8/201x 64-bit


Return to Closed Bugs

Who is online

Users browsing this forum: No registered users and 1 guest