[ACS] Division by Zero Issue

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
Korni27
Posts: 46
Joined: Sun Jan 31, 2021 9:18 am
Preferred Pronouns: No Preference
Operating System Version (Optional): Windows 10
Location: Poland
Contact:

[ACS] Division by Zero Issue

Post by Korni27 »

I have this custom Horde Mode script that spawns in monsters but during testing, in the later waves (Around 1 to 2 hours in) it crashes with the message "Division by Zero". I went on the TSPG discord server (as that's where I hosted the server), asked around, and just got that all the crashes happened during the monster spawning wave and that I should check the thing inside the waves, but after doing so, I have no clue of what can be causing such an error, so I came here for help

So if anybody wants to help me, it would be greatly appreciated

The main Script responsible for wave control and text display

Code: Select all

ACS_NamedExecute("HD_SpawningFunction",0);
			Until(EnemyCounter == 0) //wait untill zero
			{
				delay(1);
				SetFont("BIGFONT");
				SetHudSize(520, 400,0);
				HudMessage(s:"Wave ", i:waves , s:": " , i:EnemyCounter, s:" Demons Left!" ; HUDMSG_PLAIN, 0, CR_GOLD, 260.4, 80.4, 0.1);

				If(DerailerBools[2] == TRUE) //Derailers appear in late-game waves, but the game crashed even before them so they are not the issue, plus they work fine
				{
					if(HALFLIFEDERAILERRANDOMPOINT == EnemyCounter)
					{
						For(int n = 0; n < 16; n++) //goes through all the players, I though this could be an issue, but the game crashes even when this is FLASE
						{
							SetActorProperty(1000+n,APROP_Health,GetActorProperty(1000+n,APROP_Health)/2);
							FadeTo(0.1,0.0,0.0,0.5,0.0);
							FadeTo(0.1,0.0,0.0,0.0,2.0);
							HALFLIFEDERAILERRANDOMPOINT = -1;
						}
						SectorSound("derailer/powerdown",1.0);
					}
				}

				If(DerailerBools[0] == TRUE) //Same deal as before
				{
					if(HALFLIFEDERAILERRANDOMPOINT == EnemyCounter)
					{
						For(int m = 0; m < 16; m++)
						{
							TakeActorInventory(1000+m,"Clip",CheckActorInventory(1000+m,"Clip") / 2);
							TakeActorInventory(1000+m,"Shell",CheckActorInventory(1000+m,"Shell") / 2);
							TakeActorInventory(1000+m,"RocketAmmo",CheckActorInventory(1000+m,"RocketAmmo") / 2);
							TakeActorInventory(1000+m,"Cell",CheckActorInventory(1000+m,"Cell") / 2);
							TakeActorInventory(1000+m,"RocketFuel",CheckActorInventory(1000+m,"RocketFuel") / 2);
							TakeActorInventory(1000+m,"Skulls",CheckActorInventory(1000+m,"Skulls") / 2);
						}
						FadeTo(0.1,0.0,0.0,0.5,0.0);
						FadeTo(0.1,0.0,0.0,0.0,2.0);
						HALFLIFEDERAILERRANDOMPOINT = -1;
					}
					SectorSound("derailer/powerdown",1.0);
				}

				if(AmountOfDeadlayers == PlayerCount())
				{
					GameOver = TRUE;
				}
			}
			Thing_Remove(600); //Remove Monsters
			ACS_NamedTerminate("HD_SpawningFunction",0); //Make sure the function is gone
			Break;
and Here is the function where the monsters spawn, and give cash to the killer

Code: Select all

Script "HD_SpawningFunction" (VOID)
{
	If(Waves < 30)
	{
		Delay((70 + Random(0,15)) - Waves);
	}
	else
	{
		Delay((70 + Random(1,3)) - Waves);
	}

	if(EnemyCounter != ThingCount(T_NONE,600) && ThingCount(T_NONE,600) < PrevEnemyCount) //Function spawn the exact amounts of monsters needed for the wave, calculated before hand
	{
		int spot = random(100,111);
		If(SpawnSpotFacing(Monster_List[random(MonsterMinTier,MonsterTier)],spot,600)) //Check if a monster is spawnable in tat place (this is what I suspect could be causing it)
		{
			SpawnSpotFacing("TeleportFog",spot,0);
			SetThingSpecial(600,80,90,0,GetActorProperty(0,APROP_SpawnHealth),0,0); //Suplies their kill script with their health

			If(DerailerBools[1] == TRUE)
			{
				SetActorProperty(600,APROP_Reactiontime,0); //Again, game crashes before this is even activated plus it works fine
			}

			If(DerailerBools[6] == TRUE)
			{
						Thing_Hate(600,StatuePlayerTID,2); //Again, game crashes before this is even activated plus it works fine
			}

			if(EnemyCurrentCounter < ThingCount(T_NONE,600))
			{
				EnemyCurrentCounter++;
			}
			else if(EnemyCurrentCounter > ThingCount(T_NONE,600))
			{
				EnemyCurrentCounter = ThingCount(T_NONE,600);
			}
		}
	}
	If(EnemyCurrentCounter == PrevEnemyCount)
	{
		Suspend;
	}

	Restart;
}

Script 90 (int MonsterHealth)
{
	EnemyCounter--;
	For(int i = 0;i < 16;i++)
	{
		GiveActorInventory(1000+i,"HordeMode_Points",(MonsterHealth + 10 + Waves * GameSkill() * 5 + Random(0,32)) - PlayerCount() * 2); //Maybe, but then again, no division plus nothing came up when tested
	}
}[\code]

if anybody can help, it would be much appreciated, thanks in advance
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: [ACS] Division by Zero Issue

Post by Player701 »

I do not see any division operations in your code where the divisor may be zero. Besides, the game should not crash if such a division happens in script code, but instead print a warning message and terminate the script.

Are you sure that the issue is caused by these particular scripts and not by some other one? Or, for that matter, that it is an ACS issue in the first place?

In any case, showing us the entire ACS code might shed a bit more light on this, but if you're getting a hard crash instead of a simple warning, then it's not very likely. In this case, you should attempt to create a small, self-contained example mod which reproduces the issue, and send it to the developers along with a bug report.
Post Reply

Return to “Scripting”