Issue when acessing a variable from another class

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
SellDemApplez
Posts: 5
Joined: Sun Jun 01, 2025 2:41 pm
Preferred Pronouns: He/Him

Issue when acessing a variable from another class

Post by SellDemApplez »

Hello! As the title says, whenever I try to access a variable from another class, the error is thrown saying that it "is reading at address zero". here is the code, am I doing something wrong?

The Class I am trying to access the variable

Code: Select all

class MyStandaloneGameHUD : BaseStatusBar

{
	HUDFont mHUDFont;

	SendirPlayer pmo;
	ShieldItem shield;
	bool shieldStatus;
	override void Init(void)

	{
		Super.Init();
		SetSize(0, 320, 200);
		Font fnt = SmallFont;
		mHUDFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), Mono_CellLeft, 1, 1);
		Self.shieldStatus = shield.hasUsedShield;
	}



	override void Draw(int state, double TicFrac)

	{
		if (CPlayer && CPlayer.mo)
		{
			pmo = SendirPlayer(CPlayer.mo);
		}
		
		BaseStatusBar.Draw(state, TicFrac);
		if (state == HUD_StatusBar || state == HUD_Fullscreen)
		{
			BeginHUD(forcescaled: true);
			DrawHUD();
		}
	}
	void DrawHUD()
	{
		
		//DrawBar("barfull","barblank",pmo.player.health,100,(99, -20),0,SHADER_VERT,
			//DI_ITEM_CENTER | DI_SCREEN_LEFT_BOTTOM );
		DrawString(mHUDFont, StringTable.Localize("$TXT_HUD_HEALTH") .. FormatNumber(pmo.player.health, 3), (22, -30));
		DrawString(mHUDFont, StringTable.Localize("RAGE:") .. FormatNumber(pmo.rage, 3), (22, -20));
		DrawString(mHUDFont, StringTable.Localize("Arcane Shells:").. pmo.CountInv("Shell") , (260, -20)); //.. CheckInventory("Shell")
		DrawString(mHUDFont, StringTable.Localize("Shield:").. getShieldStatus() , (260, -20)); 
	}
	String getShieldStatus()
	{
	if (!shieldStatus) return "Ready!";
	else return "Not Ready";
	
	}

}
The class that has said variable

Code: Select all

class ShieldItem : CustomInventory {

	bool hasUsedShield;
	property hasUsedShield : hasUsedShield;

Default {
	Inventory.PickupMessage "Picked up the Shield!";
	Inventory.Amount 1;
	Inventory.DefMaxAmount 1;
	
	Self.hasUsedShield false;
	
}


}
Post Reply

Return to “Scripting”