Bool set by number comparison statement result?

Discussions about Coding and Scripting

Bool set by number comparison statement result?

Postby LannFyre » Fri Oct 21, 2016 3:05 am

Is bHasNotifies being set to true if the following comparison math statement is made true? I didn't write this, but I'm curious if this is giving me a result, can't log it yet so I'm not sure if it is even giving a result.
Code: Select all
local int Max;

bHasNotifies = Max > 0;
<<| http://uncodex.ut-files.com/ |>>

Code reference for UGold, UT99, Unreal2, UT2k3, UT3

Additional Beyond Unreal Wiki Links
wiki.beyondunreal.com/Legacy:Console_Bar
wiki.beyondunreal.com/Exec_commands#Load
wiki.beyondunreal.com/Legacy:Exec_Directive#Loading_Other_Packages
wiki.beyondunreal.com/Legacy:Config_Vars_And_.Ini_Files
wiki.beyondunreal.com/Legacy:INT_File
User avatar
LannFyre
Skilled
 
Posts: 233
Joined: Sun Dec 28, 2014 1:10 am
Location: Anubitek

Re: Bool set by number comparison statement result?

Postby Barbie » Fri Oct 21, 2016 4:06 am

Is bHasNotifies being set to true
Yes. The right side is evaluated what results in type BOOL. That result is then assigned to the variable at left side.
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
Barbie
Godlike
 
Posts: 1641
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Bool set by number comparison statement result?

Postby sektor2111 » Fri Oct 21, 2016 6:28 am

These are already used by UT but I cannot recall where - you need to read more codes. Else bools can be set even in different way:
Snippet here
Code: Select all
   HitActor = Trace(HitLocation, HitNormal, Inv.Location, Location, false);
   bInvObstructed = HitActor != None;
Bool is result of a sort of an "If" query but without writting IF:
Code: Select all
if (Max > 0)
   bHasNotifies = True;
else //Else if not assigned already is false
   bHasNotifies = False;
Does the same thing.
LannFyre wrote:..can't log it yet so I'm not sure if it is even giving a result.
:shock: What !? ANY snippet can be ported in a small tiny little mutator logger for doing checks toward a code - clearly you did not understand working with temp mutators/actors, this is how I do check things without screwing my mods.
Other case - calling directly other function without assigning too many bools:
Code: Select all
   BestPath = FindBestInventoryPath(BestWeight, !bNovice && (skill >= 2));
Because FindBestInventoryPath sounds like
Code: Select all
   native(540) final function actor FindBestInventoryPath(out float MinWeight, bool bPredictRespawns);
All IF block reacts if condition is TRUE and then "else" comes for FALSE case.
User avatar
sektor2111
Godlike
 
Posts: 3865
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Bool set by number comparison statement result?

Postby Chris » Fri Oct 21, 2016 7:45 pm

A bit more in-depth of what's happening in the VM:

Doing something like this simply results in fewer opcodes to be executed and thus makes your code more optimal.
Code: Select all
myInt = 50;
bSomeBool = (myInt >= 10 || myInt < 5)   && myInt < 100;


So what's actually happening here?
Let's start looking at the structure of an operator.
An operator can take as most two operands and every operator in this line returns a boolean.

Code: Select all
native(153) static final operator(24) bool >= ( int A, int B );
native(150) static final operator(24) bool <  ( int A, int B );


So in order to evaluate the result of the && operator, the right-hand and left-hand operands has to be evaluated.
Now the right-hand operand has a single operator argument where no additional operands has to be evaluated.
On the left-hand we have an additional level of operators, which means in order to evaluate '&&' we have to evaluate '||' , in order to evaluate '||'
we have to evaluate its corresponding resulting operands 'myInt >= 10 ' and 'myInt < 5'.
So when every operator successfully evaluates its operands it pushes the result onto the variable stack of the VM.
That in turn means that the previous operator in the hierarchy then pops the first variable off of the stack (which was the result) so it can then re-evaluate that with the new conditions, and Mary goes around...

So what happens in your code is that the assignment operator takes the result of the evaluated '>' operator, pops it off of the stack and assigns it to the boolean variable.
If you take a close look at the return type of the operators they all return a boolean, so there is no type mismatch and therefore completely legal.

An if statement takes a single boolean operand, which is the result of the operators used as an argument.

Like Sektor2111 said, any variable can be easily output to the console, because the engine automatically coerces any incoming data type to a string, which the engine performs specific type conversions on, all happening under the hood.
Chris
Experienced
 
Posts: 116
Joined: Mon Nov 24, 2014 9:27 am


Return to Coding, Scripting

Who is online

Users browsing this forum: No registered users and 3 guests