Key display troubles

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Key display troubles

Postby Telemassacre » Tue May 25, 2021 5:39 pm

Hi, i need some help. I have some trouble with adding new keys. They don't show up on the status bar.
ZScript:
Code: Select allExpand view
class RTPStatusBar : DoomStatusBar
{
   override void DrawBarKeys()
   {
      bool locks[9];
      String image;
      for(int i = 0; i < 8; i++) locks[i] = CPlayer.mo.CheckKeys(i + 1, false, true);
      // key 1
      if (locks[1] && locks[4]) image = "STKEYS6";
      else if (locks[1]) image = "STKEYS0";
      else if (locks[4]) image = "STKEYS3";
      DrawImage(image, (239, 171), DI_ITEM_OFFSETS);
      // key 3 [broken key]
      if (locks[7] && locks[8]) image = "I_SLVBTH";
      else if (locks[7]) image = "I_SLVCRD";
      else if (locks[8]) image = "I_SLVSKU";
      else image = "";
      // key 2
      if (locks[2] && locks[5]) image = "STKEYS7";
      else if (locks[2]) image = "STKEYS1";
      else if (locks[5]) image = "STKEYS4";
      else image = "";
      DrawImage(image, (244, 181), DI_ITEM_OFFSETS);
      // key 4
      if (locks[0] && locks[3]) image = "STKEYS8";
      else if (locks[0]) image = "STKEYS2";
      else if (locks[3]) image = "STKEYS5";
      else image = "";
      DrawImage(image, (239, 191), DI_ITEM_OFFSETS);
   }
}
User avatar
Telemassacre
 
Joined: 13 Oct 2020
Location: ACS School
Operating System: Windows 10/8.1/8/201x 64-bit

Re: Key display troubles

Postby Player701 » Tue Jun 01, 2021 8:22 am

Provided that your LOCKDEFS are set up correctly (since CheckKeys uses the same lock numbers that LOCKDEFS does) the problem is in your for loop. You check for locks[8] but your loop only counts up to 7 because when i becomes 8 the condition i < 8 evaluates to false. Which means that locks[8] is never assigned to.

There are two ways to fix this: change i < 8 to either i <= 8 or i < 9. It doesn't matter which one you choose, the result will be the same.
User avatar
Player701
 
 
 
Joined: 13 May 2009
Location: Russia
Discord: Player701#8214
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support


Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests