Page 1 of 1

Game crashes when executing an script from decorate

Posted: Wed Dec 07, 2016 7:56 pm
by Lord_of_D:
An icon is supposed to be shown on the hud displaying if the player has an item or not(This is so it can be shown too on chasecam mode), however when the player pickups an item that gives a random item which is supposed to be displayed on the hud the game freezes for a momment and then crashes, can somebody help me out?

Code: Select all

Actor RandomItem : Ammo 10000
{
	Radius 64
	Height 64
	Inventory.PickupMessage "You got a Random Item!"
	Inventory.PickupSound "ITEMBOX1"
	Inventory.Amount 1
	Inventory.MaxAmount 1
	+MOVEWITHSECTOR
	States
	{
	Spawn:
		ITEM ABCDEFGHIJKLMNOP 4 Bright
		Loop
	Pickup:
		TNT1 A 0
		Stop
	}
}


Actor Player : DoomPlayer
{
	...
	
	States
	{
	...
	Stay:
		...
		TNT1 A 0 A_JumpifInventory("RandomItem",1,"GiveItem")
		...
	GiveItem:
		TNT1 A 0 A_JumpifInventory("CheckItem",1,"Stay")
		TNT1 A 0 A_GiveInventory("CheckItem",1)
		TNT1 A 0 ACS_ExecuteAlways(602,0)
		Goto Stay

Code: Select all

#library "HUDICONS"
#include "zcommon.acs"

Script 600 Enter
{
		SetFont("ITMEMPTY");
		HudMessage(s:"A"; HUDMSG_Plain, PlayerNumber(), 0 , 0.5, 0.1, 0);
}

Script 601 (Void)
{
		SetFont("ITMEMPTY");
		HudMessage(s:"A"; HUDMSG_Plain, PlayerNumber(), 0 , 0.5, 0.1, 0);
}

Script 602 (void)
{
	int Check = Random(1,2);
	if(Check == 1){
		GiveInventory("GreenSkullAmmo",1);
		SetFont("ITMGSKUL");
		HudMessage(s:"A"; HUDMSG_Plain, PlayerNumber(), 0 , 0.5, 0.1, 0);
	}
	if(Check == 2){
		GiveInventory("RedSkullAmmo",1);
		SetFont("ITMRSKUL");
		HudMessage(s:"A"; HUDMSG_Plain, PlayerNumber(), 0 , 0.5, 0.1, 0);
	}

}

Re: Game crashes when executing an script from decorate

Posted: Wed Dec 07, 2016 8:13 pm
by Ænima
The ACS looks fine.

Is there a zero-tic infinite loop in the "Stay:" state? I can't tell because you didn't post the full code.

Re: Game crashes when executing an script from decorate

Posted: Wed Dec 07, 2016 8:59 pm
by Lord_of_D:
Ænima wrote:The ACS looks fine.

Is there a zero-tic infinite loop in the "Stay:" state? I can't tell because you didn't post the full code.
there isnt, theres a single state of "1", everything else are multiple states that play a sound or jump to another state, but the jump to GiveItem is almost at the beginning of the state, maybe thats what causing this crash:

Code: Select all

Stay:
		DSLY A 0 Healthing(100)
		TNT1 A 0 A_JumpifInventory("RandomItem",1,"GiveItem")
		TNT1 A 0 A_TakeInventory("BikeSpeed", 1)
		TNT1 A 0 A_JumpIfInventory("TurnLeft", 1, "TurnLeft")
		TNT1 A 0 A_JumpIfInventory("TurnRight", 1, "TurnRight")
		TNT1 A 0 A_JumpIfInventory("BackPedal", 1, "BackPedal")
		TNT1 A 0 A_JumpIfInventory("Turbo", 1, "Accelerate")
		TNT1 A 0 A_JumpIfInventory("Accelerate", 1, "Accelerate")
		DSLY A 1 SetPlayerProperty(1,1,4)
		TNT1 A 0 A_JumpIfInventory("TurnLeft", 1, "TurnLeft")
		TNT1 A 0 A_JumpIfInventory("TurnRight", 1, "TurnRight")
		TNT1 A 0 A_JumpIfInventory("BackPedal", 1, "BackPedal")
		TNT1 A 0 A_TakeInventory("MaxLeft", 1)
		TNT1 A 0 A_TakeInventory("MaxRight", 1)
		TNT1 A 0 A_JumpIfInventory("Accelerate", 1, "Accelerate")
		TNT1 A 0 A_PlaySound("KARTEFF1", 2, 1, 1)
		TNT1 A 0 A_TakeInventory("MaxLeft", 1)
		TNT1 A 0 A_TakeInventory("MaxRight", 1)
		Loop
edit: nope, it still crashes

Re: Game crashes when executing an script from decorate

Posted: Wed Dec 07, 2016 9:51 pm
by Combinebobnt
What is the state of "CheckItem" before all of this? If it is already 1 such as when I guess you pick up 2 items, the two states will just loop back and forth forever. Make sure it gets taken/reset properly or whatever.

nice karts

Re: Game crashes when executing an script from decorate

Posted: Wed Dec 07, 2016 10:12 pm
by Lord_of_D:
Combinebobnt wrote:What is the state of "CheckItem" before all of this? If it is already 1 such as when I guess you pick up 2 items, the two states will just loop back and forth forever. Make sure it gets taken/reset properly or whatever.
the "CheckItem" is just an inventory item that that im using to prevent that, and the max amount a player can have is 1, so the "2 items" problem wont happen, also i have in mind to discard the "CheckItem" once the weapon is used.

Code: Select all

Actor CheckItem : Inventory
{
	Inventory.MaxAmount 1
}

Re: Game crashes when executing an script from decorate

Posted: Wed Dec 07, 2016 11:06 pm
by Combinebobnt
You misunderstood "2 items"; I mean that the first time you pick up the item, checkitem has a value of 1. The next time you pick it up, both a_jumps will trigger and there is an infinite loop (from what I can tell). Yes you definitely want to take it away or write the code different or whatever