[SOLVED] [ZScript] "Unable to resolve str as type" in custom HUD

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
MFG38
Posts: 414
Joined: Sun Apr 14, 2019 8:26 am
Graphics Processor: nVidia (Modern GZDoom)
Location: Finland
Contact:

[SOLVED] [ZScript] "Unable to resolve str as type" in custom HUD

Post by MFG38 »

Over the past few days, I've been rewriting the HUD from a gameplay mod of mine from SBARINFO to ZScript. With it being almost finished, the time came to test the thing and see how it looks in-game. Excitedly, I slapped the .pk3 into ZDL and clicked the Play button, but instead of the game booting up, I got messages about 10 errors, which I was able to fix pretty quickly (they were all related to similar functions). So afterwards, I recompile the .pk3, add it into ZDL and click the Play button again - and now an entirely different error pops up, saying the following:
sgd_v20-pre-r405.pk3:zscript/hud.txt, line 45: Unable to resolve str as type.
Now, what's curious to me is that the error in question did not pop up in the log file until I fixed the previous errors. I tried to look for information about it but came across none, so I was hoping someone more intelligent than myself would be able to look at the code and tell me what's wrong with it.

Entire code for the HUD is in the spoiler below.
Spoiler:
Last edited by MFG38 on Sun Dec 04, 2022 12:16 am, edited 1 time in total.
User avatar
phantombeta
Posts: 2084
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: [ZScript] "Unable to resolve str as type" in custom HUD

Post by phantombeta »

There's no type str, the string type in ZScript is String. Replace str with String and it should work, as long as there aren't any other errors.
User avatar
MFG38
Posts: 414
Joined: Sun Apr 14, 2019 8:26 am
Graphics Processor: nVidia (Modern GZDoom)
Location: Finland
Contact:

Re: [ZScript] "Unable to resolve str as type" in custom HUD

Post by MFG38 »

phantombeta wrote: Fri Dec 02, 2022 5:16 pm There's no type str, the string type in ZScript is String. Replace str with String and it should work, as long as there aren't any other errors.
Well, doing that seems to have fixed the type-resolution issue, but now I'm getting two other errors:
Script error, "sgd_v20-pre-r410.pk3:zscript/hud.txt" line 47:
Unknown identifier 'ReadyWeapon'
Script error, "sgd_v20-pre-r410.pk3:zscript/hud.txt" line 50:
Unknown identifier 'selweap'
I haven't even changed the code that much between attempts to rectify the problem - a couple other errors did pop up in between (related to play-scope functions used in the ui context and a VM abort when picking up a weapon with no ammo) but those were quickly fixed. My current code in the DrawWeaponsAndAmmo() function is almost identical to the one in the OP except for String instead of str and an ammo != null check added to the ammo count's DrawString call. Like what else could possibly be wrong at this point?

The more I try to think about and fix the issues I'm having here, the less fond I grow of ZScript.

EDIT: Okay, I searched around for a tiny bit for possible solutions and came across one that I hope will do the trick. I'll report back when I get around to trying it out.
User avatar
MFG38
Posts: 414
Joined: Sun Apr 14, 2019 8:26 am
Graphics Processor: nVidia (Modern GZDoom)
Location: Finland
Contact:

Re: [ZScript] "Unable to resolve str as type" in custom HUD

Post by MFG38 »

Well. I'm officially out of ideas. I tried Player701's idea of a static function from here, it produced an error, tried giving all the weapons inventory icons and getting them directly with GetInventoryIcon(), it produced an error, tried fiddling around with my previous implementation as much as I could without breaking it further, every single attempt produced an error.

Somebody please come up with a fix. I want to get a new version of this mod out before the end of the year and I'm this close to having it completed. I can't release it in a state where it refuses to even load because of a pesky-ass fucking error that no fix I've attempted has worked for.

Code's in the spoiler below.
Spoiler:
Jarewill
 
 
Posts: 1759
Joined: Sun Jul 21, 2019 8:54 am

Re: [ZScript] "Unable to resolve str as type" in custom HUD

Post by Jarewill »

It would be handy if you could upload your current project here.

For the snippet of code you provided, this change seemed to make it run:

Code: Select all

        // Line below is producing the latest error ("cannot convert to string").
        // DrawImage(GetInventoryIcon(CPlayer.ReadyWeapon,ITYPE_WEAPON),(278,192),DI_ITEM_OFFSETS);
		DrawInventoryIcon(CPlayer.ReadyWeapon,(278,192),DI_ITEM_OFFSETS);
However I also ripped out a lot of functions and other things just to make it run because I lacked proper assets.
If this doesn't fix it then please upload your entire project here so I can take a look without needing to rip a lot of code out.
User avatar
MFG38
Posts: 414
Joined: Sun Apr 14, 2019 8:26 am
Graphics Processor: nVidia (Modern GZDoom)
Location: Finland
Contact:

Re: [ZScript] "Unable to resolve str as type" in custom HUD

Post by MFG38 »

Jarewill wrote: Sat Dec 03, 2022 2:58 pm For the snippet of code you provided, this change seemed to make it run:

Code: Select all

        // Line below is producing the latest error ("cannot convert to string").
        // DrawImage(GetInventoryIcon(CPlayer.ReadyWeapon,ITYPE_WEAPON),(278,192),DI_ITEM_OFFSETS);
		DrawInventoryIcon(CPlayer.ReadyWeapon,(278,192),DI_ITEM_OFFSETS);
...It really was that simple. :bang: :bang: :bang: :bang: :bang: :bang:

I spent three days wracking my brain with this shit and this simple change is the one that finally works. I was trying to overcomplicate the method and drove myself insane in the process. I feel embarrassed.

Anyway, help's appreciated.
Post Reply

Return to “Scripting”