"How do I ZScript?"

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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!)
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: "How do I ZScript?"

Post by ZZYZX »

Organizational. It's for structures that don't have specific scope and just contain data.
User avatar
Nash
 
 
Posts: 17506
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: "How do I ZScript?"

Post by Nash »

Thanks for the documentation ZZYZX. Just by reading it 1 pass, it already explains a lot. Going to have to read it a few more times in addition to writing code, but the fact that there's reference is already a huge help. Thanks again.
User avatar
Jimmy
 
 
Posts: 4728
Joined: Mon Apr 10, 2006 1:49 pm
Preferred Pronouns: He/Him

Re: "How do I ZScript?"

Post by Jimmy »

Major Cooke wrote:
Jimmy wrote:Can I use ZScript's menu system to:

(1) Change music in-game, i.e. with SetMusic;
(2) Load a menu with options generated from a global ACS array;
(3) Have the menu not pause gameplay;
(4) Perform actions like swapping the menu options' position and changing the contents of the global array that generated them;
(5) Generate a quantity of options dependent on the player's choice;
(6) Split the menu's options into segments, size and quantity also dependent on the player's choice;
(7) Have each option show a number of different (but connected, via the array) values per row.

No points awarded for guessing my purposes here. :P
1. Yes.
2. No. You need to make ZScript global vars instead.
3. Yes.
4. Maybe.
5. Yes.
6. Yes.
7. I think so.
Sounds great! So my only obstacle would seem to be ascertaining how ZScript global vars are done but I'm guessing that's super-straightforward. Setting those variables might be another issue, though, as I plan to do it from a LANGUAGE lump.
User avatar
Major Cooke
Posts: 8216
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

Re: "How do I ZScript?"

Post by Major Cooke »

Code: Select all

class D4DDeathStorage : Thinker
{
	//--------------------------------------------------------------------------
	// Functions
	//--------------------------------------------------------------------------
	
	D4DDeathStorage Init()
	{
		ChangeStatNum(STAT_STATIC);
		return self;
	}

	static D4DDeathStorage Get()
	{
		ThinkerIterator it = ThinkerIterator.Create("D4DDeathStorage",STAT_STATIC);
		let p = D4DDeathStorage(it.Next());
		if (p == null)
		{
			p = new("D4DDeathStorage").Init();
		}
		return p;
	}
}
You can rename D4DDeathStorage to whatever you like. Insert your own variables and such there. Then, inside of another class, do this:

Code: Select all

let globalvar = D4DDeathStorage.Get();
if (globalvar)
{
    //Stuff.
}
See D4D's github for more examples.
User avatar
Major Cooke
Posts: 8216
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

Re: "How do I ZScript?"

Post by Major Cooke »

So I was thinking about a potential way to grab a player's inventory for possible use in the menus...

User Cvars. I think those could ultimately solve my problem if access is granted in ZScript.

If not, then I'm out of ideas.
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: "How do I ZScript?"

Post by Graf Zahl »

You can read the inventory as you like in the menus. It's only the writing that needs to go through the network. Like ZZYZX said, the best approach would be to install a NetworkEvent handler and then pass the info through there and do the real action in the handler's callback.

The event handler will be safely on the play side to manipulate whatever you want.
User avatar
Xaser
 
 
Posts: 10774
Joined: Sun Jul 20, 2003 12:15 pm

Re: "How do I ZScript?"

Post by Xaser »

Jimmy wrote:Sounds great! So my only obstacle would seem to be ascertaining how ZScript global vars are done but I'm guessing that's super-straightforward. Setting those variables might be another issue, though, as I plan to do it from a LANGUAGE lump.
The "global vars" implementation is a bit more involved than you may think (see Graf's post here -- you're technically making a Singleton class), but it's a solved problem. Hopefully a library-ized one in the nebulous future. :P

Not sure about the flexibility of the LANGUAGE lump part exactly; for dev-folk: is it as easy as using a "$LANGUAGE_STRING" directive as before? Relatedly, is LANGUAGE-fetching supported in the new String.Format function?
User avatar
Major Cooke
Posts: 8216
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

Re: "How do I ZScript?"

Post by Major Cooke »

Graf Zahl wrote:You can read the inventory as you like in the menus. It's only the writing that needs to go through the network. Like ZZYZX said, the best approach would be to install a NetworkEvent handler and then pass the info through there and do the real action in the handler's callback.

The event handler will be safely on the play side to manipulate whatever you want.
But CountInv and FindInventory doesn't work because they're part of actor, which is from thinker that's a play object. How do we go searching through the inventory? Or do you mean to have the network event both get and set the inventory?
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: "How do I ZScript?"

Post by Graf Zahl »

Xaser wrote: Not sure about the flexibility of the LANGUAGE lump part exactly; for dev-folk: is it as easy as using a "$LANGUAGE_STRING" directive as before? Relatedly, is LANGUAGE-fetching supported in the new String.Format function?

String.Format is too low level for automated language support.
All print functions auto-localize but if you need to do calculations with the localized text you have to call Stringtable.Localize yourself.
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: "How do I ZScript?"

Post by Graf Zahl »

Major Cooke wrote: But CountInv and FindInventory doesn't work because they're part of actor, which is from thinker that's a play object. How do we go searching through the inventory? Or do you mean to have the network event both get and set the inventory?

Some functions need to be cleared for external access, best make a report for any you think needs to be accessible. This part isn't done yet.
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: "How do I ZScript?"

Post by ZZYZX »

Graf Zahl wrote:String.Format is too low level for automated language support.
All print functions auto-localize but if you need to do calculations with the localized text you have to call Stringtable.Localize yourself.
Not exactly. String.Format parses the formats manually. You can definitely add a format letter, implicitly convert it to 's' for string format and substitute the language item.
Although I'm not sure that it's ok to do architecturally and if that's even needed.
Last edited by ZZYZX on Tue Mar 07, 2017 10:18 am, edited 1 time in total.
User avatar
Major Cooke
Posts: 8216
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

Re: "How do I ZScript?"

Post by Major Cooke »

Done.

Now, for the network event handler, how should this be handled? I don't think I can straight up do a SendNetworkEvent since it's play (or has this been made an exception?), so should I store it all in a thinker class, and upon the menu's destruction, have that thinker update the player and destroy itself?
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: "How do I ZScript?"

Post by ZZYZX »

SendNetworkEvent is not play, NetworkProcess is. Also there is no way to get a network event executed in the UI. Wait until CountInv/FindInventory become accessible.
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: "How do I ZScript?"

Post by Graf Zahl »

You sent a network event by calling EventHandler.SendNetworkEvent and then implement a listener that receives it. This will automagically transfer your request past the barrier safely.
User avatar
Major Cooke
Posts: 8216
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

Re: "How do I ZScript?"

Post by Major Cooke »

I get the feeling they won't be stored up for mass processing in NetworkProcess, so I will have to create a thinker for the player before the start of the menu that can hold all the data being changed. The event handler will manipulate the thinker as the player does his stuff. Once the menu is destroyed, it does its duty of changing the player's inventory before destroying itself.

If that's not the way to do it, what kind of listener are we talking about?

Return to “Scripting”