Return type mismatch (modifying the max of an inv.item)

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Return type mismatch (modifying the max of an inv.item)

Post by wildweasel »

So, for the next version of Mixed Tape 3, I've been tinkering with the water-bottle system. Currently, the player can pick up water bottles until they've got 50 of them, and they may use their bottle from the inventory bar to instantly heal themselves for as many HP as the bottle currently carries. I'm working on modifying the system so that the player initially starts with a maximum of 10, but can gain 1 capacity for every armor bonus they pick up. Since there's no built-in way to do this, I'm trying to write my own system.

In theory, this code SHOULD work:

Code: Select all

ACTOR MaxWater : Inventory {} // Governs maximum water capacity.

ACTOR WaterFlask : CustomInventory replaces HealthBonus
{
	Inventory.Icon "FLSKICON"
	Inventory.InterHubAmount 0x7fffffff
	Inventory.MaxAmount 0x7fffffff
	Inventory.PickupMessage "Found some water."
	Tag "Water Bottle"
	Scale 0.65
	+INVENTORY.INVBAR
	+INVENTORY.UNDROPPABLE
	+INVENTORY.KEEPDEPLETED
	+INVENTORY.UNTOSSABLE
	States
	{
	Spawn:
		FLSK A -1
		Stop
	Pickup:
		TNT1 A 0 {
			if (CountInv("WaterFlask") == CountInv("MaxWater")) {
				return state("DontPickup");
			}
			else {
				A_GiveInventory("WaterFlask", 1);
			}
		}
		Stop
	DontPickup:
		TNT1 A 0 A_Print("Water bottle is full.")
		Fail
	Use:
		TNT1 A 0 A_JumpIf(health >= 100, "DontDrinkNoNoise")
	UseLoop:
		TNT1 A 0 A_JumpIf(health >= 100, "DontDrink")
		TNT1 A 0 A_TakeInventory("WaterFlask", 1)
		TNT1 A 0 A_GiveInventory("Health", 1)
		TNT1 A 0 A_JumpIfInventory("WaterFlask", 1, "UseLoop")
	FlaskEmpty:
		TNT1 A 0 A_PlaySound("water/drink", CHAN_ITEM)
		Fail
	DontDrink:
		TNT1 A 0 A_PlaySound("water/drink", CHAN_ITEM)
		Fail
	DontDrinkNoNoise:
		TNT1 A 0 A_Print("Can't drink water, health already full!")
		Fail
	}
}

ACTOR EmptyWaterFlask : CustomInventory
{
	Inventory.PickupMessage "Found an empty bottle - Water capacity increased."
	Scale 0.65
	States
	{
	Spawn:
		FLSK B -1
		Stop
	Pickup:
		TNT1 A 0 A_GiveInventory("MaxWater", 1)
		Stop
	}
}
But it halts ZDoom on startup with a "return type mismatch" error. Admittedly, I'm still new to the whole anonymous functions thing, but I've pored over what little of the section exists on the Wiki and haven't figured out what I'm doing wrong here. Any ideas? Alternatively, am I overcomplicating this? Is there a better way to handle this?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Return type mismatch (modifying the max of an inv.item)

Post by Graf Zahl »

Your function has two exits:

One returns a state, the other returns nothing. That's not allowed.
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Graphics Processor: nVidia with Vulkan support
Location: Maryland, US
Contact:

Re: Return type mismatch (modifying the max of an inv.item)

Post by Ed the Bat »

Finish your Pickup frame with return state(null);

Code: Select all

   Pickup:
      TNT1 A 0 {
         if (CountInv("WaterFlask") == CountInv("MaxWater")) {
            return state("DontPickup");
         }
         else {
            A_GiveInventory("WaterFlask", 1);
         }
	return state(null);
      }
      Stop
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: Return type mismatch (modifying the max of an inv.item)

Post by wildweasel »

Using this code:

Code: Select all

Pickup:
		TNT1 A 0 {
			if (CountInv("WaterFlask") == CountInv("MaxWater")) {
				return state("DontPickup");
			}
			else {
				A_GiveInventory("WaterFlask", 1);
			}
			return state(null);
		}
		Stop
I currently get "Unexpected token 'null'".
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Graphics Processor: nVidia with Vulkan support
Location: Maryland, US
Contact:

Re: Return type mismatch (modifying the max of an inv.item)

Post by Ed the Bat »

Silly me, you're still using DECORATE...
Does return state(""); still work in DECORATE?
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: Return type mismatch (modifying the max of an inv.item)

Post by wildweasel »

It doesn't give errors, but GZDoom now crashes on load.

[edit] Using GZDoom g2.3pre-927-gb709db3 64-bit from 2016-12-09, non-ZScript build.

[edit edit] It might help too if you have the project file - here's the version that crashes: https://dl.dropboxusercontent.com/u/766 ... borked.pk3
User avatar
Xaser
 
 
Posts: 10774
Joined: Sun Jul 20, 2003 12:15 pm
Contact:

Re: Return type mismatch (modifying the max of an inv.item)

Post by Xaser »

Bit of a guess at the moment, but try zero instead of the empty string. "return state(0);" is what I've used (successfully) in DECORATE-land.
Last edited by Xaser on Sun Dec 18, 2016 3:19 pm, edited 2 times in total.
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: Return type mismatch (modifying the max of an inv.item)

Post by wildweasel »

Xaser wrote:Bit of a guess at the moment, but try zero instead of the empty string. "return state(0);" is what I've used (successfully) in DECORATE-land.
Sadly, that still crashes GZDoom in the same way as soon as a map loads. If there's something else I've missed, feel free to look at my project file in the previous post.
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Graphics Processor: nVidia with Vulkan support
Location: Maryland, US
Contact:

Re: Return type mismatch (modifying the max of an inv.item)

Post by Ed the Bat »

I honestly just don't know what works in DECORATE; I abandoned it as soon as ZScript came out. I just know return state(""); USED to work but then it was changed.
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: Return type mismatch (modifying the max of an inv.item)

Post by wildweasel »

Ed the Bat wrote:I honestly just don't know what works in DECORATE; I abandoned it as soon as ZScript came out. I just know return state(""); USED to work but then it was changed.
In that case, the alternate question still stands: is there some better way I can handle this? As hesitant as I am to learn an entire new language to make this work (for a mod whose entire motto was "I wanted to make something new but didn't want to waste a lot of effort"), I'd be willing to dive in a little to make this work right.
User avatar
Xaser
 
 
Posts: 10774
Joined: Sun Jul 20, 2003 12:15 pm
Contact:

Re: Return type mismatch (modifying the max of an inv.item)

Post by Xaser »

If you're talking an outright crash (i.e. not a console abort or a startup error with a specific message), that's a thing to be reported as a bug. Even if there's something wrong in the decorate code, such crashes ought not happen. Perils of alpha software. :P
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Graphics Processor: nVidia with Vulkan support
Location: Maryland, US
Contact:

Re: Return type mismatch (modifying the max of an inv.item)

Post by Ed the Bat »

ZScript supports everything DECORATE can do, and aside from a few syntatical differences, it does them pretty much the same way. I wouldn't call it learning a new language, really.

Honestly, if this were me, I'd convert just this one actor to ZScript so I could do this in a way I know would work (minimum effort, right?) and called it a band-aid.
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: Return type mismatch (modifying the max of an inv.item)

Post by wildweasel »

Xaser wrote:If you're talking an outright crash (i.e. not a console abort or a startup error with a specific message), that's a thing to be reported as a bug. Even if there's something wrong in the decorate code, such crashes ought not happen. Perils of alpha software. :P
Yup, it's an outright crash:
Image

But I'm not able to discern at the moment if it's something I've done wrong (perhaps I've somehow created a busy loop in something's spawn state, I don't know!), which is why it'd be awful nice to have an extra set of eyes on this before I go waste Graf's time with a bug report that isn't a bug.
Ed the Bat wrote:ZScript supports everything DECORATE can do, and aside from a few syntatical differences, it does them pretty much the same way. I wouldn't call it learning a new language, really.

Honestly, if this were me, I'd convert just this one actor to ZScript so I could do this in a way I know would work (minimum effort, right?) and called it a band-aid.
In that case, any assistance whatsoever with getting this started would be welcomed. As I understand it, even the documentation for ZScript is heavily WIP, so I haven't the foggiest where to start.
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Graphics Processor: nVidia with Vulkan support
Location: Maryland, US
Contact:

Re: Return type mismatch (modifying the max of an inv.item)

Post by Ed the Bat »

Sorry to say, weasel, it looks like you might be right. I just converted the actor to ZScript, and it still causes the crash. I'd need to set aside some time to look it over, but as it stands, I gotta guess we have an infinite loop in here.
And, just for your reference, here's the actor in ZScript:
Spoiler:
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: Return type mismatch (modifying the max of an inv.item)

Post by wildweasel »

Total noob question, does ZScript belong in its own lump? =/
Locked

Return to “Editing (Archive)”