"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
AFADoomer
Posts: 1346
Joined: Tue Jul 15, 2003 4:18 pm

Re: "How do I ZScript?"

Post by AFADoomer »

Nash wrote:What's stopping you from just overwriting/assigning to "target" directly?
Nothing. Target is the actor's shooting target, though, not the movement goal.

They are related in use, though. A_Chase is set up so that the actor will only move toward the goal when target is set to goal, but that "target = goal" assignment is handled internally... A_Chase sets the target to the goal as needed if the actor has a goal set, but only when there is no shooting target (or bChaseGoal is true).
User avatar
Rachael
Posts: 13997
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her

Re: "How do I ZScript?"

Post by Rachael »

Nash wrote:Question: what is for (;;) and why is it used that way?
"for (;;)" simply creates an infinite loop. It's like doing "while (true)" really - the two are quite interchangeable. It simply creates a loop that continuously executes with no conditional ending. Obviously, such a loop should contain delays of some sort to allow other operations to take place while the loop is in effect.
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 »

AFADoomer wrote:(Assuming this is in an actor, and that you want to set that actor's goal)

Code: Select all

            goal = goalobjectpointer;
            bChaseGoal = True; // equivalent to the "don't chase target" flag - or just leave it off for normal behavior.
I had tried this, and it wasn't working giving a Expression must be a modifiable value error... turns out my problem wasn't setting the goal, it was that I was tired and attempting to change the pointer from the play context, heh. Thanks anyway, though.
User avatar
Agentbromsnor
Posts: 265
Joined: Wed Mar 28, 2012 2:27 am

Re: "How do I ZScript?"

Post by Agentbromsnor »

I'm trying to control the player-animations in my platform-game using ZScript, and I can't figure out how to call the actual frame-states (standing, walking, jumping etc.) from a void function. Can someone educate me on that?

Edit: The "SetStateLabel" function is apparently what I'm looking for.
User avatar
hfc2x
Posts: 646
Joined: Mon Aug 17, 2009 11:37 am
Location: Chule

Re: "How do I ZScript?"

Post by hfc2x »

How can you read a value from a Custom Actor Property and use it as a variable in an anonymous function?
ZzZombo
Posts: 339
Joined: Mon Jul 16, 2012 2:02 am

Re: "How do I ZScript?"

Post by ZzZombo »

Code: Select all

    let actor=<actor class>(<actor pointer>);// access actor.<custom variable> next how you wish.
?
User avatar
Accensus
Banned User
Posts: 2383
Joined: Thu Feb 11, 2016 9:59 am

Re: "How do I ZScript?"

Post by Accensus »

Actually no need for a pointer. Just use the property directly as you'd a DECORATE expression, i.e. Health.
ZzZombo
Posts: 339
Joined: Mon Jul 16, 2012 2:02 am

Re: "How do I ZScript?"

Post by ZzZombo »

Ah, if it's being used inside the class that defined it, then yea.
User avatar
AFADoomer
Posts: 1346
Joined: Tue Jul 15, 2003 4:18 pm

Re: "How do I ZScript?"

Post by AFADoomer »

ZzZombo wrote:Ah, if it's being used inside the class that defined it, then yea.
Or "cast" the pointer as the class, then use it...

Assuming your actor is of class MyClass:

Code: Select all

// Like you said, this *won't* work except from inside the actor
theactor.newvariable = 5

// But this *will* work from wherever...
MyClass(theactor).newvariable = 5;
User avatar
Nash
 
 
Posts: 17513
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: "How do I ZScript?"

Post by Nash »

Yo how do I compare if string a == string b? For example, if (a == "apples") ?

strcmp doesn't seem to exist in ZScript? :S

Code: Select all

// compile error, function not found
if (String.strcmp(stringVar, "apples") == 0)
{
}
 
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 »

== works. If you need it to be case-insensitive, ~==.
User avatar
Nash
 
 
Posts: 17513
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: "How do I ZScript?"

Post by Nash »

Holy crap, that's the first time I've ever heard of how that is supposed to even work. :O Thanks!
User avatar
hideousdestructor
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

Re: "How do I ZScript?"

Post by hideousdestructor »

How do you do the equivalent of summonfriend?

This doesn't work - they'll only target each other and other monsters, but not deathmatch opponents:

Code: Select all

	actor bbb=spawn("DoomImp",pos);
	bbb.bfriendly=true;
	bbb.master=self;
	bbb.friendplayer=AAPTR_DEFAULT;
EDIT: Had to make this explicit:

Code: Select all

	bbb.designatedteam=self.player.getteam();
ZzZombo
Posts: 339
Joined: Mon Jul 16, 2012 2:02 am

Re: "How do I ZScript?"

Post by ZzZombo »

"friendplayer" is an index of the "owner" player, that is, you use AAPTR_DEFAULT wrong. Your setup may or may not work by chance due to that.
User avatar
hideousdestructor
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

Re: "How do I ZScript?"

Post by hideousdestructor »

Thanks, good catch - I totally forgot to consider that what with my adventures in mousecrash wackyland. (see closed bugs forum)

Another weird problem: I've got this code:

Code: Select all

...
        thinkeriterator it=thinkeriterator.create("HDWeapon");
        HDweapon hdw;
        while(
            hdw=HDWeapon(it.Next())
        ){
            if(hdw.owner==self){
                int blx;
                if(hdw is "Lumberjack"){
                    blx+=100;
                    if(hdw.weaponstatus[1]>=0)blx+=BLOX_BATTERY_LOADED;
                }else if(hdw is "HDPistol"){
... 
and so on, with each "HDWeapon" owned by the caller adding a different value to "blx".

Which works fine, except this ends up with "blx" being some obscenely high number unless I explicitly reset it with "int blx=0". Why is this? Shouldn't that int be re-initialized every time that block is run?

Return to “Scripting”