'if ( a_check<x> )' functionality detection

Moderator: GZDoom Developers

User avatar
Major Cooke
Posts: 8212
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:

'if ( a_check<x> )' functionality detection

Post by Major Cooke »

Now this is for ideas involving things like A_CheckLOF and A_CheckBlock, etc.

Would it be possible to change the if statements where, if the jumping function is inside an if block, it could perform some functions like changing a user var based on if it's true or not?

Code: Select all

TNT1 A 0
{
    if ( A_CheckLOF(...) )
    {
        //Some functionality here like A_SetUserVar
    }
    else //Should A_CheckLOF fail
    {
    }
}
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49235
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: 'if ( a_check<x> )' functionality detection

Post by Graf Zahl »

Be careful! Most of the jump functions used wrong can seriously cause havoc.
User avatar
Major Cooke
Posts: 8212
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: 'if ( a_check<x> )' functionality detection

Post by Major Cooke »

I didn't even think they could be used in an if statement. Huh...

That got me thinking... What about a DoNotJump keyword for them placed inside of the state parameter? One that could allow the function to proceed but is not actually performed -- instead, it simply returns a value of true or false based on ACTION_JUMP being called.
User avatar
randi
Site Admin
Posts: 7749
Joined: Wed Jul 09, 2003 10:30 pm
Contact:

Re: 'if ( a_check<x> )' functionality detection

Post by randi »

God, I'd rather not deal with that mess.
User avatar
randi
Site Admin
Posts: 7749
Joined: Wed Jul 09, 2003 10:30 pm
Contact:

Re: 'if ( a_check<x> )' functionality detection

Post by randi »

Actually, I think I came up with a way to make this work and (maybe) give you your compound block "goto"s at the same time. But as a warning, it means you'll probably have to change your A_Jumps inside compound statements to return A_Jump(); to make them jump.
User avatar
Major Cooke
Posts: 8212
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: 'if ( a_check<x> )' functionality detection

Post by Major Cooke »

Okay, so that means we'll be able to do if ( <jump function> ) { return <jump function>; } in a manner of speaking?
User avatar
randi
Site Admin
Posts: 7749
Joined: Wed Jul 09, 2003 10:30 pm
Contact:

Re: 'if ( a_check<x> )' functionality detection

Post by randi »

And now you have it. As a reminder, if you have this anywhere:

Code: Select all

A_Jump(); return;
You will need to change it to this to make the jump happen:

Code: Select all

return A_Jump();
As a convenience, you can also jump to a specific state without using A_Jump(256, x) like this:

Code: Select all

return A_State("AnotherState");
And if you want to do something when a jump is indicated and also take the jump, you can combine them like this:

Code: Select all

if (A_Jump(128, "Somewhere"))
{
    // Do something because it wants to jump
    ...
    // Now make the jump happen
    return A_State("Somewhere");
} 
And if I broke anything, I'm sure you'll let me know about it...
User avatar
Major Cooke
Posts: 8212
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: 'if ( a_check<x> )' functionality detection

Post by Major Cooke »

Woo! Awesome!

Now, about the A_Int: So does that work with things like A_CheckProximity, A_RadiusGive, anything that does a 'return numret' inside thingdef_codeptr?
User avatar
randi
Site Admin
Posts: 7749
Joined: Wed Jul 09, 2003 10:30 pm
Contact:

Re: 'if ( a_check<x> )' functionality detection

Post by randi »

A_Int is there because you can't do something like return 0; You have to do return A_Int(0); instead. The only place in DECORATE where this would be useful is with CustomInventory.

Actually, I think I messed those return value kludge functions up, but I'm in bed now...
User avatar
Fishytza
Posts: 793
Joined: Wed Feb 23, 2011 11:04 am
Preferred Pronouns: They/Them
Contact:

Re: 'if ( a_check<x> )' functionality detection

Post by Fishytza »

Okay, just to see if I understand the new jumping correctly.

Code: Select all

if( (1+1) == 2 )
{
	A_DoStuff;
	A_DoSomeMoreStuff;
	A_Jump(256, "JumpyJump");
}
The jump to 'JumpyJump' will not happen because I did not declare it as

Code: Select all

return A_Jump(256, "JumpyJump");
correct?
Edward-san
Posts: 1774
Joined: Sat Oct 17, 2009 9:40 am

Re: 'if ( a_check<x> )' functionality detection

Post by Edward-san »

yes, but now you can use A_State(...) instead of A_Jump(256, ...)

Code: Select all

return A_State("JumpyJump");
User avatar
Major Cooke
Posts: 8212
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: 'if ( a_check<x> )' functionality detection

Post by Major Cooke »

So A_SetInt is meaningless anywhere outside of custominventory? Just wanted to clarify. Aside aborting code blocks.
User avatar
Fishytza
Posts: 793
Joined: Wed Feb 23, 2011 11:04 am
Preferred Pronouns: They/Them
Contact:

Re: 'if ( a_check<x> )' functionality detection

Post by Fishytza »

Since this has been added just recently, is it okay if I report a little issue here? Because I'm not entirely sure if this is a bug or not.

So, basically when ever I call "return A_State("blah");" inside an if block, I also must call an identical "return A_State(0);" at the end even though I don't want to jump (otherwise I get a "Action list must end with a return statement" message). Is that intentional?

Now here's something which I think is a bug:
Spoiler:
User avatar
Major Cooke
Posts: 8212
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: 'if ( a_check<x> )' functionality detection

Post by Major Cooke »

No, you really aught to post it in the bugs section.

Also, finish the if statement with an else {}. I think that's what it needs. I'm doing some testing right now.

You know, this would actually be a perfect opportunity to see if A_Chase could work here...
Last edited by Major Cooke on Fri Feb 19, 2016 9:38 am, edited 1 time in total.
User avatar
Fishytza
Posts: 793
Joined: Wed Feb 23, 2011 11:04 am
Preferred Pronouns: They/Them
Contact:

Re: 'if ( a_check<x> )' functionality detection

Post by Fishytza »

Major Cooke wrote:finish the if statement with an else {}.
Why? The crash still happens unless I add "return A_State(0);" in the else block.
Post Reply

Return to “Closed Feature Suggestions [GZDoom]”