Page 1 of 1

[ZScript]Refreshing custom ZScript Status Bar (Solved)

Posted: Mon Oct 08, 2018 8:00 pm
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? :)

Re: [ZScript]Refreshing custom ZScript Status Bar

Posted: Mon Oct 08, 2018 10:33 pm
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 ();
		}
	}

Re: [ZScript]Refreshing custom ZScript Status Bar

Posted: Tue Oct 09, 2018 6:34 am
by Cherno
Yes, you are right. Anyway, when is Draw() called and how can I solve my problem? :3:

Re: [ZScript]Refreshing custom ZScript Status Bar

Posted: Tue Oct 09, 2018 6:04 pm
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);
               
                //...
	}

Re: [ZScript]Refreshing custom ZScript Status Bar

Posted: Thu Oct 11, 2018 10:48 am
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?!?

Re: [ZScript]Refreshing custom ZScript Status Bar

Posted: Thu Oct 11, 2018 10:53 am
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.

Re: [ZScript]Refreshing custom ZScript Status Bar

Posted: Thu Oct 11, 2018 11:54 am
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 :)

Re: [ZScript]Refreshing custom ZScript Status Bar

Posted: Thu Oct 11, 2018 4:28 pm
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.

Re: [ZScript]Refreshing custom ZScript Status Bar

Posted: Thu Oct 11, 2018 5:11 pm
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
}

Re: [ZScript]Refreshing custom ZScript Status Bar

Posted: Thu Oct 11, 2018 5:28 pm
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.

Re: [ZScript]Refreshing custom ZScript Status Bar

Posted: Thu Oct 11, 2018 7:18 pm
by Cherno
Thank you. That was the cause of my problem. Silly me just re-used the ACS syntac for the function.