'if ( a_check<x> )' functionality detection

Post a reply

Smilies
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :geek: :ugeek: :!: :?: :idea: :arrow: :| :mrgreen: :3: :wub: >:( :blergh:
View more smilies

BBCode is OFF
Smilies are ON

Topic review
   

Expand view Topic review: 'if ( a_check<x> )' functionality detection

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

by Fishytza » Sun Feb 21, 2016 8:59 am

Right. Everything's clear now. Thank you for being patient with me, Randi. :)

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

by randi » Sat Feb 20, 2016 10:31 pm

FishyClockwork wrote:This on its own doesn't declare 'success' (because it's a jumping function)

Code: Select all

TNT1 A 0 A_Jump(111, "bleh")
To clarify, the above should be thought of as a compact way to write:

Code: Select all

TNT1 A 0 { return A_Jump(111, "bleh"); }
Because that's exactly how it gets processed. The two produce exactly the same code for the VM because they are the same.

It has no effect on the success of a CustomInventory state chain not because you called a jumping function but because the jumping function, which returns a state, is called with return to propagate the result out to the caller of your little function.

If it helps, what you are creating with this single line is an anonymous function ("anonymous" because it has no name) with an inferred return type, and the state calls that function. If it was written out as an explicit function (supposing DECORATE could express this), it would look something like this:

Code: Select all

actor MyActor
{
    action state A_MyJumper()
    {
        return A_Jump(111, "bleh");
    }

    states
    {
        TNT1 A 0 A_MyJumper
    }
}
FishyClockwork wrote:while this does declare 'success' because it doesn't return anything, nevermind its contents, correct?
Correct. This function returns nothing, so it gets counted as success.

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

by Fishytza » Sat Feb 20, 2016 7:39 am

randi wrote:If a function returns nothing, a CustomInventory chain will succeed.
Okay so, to be quite specific:

This on its own doesn't declare 'success' (because it's a jumping function)

Code: Select all

TNT1 A 0 A_Jump(111, "bleh")
while this does declare 'success' because it doesn't return anything, nevermind its contents, correct?

Code: Select all

TNT1 A 0
{
    A_Jump(111, "bleh"); //I know this will never jump, that's not the point
}

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

by randi » Sat Feb 20, 2016 6:30 am

FishyClockwork wrote:what happens if I don't use "return A_Whatever;" or just use "return;"? Does success of the action block depend on what functions were called within it?
randi wrote:If a function returns nothing, a CustomInventory chain will succeed.

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

by Fishytza » Sat Feb 20, 2016 2:47 am

I'm likewise fine with how they're named.


Let's see if I got this right.

Within a chain state, if an X determines success then the whole chain succeeds.
X can be a single action function EG

Code: Select all

TNT1 A 0 A_SpawnItemEx("etc")
or it can be a action block EG

Code: Select all

TNT1 A 0
{
    A_Stuff;
    A_Etc;
    ....
}
Now, within a action block the action functions used are irrelevant since what actually determines success of the action block is "return A_Bool(true/false);" or "return A_Int(0/1);".

Assuming I guessed everything correctly so far, what happens if I don't use "return A_Whatever;" or just use "return;"? Does success of the action block depend on what functions were called within it?

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

by Major Cooke » Fri Feb 19, 2016 11:01 pm

Nah they're fine. I get they pretty much represent what they say. I just wasn't sure how to properly use them but with that explanation, that clears things up. Thanks for that!

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

by randi » Fri Feb 19, 2016 10:18 pm

Would it help you if I renamed A_Int, A_Bool, and A_State to int, bool, and state so that they look like function-style casts ala C++? Because that's pretty much what they're there for: Declaring the type of the return value.
  • If a function returns a non-NULL state, it causes a jump. If a NULL state is returned, no jump happens. Either way, a CustomInventory chain is not affected.
  • If a function returns an int of non-0 or a bool of true, a CustomInventory chain will succeed. If it returns 0 or false, that state will fail, possibly failing a CustomInventory chain. If not called as part of a CustomInventory chain, the return value is ignored.
  • If a function returns nothing, a CustomInventory chain will succeed.
So use return A_Bool(false); or return A_Int(0); to mark the state as failed. If every state fails, then the chain fails. If any state succeeds, then the whole chain succeeds. (Or if I renamed those functions, that would be return bool(false); or return int(0);)

Nothing about CustomInventory's behavior has changed. The only "difference" is that now you can write your own functions to make it fail.

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

by Major Cooke » Fri Feb 19, 2016 5:18 pm

Yeah I am. I'm trying to understand how A_Int and A_Bool can be used best... I know you said mainly only useful for custom inventories.

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

by randi » Fri Feb 19, 2016 5:15 pm

I think you're confused, and you're confusing me.

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

by Major Cooke » Fri Feb 19, 2016 5:09 pm

I think I'm starting to get it. Because custominventory can essentially be used for determining true and false conditions based on pickup/use success or fail, the moment its processed, it's sent back to the owner of the one doing the giving and thus they can use this in A_SetUserVar... Right? So something like A_SetUserVar(user_given, A_RadiusGive(...)) <--entirely speculation, haven't even tried it yet.

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

by randi » Fri Feb 19, 2016 4:49 pm

FishyClockwork wrote:So not only is "return" mandatory even though you don't want to jump
Use A_State(0) or A_State("") to signal you don't wish to jump. This is the way all the A_Jump functions are doing it now too.
FishyClockwork wrote:but you cannot use "return A_State" and "return A_Int/A_Bool" in the same action block, else you get this error "Return types are incompatible"
Because you're defining an anonymous function, it needs to have a single return type. If you try to mix them, it can't deduce which one you really wanted to use and will give you that error.

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

by Fishytza » Fri Feb 19, 2016 9:58 am

Major Cooke wrote:I'll report this on the bug forums if you haven't already.
Be my guest. Nevermind.

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

by Major Cooke » Fri Feb 19, 2016 9:53 am

The real bug is "Action list must end with a return statement" is not covering all corner case scenarios. Looks like it's going to need some further checks added.

I'll report this on the bug forums if you haven't already.

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

by Fishytza » Fri Feb 19, 2016 9:50 am

No crash if "return A_State(0);" is outside and right after the two if-else blocks.

It seems to be smart enough to expect a return of some sort if it finds one inside a if block but gets caught off-guard with something like:

Code: Select all

		TNT1 A 0
		{
			if( randompick(0,1) == 1 )
			{
				A_Log("jumping");
				return A_State("Skok");
			}
		}
In this instance, if the if condition is not met then it just crashes. If you add another function (eg. A_SpawnItemEx) after the if block then you get a error at start up "Action list must end with a return statement"

So not only is "return" mandatory even though you don't want to jump, but you cannot use "return A_State" and "return A_Int/A_Bool" in the same action block, else you get this error "Return types are incompatible"

IE this is a big no-no

Code: Select all

		TNT1 A 0
		{
			if( randompick(0,1) == 1 )
			{
				A_Log("jumping");
				return A_State("Skok");
			}
			A_Log("fffff");
			return A_Int(1);
		}

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

by Major Cooke » Fri Feb 19, 2016 9:46 am

Try moving the return statement to just after the else's closing bracket, see if it crashes.

Top