having troubles with anonymous functions in 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!)
Post Reply
User avatar
Zen3001
Posts: 412
Joined: Fri Nov 25, 2016 7:17 am
Location: some northern german shithole

having troubles with anonymous functions in zscript

Post by Zen3001 »

My first attempt at zscript.
I allready posted this code in my previous thread but here I am again

Code: Select all

Class Randomname : Doomimp{
	Default{
		//$Category Monsters
		Speed 11;
		+PUSHABLE
	}
	States{
		Spawn:
			TNT1 A 1{
				A_PrintBold("this should appear if the code works"); //It doesn't appear anywhere
				if (args[0] == 0){
					A_Jump(256, "Stand");
				}else{
					A_Jump(256, "Walk");
				}
			}
		Walk:
			TNT1 A 0 A_Look();
			TROO AABBCCDD 3 A_Wander();
			Loop;
		Stand:
			TROO AB 1 A_Look();
			Loop;
	}
}
The anonymous function doesn't seems to be working it just skips to walk without any errors.
Blue Shadow
Posts: 5046
Joined: Sun Nov 14, 2010 12:59 am

Re: having troubles with anonymous functions in zscript

Post by Blue Shadow »

See [wiki=Actor_states#NoDelay]NoDelay[/wiki].
User avatar
Zen3001
Posts: 412
Joined: Fri Nov 25, 2016 7:17 am
Location: some northern german shithole

Re: having troubles with anonymous functions in zscript

Post by Zen3001 »

that helped kind of, the print function is now working so it's going trough the anonymous function but it doesn't jump to the stand state even tho all arguements are 0
Blue Shadow
Posts: 5046
Joined: Sun Nov 14, 2010 12:59 am

Re: having troubles with anonymous functions in zscript

Post by Blue Shadow »

Do this:

Code: Select all

return A_Jump(...);
See [wiki=Actor states#Return]this[/wiki] for reference.

Edit: Since the use of a return statement is required, make sure to cover all possible paths. This means if you have something like this:

Code: Select all

TNT1 A 0
{
    if (blah > 0)
    {
        return A_Jump(...);
    }
    else
    {
        return A_Jump(...);
    }
}
You'll get an error, unless you put a return statement at the end (the engine considers it as a possible path the function could go through still):

Code: Select all

TNT1 A 0
{
    if (blah > 0)
    {
        return A_Jump(...);
    }
    else
    {
        return A_Jump(...);
    }

    return null; // If this produces an error, change it to: return ResolveState(null);
}
User avatar
Zen3001
Posts: 412
Joined: Fri Nov 25, 2016 7:17 am
Location: some northern german shithole

Re: having troubles with anonymous functions in zscript

Post by Zen3001 »

yeah everything seems to be working now, thanks for helping.
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
Contact:

Re: having troubles with anonymous functions in zscript

Post by hideousdestructor »

I find it easier to just use

Code: Select all

...
setstatelabel(...);
return;
...
and not to worry about the paths except to make sure nothing is being executed that shouldn't be.
Post Reply

Return to “Scripting”