"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!)

Re: "How do I ZScript?"

Postby Blue Shadow » Wed Oct 18, 2017 7:58 am

ramon.dexter wrote:How do I use random number in Damage property of projectile? When i put in 'random(1,10);', it returns error, that even numbers has to be used :(

Use DamageFunction instead of Damage as the property.
User avatar
Blue Shadow
 
Joined: 14 Nov 2010
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: ATI/AMD (Modern GZDoom)

Re: "How do I ZScript?"

Postby Major Cooke » Thu Oct 19, 2017 1:46 pm

Just be warned, changing the damage from then on out will remove the damagefunction and it'll be based on damage*1d8! At least that's what it looks like from the source code.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: "How do I ZScript?"

Postby cambertian » Thu Oct 19, 2017 2:39 pm

If I'm trying to make an inventory item that should only be picked up if, say, the player doesn't have item X in his inventory, which virtual function should I override - HandlePickup, TryPickup, TryPickupRestricted, CanPickup, or ShouldStay?
I've been trying HandlePickup already, but even when it returns false it seems to get added to the inventory...
User avatar
cambertian
Resident Non-Programming Programmer
 
Joined: 07 May 2015
Location: New England Area, USA
Discord: cambertian#6245
Operating System: Windows 10/8.1/8/201x 64-bit
Graphics Processor: nVidia with Vulkan support

Re: "How do I ZScript?"

Postby ZippeyKeys12 » Sat Oct 21, 2017 5:52 pm

Is it possible to detect multiple simultaneous key-presses inside of InputProcess? Set booleans when buttons are pressed and remove when released—Thanks Gutawer

Also is it possible to register an EventHandler while the game is running? I recall seeing ZZYZX mention this, but I can't seem to figure it out. :?

Any help would be appreciated :)

EDIT: Also, is it not possible to put a constant array in a struct?
EDIT 5: Can I access a variable in an EventHandler from my StatusBar?

EDIT 2: Is there no way to do exponents? exp(x) is only e^x ** Operator—Thanks Gutawer again
EDIT 3: I guess I know nothing. Does cos(x) have a relatively significant performance cost like sqrt(x)? Don't bother micro-optimizing—Thanks Gutawer again
EDIT 4: And is there a way to get pi? Set it as a constant because it's close enough—Thanks Apeirogon
Last edited by ZippeyKeys12 on Sun Nov 05, 2017 7:45 pm, edited 2 times in total.
ZippeyKeys12
 
Joined: 15 Jun 2016

Re: "How do I ZScript?"

Postby Apeirogon » Sun Oct 22, 2017 10:52 am

ZippeyKeys12 wrote:EDIT 4: And is there a way to get pi?


TL:DR Just define its as constant.
Pi is irrational transcendent number and cant be evaluate like 2+2, just approximately defined to some decimal number. Even if you planing use eulers identity to find n roots of number (why?),pi=3.141596 and e=2.718281828 would be more than satisfaing aproximation, because other number in gzdoom may, and would, be defined with musch less precision.

How make a_chase function more "intelligent", because, as example, monster hard to find entrance into small corridor where stand player?
User avatar
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: "How do I ZScript?"

Postby ZippeyKeys12 » Sun Oct 22, 2017 6:54 pm

Apeirogon wrote:How make a_chase function more "intelligent", because, as example, monster hard to find entrance into small corridor where stand player?

If you're making a map then check this out:https://forum.zdoom.org/viewtopic.php?f=105&t=58168 else idk maybe try using hitscans or actors to try and plot out the map and try every path to find the player?
ZippeyKeys12
 
Joined: 15 Jun 2016

Re: "How do I ZScript?"

Postby Gutawer » Mon Oct 23, 2017 3:39 am

ZippeyKeys12 wrote:EDIT 2: Is there no way to do exponents? exp(x) is only e^x
EDIT 3: I guess I know nothing. Does cos(x) have a relatively significant performance cost like sqrt(x)?

2: Use the ** operator.
3: Even sqrt() doesn't have a massive performance impact unless you're calling it a lot, so I wouldn't assume that cos() has any significant performance impact either. Don't try and optimise until your code is running slowly, because otherwise you get messy micro-optimised code which is a pain to read.
User avatar
Gutawer
User Accounts Assistant
 
Joined: 16 Apr 2016
Discord: Gutawer#3431

Re: "How do I ZScript?"

Postby ramon.dexter » Tue Oct 24, 2017 5:38 am

OK, how does replaces excatly work in zscript?

Let's say, I have a weapon, here:
Code: Select allExpand view
class staffBlaster : Weapon replaces RocketLauncher


But I can find rocket launcher where it should be in map (better said: It is not replaced). Relacers for rocketammo works as expected, replacers for other weapons work as expected, but the replacer for rocketlauncher just dont work. What am I doing wrong?
User avatar
ramon.dexter
rudebwoy
 
Joined: 20 Oct 2015
Location: Kozolupy, Bohemia
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: "How do I ZScript?"

Postby Blue Shadow » Tue Oct 24, 2017 5:48 am

Are you loading other mods with yours that replace the rocket launcher (especially ones which to so via DECORATE)?
User avatar
Blue Shadow
 
Joined: 14 Nov 2010
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: ATI/AMD (Modern GZDoom)

Re: "How do I ZScript?"

Postby ramon.dexter » Tue Oct 24, 2017 5:57 am

No. I'm testing the mod only with basic doom2. And it really suprises me, since the shotgun IS replaced, the armor is replaced, but the rocketlauncher sits there and smiles on me :)
User avatar
ramon.dexter
rudebwoy
 
Joined: 20 Oct 2015
Location: Kozolupy, Bohemia
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: "How do I ZScript?"

Postby ZippeyKeys12 » Tue Oct 24, 2017 8:21 am

Is your rocket launcher in a separate file that you forgot to #include?
Maybe something is left over in AutoLoad?
ZippeyKeys12
 
Joined: 15 Jun 2016

Re: "How do I ZScript?"

Postby ramon.dexter » Tue Oct 24, 2017 10:33 pm

Yup. forget to remove the rocketlaucnher replacer/remover that I put in and completely forgot about :)
User avatar
ramon.dexter
rudebwoy
 
Joined: 20 Oct 2015
Location: Kozolupy, Bohemia
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: "How do I ZScript?"

Postby Rip and Tear » Sat Oct 28, 2017 1:56 pm

What is the practical effect of the identifier in the random number functions (wiki)?
User avatar
Rip and Tear
I <3 ZScript
 
Joined: 02 May 2017
Operating System: Mac OS w/ M1 Processor

Re: "How do I ZScript?"

Postby ZippeyKeys12 » Mon Oct 30, 2017 10:04 am

Rip and Tear wrote:What is the practical effect of the identifier in the random number functions (wiki)?

From what I can tell, it seems as if running random functions under a specific identifier could somehow bias future random functions with that same identifier. So I supposed if one needed a more independent random value they would use a different identifier? :shrug:
Gonna have to see what someone more informed has to say, I'm interested now.
ZippeyKeys12
 
Joined: 15 Jun 2016

Re: "How do I ZScript?"

Postby Gutawer » Mon Oct 30, 2017 11:42 am

The identifier determines which FRandom object is returned internally when parsing the random functions - essentially, each FRandom object is a random number generator which holds an array of "states" (20 states, if interpreted as 32-bit integers). When an RNG function is called, the internal array index is incremented, and the state at that index is returned as a random number. Each FRandom object's states are seperate from the others, meaning that RNGs with different objects act independently of each other. So:
Code: Select allExpand view
int num1 = random(0, 10);
int num2 = random(0, 10);
Console.printf("%d, %d", num1, num2);

should act the same as:
Code: Select allExpand view
int num1 = random(0, 10);
int throwaway = random[whatever](0, 10);
int num2 = random(0, 10);
Console.printf("%d, %d", num1, num2);
User avatar
Gutawer
User Accounts Assistant
 
Joined: 16 Apr 2016
Discord: Gutawer#3431

PreviousNext

Return to Scripting

Who is online

Users browsing this forum: No registered users and 2 guests