A_JumpIfInTargetInventory problem

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
OrinTheDoom
Posts: 3
Joined: Sat Nov 10, 2018 3:59 am

A_JumpIfInTargetInventory problem

Post by OrinTheDoom »

I have a piece of code where a player is given or taken away Inventory item "Stl", depending on player's light level.

Code: Select all

script "LightCheck" enter
{
  while (true)
  {
    if (GetActorLightLevel(0) <= 96)
	{
		GiveInventory("Stl", 1);
	    SetActorProperty(0, APROP_RENDERSTYLE, STYLE_ADD);
	    print(f: CheckInventory("Stl")); //Gives 1.52...
	}
    else 
	{
	    TakeInventory("Stl", 1);
	    SetActorProperty(0, APROP_RENDERSTYLE, STYLE_NORMAL);
	    print(f: CheckInventory("Stl")); //Gives 0
	}
	delay(1);
  }
}
//Seems to work fine
However, when I use A_JumpIfInTargetInventory(), odd bug occurs.

Code: Select all

States
  {
  Spawn:
	POSS AB 0 A_GiveInventory("StKill", 1) //Not important in this case
	Goto Idle
  Idle:
	POSS AB 0 A_JumpIfInTargetInventory("Stl", 1, "DarkIdle")
	POSS AB 10 A_Look
	Loop
  DarkIdle:
	POSS AB 0 A_JumpIfInTargetInventory("Stl", 0, "Death")
	POSS AB 10 A_LookEx(0, 0, 192)
	Loop
  See:
	POSS AABBCCDD 0 A_TakeInventory("StKill", 1) //Also not important
	POSS AABBCCDD 0 A_JumpIfInTargetInventory("Stl", 1, "DarkSee")
	POSS AABBCCDD 3 A_Chase
	Loop
  DarkSee:
	POSS AABBCCDD 0 A_JumpIfInTargetInventory("Stl", 0, "See") //It automatically goes to "See" state, even though "Stl" = 1
	POSS AABBCCDD 3 A_Chase
	POSS AABBCCDD 0 A_JumpIfTargetInLOS("Search", 0, 0, 0, 768)
	Loop
  Search:
	POSS AABBCCDD 0 A_ClearTarget
	POSS AABBCCDD 0 A_JumpIfInTargetInventory("Stl", 1, "DarkSearch")
	POSS AABBCCDD 3 A_Wander
	POSS AB 10 A_Look
	Loop
  DarkSearch:
	POSS AABBCCDD 0 A_JumpIfInTargetInventory("Stl", 0, "Search")
	POSS AABBCCDD 3 A_Wander
	POSS AB 10 A_LookEx(0, 0, 192)
	Loop
When I alert the monster, it runs "See" state normally, but as soon as I enter the dark area (where is supposed to be "Stl" = 1 and jump to "DarkSee"), the "DarkSee" state automatically jumps back to "See" state, as if "Stl" = 0 and causes the game to overload and crash. I have figured that out by putting "Death" state instead of "See" state.
What could be the cause of the problem?
Blue Shadow
Posts: 5043
Joined: Sun Nov 14, 2010 12:59 am

Re: A_JumpIfInTargetInventory problem

Post by Blue Shadow »

[wiki=A_JumpIfInventory]From the wiki[/wiki]:
Note that if amount is 0, the jump is only performed if the actor is carrying the maximum number of that item. This is useful for checking whether the player has the maximum amount of ammo for a particular weapon, regardless of whether or not he's found a backpack.
OrinTheDoom
Posts: 3
Joined: Sat Nov 10, 2018 3:59 am

Re: A_JumpIfInTargetInventory problem

Post by OrinTheDoom »

Well, seems like I've missed that one out XD thanks a lot!
Blue Shadow
Posts: 5043
Joined: Sun Nov 14, 2010 12:59 am

Re: A_JumpIfInTargetInventory problem

Post by Blue Shadow »

Understandably, since that bit of info isn't included in the A_JumpIfInTargetInventory page.
OrinTheDoom
Posts: 3
Joined: Sat Nov 10, 2018 3:59 am

Re: A_JumpIfInTargetInventory problem

Post by OrinTheDoom »

UPDATE:
Meanwhile, i've figured out the problem; the part where it checks for amount - it doesn't check the exact amount (if you have 2, then you also have 1 of the item).

Code: Select all

script "LightCheck" enter
{
  GiveInventory("Stl", 1);
  while (true)
  {
    if (GetActorLightLevel(0) <= 96)
	{
		if (CheckInventory("Stl") < 2) GiveInventory("Stl", 1);
	    SetActorProperty(0, APROP_RENDERSTYLE, STYLE_ADD);
	    print(f: CheckInventory("Stl"));
	}
    else 
	{
		if (CheckInventory("Stl") > 1) TakeInventory("Stl", 1);
	    SetActorProperty(0, APROP_RENDERSTYLE, STYLE_NORMAL);
	    print(f: CheckInventory("Stl"));
	}
	delay(1);
  }
}

Code: Select all

ACTOR Stl : Inventory
{
  Inventory.MaxAmount 2
}

Code: Select all

States
  {
  Spawn:
    POSS AB 0 A_GiveInventory("StKill", 1)
	Goto Idle
  Idle:
	POSS AB 0 A_JumpIfInTargetInventory("Stl", 2, "DarkIdle")
    POSS AB 10 A_Look
	Loop
  DarkIdle:
	POSS AB 0 A_JumpIfInTargetInventory("Stl", 1, "Idle")
    POSS AB 10 A_LookEx(0, 0, 192)
	Loop
  See:
    POSS AABBCCDD 0 A_TakeInventory("StKill", 1)
    POSS AABBCCDD 0 A_JumpIfInTargetInventory("Stl", 2, "DarkSee")
    POSS AABBCCDD 3 A_Chase
    Loop
  DarkSee:
    POSS AABBCCDD 0 A_JumpIfInTargetInventory("Stl", 1, "See")
    POSS AABBCCDD 3 A_Chase
	POSS AABBCCDD 0 A_JumpIfTargetInLOS("Search", 0, 0, 0, 768)
	Loop
  Search:
    POSS AABBCCDD 0 A_ClearTarget
    POSS AABBCCDD 0 A_JumpIfInTargetInventory("Stl", 2, "DarkSearch")
    POSS AABBCCDD 3 A_Wander
	POSS AB 10 A_Look
	Loop
  DarkSearch:
    POSS AABBCCDD 0 A_JumpIfInTargetInventory("Stl", 1, "Search")
    POSS AABBCCDD 3 A_Wander
	POSS AB 10 A_LookEx(0, 0, 192)
	Loop
and, unfortunately, still doing the same bug :(
Post Reply

Return to “Scripting”