"How do I ZScript?"

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!)
Locked
Pink Baron
Posts: 33
Joined: Wed Mar 16, 2016 4:19 pm

Re: "How do I ZScript?"

Post by Pink Baron »

Hi all!

I'm looking for the usage of map stats from LevelLocals global variable, but I don't figure out how to use them.
For istance, I looked both on Wiki and GZdoom itself (base.txt), and compiled this sample code on a PlayerPawn's tick function. It won't log. Ever. Why?

Code: Select all

Virtual void MyMapStatsManager ()
{
	LevelLocals p;
	
	If (p)
	{
		Int TotalMonsters = p.total_monsters;
		A_LogInt (TotalMonsters);   // Desidered result
	}
	Else {A_Log ("You suck!");}	 // Actual result .-.
}
User avatar
AFADoomer
Posts: 1342
Joined: Tue Jul 15, 2003 4:18 pm
Contact:

Re: "How do I ZScript?"

Post by AFADoomer »

I think you want to reference 'level' (declared here) instead of declaring 'LevelLocals p'.

What you are doing, instead of using the actual level info, is declaring a new object 'p' that is of struct type LevelLocals. When you check 'if (p)', it's declared and is present, despite every value being uninitialized, so that logic succeeds, but since p.total_monsters has no value, you are most likely logging an empty line.

Just referencing 'level.total_monsters' as a variable should work... Something like this should print the value:

Code: Select all

Virtual void MyMapStatsManager ()
{
      console.printf("%d", level.total_monsters);
}
User avatar
Jekyll Grim Payne
Global Moderator
Posts: 1118
Joined: Mon Jul 21, 2008 4:08 am
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)
Contact:

Re: "How do I ZScript?"

Post by Jekyll Grim Payne »

Guys, I don't want to go for the lamest quesitons, but seriously, where do I start from if I don't understand Zscript structure and logic at all, and DECORATE is the only scripting language I've ever mastered while everything else, including C, is completely beyond me? 'Cause at the moment I'm honestly feeling like Doom modding is coming to an end for me.
Pink Baron
Posts: 33
Joined: Wed Mar 16, 2016 4:19 pm

Re: "How do I ZScript?"

Post by Pink Baron »

AFADoomer wrote:I think you want to reference 'level' (declared here) instead of declaring 'LevelLocals p'.

What you are doing, instead of using the actual level info, is declaring a new object 'p' that is of struct type LevelLocals. When you check 'if (p)', it's declared and is present, despite every value being uninitialized, so that logic succeeds, but since p.total_monsters has no value, you are most likely logging an empty line.

Just referencing 'level.total_monsters' as a variable should work... Something like this should print the value:

Code: Select all

Virtual void MyMapStatsManager ()
{
      console.printf("%d", level.total_monsters);
}
It worked, thanks! :D

P.S. Thus, I simply had to access "levels" direcly without resorting to "let", aliases, auto or anything else shown either on Wiki or Gzdoom internal files (I even tried with "levels p", but it gave me obiously an error). Seriously, it's like finding the secret door in Milon's Secret Castle...how was I supposed to know that?!?!
Mini rant aside, thank you for the info: whenever I use that code for a mod, I'll comment it so that other users won't get stuck as much as I did.

@ Jekyll Grim Payne: As I'm currently in process to convert my mod to ZScript, I'm pretty much on the same boat. It's really, really hard to understand, but not impossible and gives several dividends. Start by studying other ZScript based mods, such as D4D, and/or converting your DECORATE files as/is for an headstart. Then, read some C+ programming tutorials as it's very similar to ZScript. After that, if you still get halted, ask here for some answers.
User avatar
Nash
 
 
Posts: 17500
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: "How do I ZScript?"

Post by Nash »

Pink Baron wrote:Seriously, it's like finding the secret door in Milon's Secret Castle...how was I supposed to know that?!?!
It's listed under the global variables section of the wiki. https://zdoom.org/wiki/ZScript_global_variables
User avatar
Ghost Prototype
Posts: 185
Joined: Sun May 19, 2013 12:22 pm
Location: Philadelphia

Re: "How do I ZScript?"

Post by Ghost Prototype »

Is there a way to change where the pickupmessage is shown on the hud and what kind of font it uses?
User avatar
Jimmy
 
 
Posts: 4726
Joined: Mon Apr 10, 2006 1:49 pm
Preferred Pronouns: He/Him
Contact:

Re: "How do I ZScript?"

Post by Jimmy »

Changing to a specific map with ZScript.

How do?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49234
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: "How do I ZScript?"

Post by Graf Zahl »

Teleport_NewMap - just like ACS.
User avatar
Accensus
Banned User
Posts: 2383
Joined: Thu Feb 11, 2016 9:59 am

Re: "How do I ZScript?"

Post by Accensus »

Code: Select all

let PowerItem = Powerup(CPlayer.mo.FindInventory("PowerQuadDamage"));
PowerupTime = PowerItem.EffectTics;
MaxPowerupTime = ???; //What to put here?

DrawBar("PWRBRON", "PWRBROFF", PowerupTime, 1000, (-94, 28), 0, 0, TOP_RIGHT_MODULE); //Ignore flag, it's custom.
So I have this ZScript HUD code, and my question is this: how to determine what the maximum time for the powerup is upon picking it up? I'm looking for a way to mimic poweruptime from SBARINFO, but so far I've only worked out half of the puzzle.
Blue Shadow
Posts: 5043
Joined: Sun Nov 14, 2010 12:59 am

Re: "How do I ZScript?"

Post by Blue Shadow »

There is a PlayerPawn method which is called GetEffectTicsForItem. It returns the current and max (default) effect tics.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: "How do I ZScript?"

Post by Matt »

Graf Zahl wrote:Teleport_NewMap - just like ACS.
So just level numbers only then, no names? :( (and no way to get, say, level.nextmap?)

EDIT: Next map, of course, could just use Exit_Normal.

Which combined with levellocals manipulation means this can be used to replay a map:

Code: Select all

level.nextmap=level.mapname;
Exit_Normal(0);
Last edited by Matt on Sat Jul 22, 2017 12:53 am, edited 1 time in total.
User avatar
Accensus
Banned User
Posts: 2383
Joined: Thu Feb 11, 2016 9:59 am

Re: "How do I ZScript?"

Post by Accensus »

Blue Shadow wrote:There is a PlayerPawn method which is called GetEffectTicsForItem. It returns the current and max (default) effect tics.
Works perfectly. Thank you, Blue Shadow.
User avatar
Rip and Tear
Posts: 187
Joined: Tue May 02, 2017 3:54 pm

Re: "How do I ZScript?"

Post by Rip and Tear »

What is the correct way to return and jump from an anonymous function in ZScript?

Code: Select all

TNT1 A 0 {
  if(foo) {
    return ResolveState("Spawn");
  }
}

Script error, Return type mismatch
User avatar
Gutawer
Posts: 469
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

Re: "How do I ZScript?"

Post by Gutawer »

You're doing it correctly, problem is, you need to return something outside of the if block in case foo is false - if you want no jump, you should use return ResolveState(null);. Otherwise it returns void which is not a State - by putting return ResolveState(<whatever>); anywhere in an anonymous function, it treats it as if it returns a State.
User avatar
Major Cooke
Posts: 8209
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

Re: "How do I ZScript?"

Post by Major Cooke »

Vaecrius wrote:1. How do I set up an inventory item that does not inherit from Weapon or Ammo (or a key) so that it would be given with ID(K)FA?


2. Is there a way to override or somehow get around an Ammo item's get-parent function so that you can have something like:

MyAmmo0:Ammo
MyAmmo1:MyAmmo0
MyAmmo2:MyAmmo0

in which MyAmmo1 and MyAmmo2 are distinct items?
1. You will need to override the player's give cheat virtual.

2. I don't follow... Can you elaborate?

Also, there's currently no way to rotate sprites on the screen when dealing with hud elements. Gotta wait for Graf on that one.
Locked

Return to “Scripting”