Trying to Read from Address Zero.

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

Trying to Read from Address Zero.

Post by SellDemApplez »

As it says in the title, the script I have throws the error of trying to read from address zero. The code is below. If there is a need for more, ask below and I will send it as soon as possible!

Code: Select all


//The Hud I am accessing the ShieldItem Var from

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; //error is located here from what the logs have told me.
	}



	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";
	
	}

}




Code: Select all

//The Inventory Class that contains the hasUsedShield variable..

class ShieldItem : CustomInventory {

	bool hasUsedShield;
	property hasUsedShield : hasUsedShield;

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


}
User avatar
phantombeta
Posts: 2162
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: Trying to Read from Address Zero.

Post by phantombeta »

Not a bug. You never assign a non-null value to shield, that means it's always null when you try to access it, which causes an error. (Because you're trying to access something that doesn't exist)
I would recommend reading the ZScript Basics guide.
SellDemApplez
Posts: 5
Joined: Sun Jun 01, 2025 2:41 pm
Preferred Pronouns: He/Him

Re: Trying to Read from Address Zero.

Post by SellDemApplez »

phantombeta wrote: Fri Jun 20, 2025 7:06 pm Not a bug. You never assign a non-null value to shield, that means it's always null when you try to access it, which causes an error. (Because you're trying to access something that doesn't exist)
I would recommend reading the ZScript Basics guide.
Alright, If I may ask: Where exactly would I define the variable? Trying to do so in the HUD throws an error, and I cannot define it in DEFAULT either due to being only able to define property values in it. Again, apologize if I am being an idiot.
User avatar
danatationn
Posts: 5
Joined: Sun Jun 15, 2025 12:34 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Arch Linux
Graphics Processor: nVidia (Modern GZDoom)
Contact:

Re: Trying to Read from Address Zero.

Post by danatationn »

try assigning values to the variables in Init() . you defined them correctly outside of init but you need to actually give them a value too afterwards

do something like FindInventory on CPlayer to get a pointer to the shield, and only then can you access info from it
Post Reply

Return to “Scripting”