[ZScript]Refreshing custom ZScript Status Bar (Solved)

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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.

[ZScript]Refreshing custom ZScript Status Bar (Solved)

Postby Cherno » Mon Oct 08, 2018 9:00 pm

I wrote a custom status bar in ZScript, but now I reliazed that it is not redrawn continuously. My code is inside DrawMainBar, and I don't understand the logic behing the draw calls. From looking at the base Doom status bar, it looks like the Drawing call is made only once in Init, but stuff like the default ammo counters etc. obviously get updated during play. I have things like a counter for a certain inventory item etc. which should get updated as well, but they are only updated once when I pick something up for the first time, and never again. What do I have to do? :?:

Also, my while(...) loops only run for one iteration, what's up with that? :)
Last edited by Cherno on Thu Oct 11, 2018 8:18 pm, edited 1 time in total.
User avatar
Cherno
 
Joined: 06 Dec 2016

Re: [ZScript]Refreshing custom ZScript Status Bar

Postby Kinsie » Mon Oct 08, 2018 11:33 pm

Cherno wrote:From looking at the base Doom status bar, it looks like the Drawing call is made only once in Init
...what? Init() doesn't call Draw at all.

From the default doom_sbar.txt:
Code: Select allExpand view
   override void Init()
   {
      Super.Init();
      SetSize(32, 320, 200);

      // Create the font used for the fullscreen HUD
      Font fnt = "HUDFONT_DOOM";
      mHUDFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), true, 1, 1);
      fnt = "INDEXFONT_DOOM";
      mIndexFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), true);
      mAmountFont = HUDFont.Create("INDEXFONT");
      diparms = InventoryBarState.Create();
   }

   override void Draw (int state, double TicFrac)
   {
      Super.Draw (state, TicFrac);

      if (state == HUD_StatusBar)
      {
         BeginStatusBar();
         DrawMainBar (TicFrac);
      }
      else if (state == HUD_Fullscreen)
      {
         BeginHUD();
         DrawFullScreenStuff ();
      }
   }
User avatar
Kinsie
A Concept Utterly Obsolete
 
Joined: 22 Oct 2004
Location: MAP33
Discord: Find Me...
Twitch ID: thekinsie

Re: [ZScript]Refreshing custom ZScript Status Bar

Postby Cherno » Tue Oct 09, 2018 7:34 am

Yes, you are right. Anyway, when is Draw() called and how can I solve my problem? :3:
User avatar
Cherno
 
Joined: 06 Dec 2016

Re: [ZScript]Refreshing custom ZScript Status Bar

Postby Cherno » Tue Oct 09, 2018 7:04 pm

I would still like some input on this, if at all possible. Basically:

Why are the things I inserted into my status bar only updating once, while the default stuff like health and ammo is updated as usual?

Code: Select allExpand view
protected void DrawMainBar (double TicFrac)
   {
               //custom code start
      int credits = CheckInventory("CE_Credits");
      DrawString(mHUDFont, FormatNumber(credits ), (0,0), DI_TEXT_ALIGN_RIGHT, Font.CR_GOLD);//is only updated once after collecting the first CE_Credits item
                //custom code end

                //default status bar: ammo etc. gets updated like it should

      DrawImage("STBAR", (0, 168), DI_ITEM_OFFSETS);
      DrawImage("STTPRCNT", (90, 171), DI_ITEM_OFFSETS);
      DrawImage("STTPRCNT", (221, 171), DI_ITEM_OFFSETS);
                     
      Inventory a1 = GetCurrentAmmo();
      if (a1 != null) DrawString(mHUDFont, FormatNumber(a1.Amount, 3), (44, 171), DI_TEXT_ALIGN_RIGHT|DI_NOSHADOW);
      DrawString(mHUDFont, FormatNumber(CPlayer.health, 3), (90, 171), DI_TEXT_ALIGN_RIGHT|DI_NOSHADOW);
      DrawString(mHUDFont, FormatNumber(GetArmorAmount(), 3), (221, 171), DI_TEXT_ALIGN_RIGHT|DI_NOSHADOW);
               
                //...
   }
User avatar
Cherno
 
Joined: 06 Dec 2016

Re: [ZScript]Refreshing custom ZScript Status Bar

Postby Cherno » Thu Oct 11, 2018 11:48 am

I also noticed that ACS has no way to draw the currently selected inventory item, so I'd have to rely on ZScript... But since custom ZScript Status Bars apparently are not updated, I'd have to scrap my Chaos Engine TC :cry: I am somewhat confused though, because from what I have read so far, ZScript was presented as the way of the future?!?
User avatar
Cherno
 
Joined: 06 Dec 2016

Re: [ZScript]Refreshing custom ZScript Status Bar

Postby phantombeta » Thu Oct 11, 2018 11:53 am

You're clearly doing something wrong. We can't help you with only the small amount of code you posted, as it doesn't seem to show anything wrong.
User avatar
phantombeta
In the meadow of sinful thoughts, every flower's a perfect one
 
Joined: 02 May 2013
Location: The United Soviet Socialist Dictatorship of Hueland
Discord: phantombeta#2461
Twitch ID: doom2fan

Re: [ZScript]Refreshing custom ZScript Status Bar

Postby Cherno » Thu Oct 11, 2018 12:54 pm

I didn't change anything else in the default doom_sbar.txt that is part of gzdoom.pk3, apart from the 2 lines I commented. That's why I only posted this particular part :)

But if you say that the error lies on my end indeed, that already helps me since I know it isn't a problem with GZDoom itself :)
User avatar
Cherno
 
Joined: 06 Dec 2016

Re: [ZScript]Refreshing custom ZScript Status Bar

Postby phantombeta » Thu Oct 11, 2018 5:28 pm

If you only changed those two lines, that indicates the problem is located either in whatever is giving the item, or in the item itself. I have the feeling it's the latter, so you should post the inventory item's code.
User avatar
phantombeta
In the meadow of sinful thoughts, every flower's a perfect one
 
Joined: 02 May 2013
Location: The United Soviet Socialist Dictatorship of Hueland
Discord: phantombeta#2461
Twitch ID: doom2fan

Re: [ZScript]Refreshing custom ZScript Status Bar

Postby Cherno » Thu Oct 11, 2018 6:11 pm

This is CE_CoinA, money that appears in the level, and CE_Credits, the behind-the-scenes-stuff that the player actually collects in his inventory. It's made this way because there are different coins to be found which all give credits. I just noticed that curiously, the ZScript status bar code also not only updates only for the first pickup, but also doesn't take the real item count into account, so if I get 5 credits from a pickup, it only changes the credits display from 0 to 1.

Note that my ACS status bar works flawlessly with the money display etc., so I wonder if anything could be wrong with the item code or maybe it has something to do with how SBARINFO (which I don't use, besides the default one included in gzdoom.pk3) interacts (if it does) with a ZScript statusbar?

Code: Select allExpand view
ACTOR CE_CoinA : CustomInventory 26018
{
   Scale 2.0
   Radius 16
   Height 32
   
   States
   {
      Spawn:
      COIA A 1
                Loop
      
      Pickup:
      TNT1 A 0 A_GiveInventory("CE_Credits", 5)
      Stop
   }
}

ACTOR CE_Credits : Inventory
{
   Inventory.MaxAmount 999
}
User avatar
Cherno
 
Joined: 06 Dec 2016

Re: [ZScript]Refreshing custom ZScript Status Bar

Postby phantombeta » Thu Oct 11, 2018 6:28 pm

Actually, looking at the statusbar code again, I just noticed you're using CheckInventory. ACS' "CheckInventory" simply returns the amount of the item, while ZScript statusbars' CheckInventory actually does what the name implies and checks if there's at least a certain amount of the item, and behaves like A_JumpIfInventory. Since you didn't specify any amount, it uses the amount argument's default value of 1.
You need to use GetAmount instead to get the amount of an inventory item from a statusbar.
User avatar
phantombeta
In the meadow of sinful thoughts, every flower's a perfect one
 
Joined: 02 May 2013
Location: The United Soviet Socialist Dictatorship of Hueland
Discord: phantombeta#2461
Twitch ID: doom2fan

Re: [ZScript]Refreshing custom ZScript Status Bar

Postby Cherno » Thu Oct 11, 2018 8:18 pm

Thank you. That was the cause of my problem. Silly me just re-used the ACS syntac for the function.
User avatar
Cherno
 
Joined: 06 Dec 2016


Return to Scripting

Who is online

Users browsing this forum: No registered users and 2 guests