[ZScript]Refreshing custom ZScript Status Bar (Solved)

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.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
Cherno
Posts: 1309
Joined: Tue Dec 06, 2016 11:25 am

[ZScript]Refreshing custom ZScript Status Bar (Solved)

Post by Cherno »

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 7:18 pm, edited 1 time in total.
User avatar
Kinsie
Posts: 7399
Joined: Fri Oct 22, 2004 9:22 am
Graphics Processor: nVidia with Vulkan support
Location: MAP33
Contact:

Re: [ZScript]Refreshing custom ZScript Status Bar

Post by Kinsie »

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 all

	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
Cherno
Posts: 1309
Joined: Tue Dec 06, 2016 11:25 am

Re: [ZScript]Refreshing custom ZScript Status Bar

Post by Cherno »

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

Re: [ZScript]Refreshing custom ZScript Status Bar

Post by Cherno »

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 all

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
Posts: 1309
Joined: Tue Dec 06, 2016 11:25 am

Re: [ZScript]Refreshing custom ZScript Status Bar

Post by Cherno »

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
phantombeta
Posts: 2084
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: [ZScript]Refreshing custom ZScript Status Bar

Post by phantombeta »

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
Cherno
Posts: 1309
Joined: Tue Dec 06, 2016 11:25 am

Re: [ZScript]Refreshing custom ZScript Status Bar

Post by Cherno »

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
phantombeta
Posts: 2084
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: [ZScript]Refreshing custom ZScript Status Bar

Post by phantombeta »

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
Cherno
Posts: 1309
Joined: Tue Dec 06, 2016 11:25 am

Re: [ZScript]Refreshing custom ZScript Status Bar

Post by Cherno »

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 all

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
phantombeta
Posts: 2084
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: [ZScript]Refreshing custom ZScript Status Bar

Post by phantombeta »

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
Cherno
Posts: 1309
Joined: Tue Dec 06, 2016 11:25 am

Re: [ZScript]Refreshing custom ZScript Status Bar

Post by Cherno »

Thank you. That was the cause of my problem. Silly me just re-used the ACS syntac for the function.
Post Reply

Return to “Scripting”