If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Cant get condition check right.

10-12-2017, 03:38 PM

Hello there.
I have these lines of code in my W_FireWeapon function.
My purpose is to play one set of frame macros if the player aims at something with 1 and 39 hitpoints and another macro if he aims at something without health.
My limited brain capacity is not able to wrap around what i have to do. The lines below have the effect that the macros are played at seemingly random patterns.

Comment

Also, you are checking if solid OR health <> range. Is that really what you want?

Do you mean i compare the solid and the health with the range to the entity that is hit by the traceline?
Uhm... strange, it works nevertheless

I didn't mean slim it down ...

Ah, now i understand what you meant. I'm often a little slow in the head.

Here is a video with how it looks ingame:

The Solider (less than 40 health at start Edit: in the most cases, this time not) get carved away immediately with the straight away holding animation. The Ogre (300 health at start) needs a little work by swinging the chainsaw from side to side, Edit: then the code starts to play the Straightaway-downsawing animation. Also, the horizontal and vertical animations are played, if the player aims at things without health or the right kind of solid. Well, don't look at the chainsaw animations too closely, they are still very clunky.

Comment

The idea here is that you should be able to use the chainsaw all the time. That being said you do not need a range or to test the SOLID type. What if the ent was a door? You can't open doors with your chainsaw? Of course you can. It does not matter if the trace_ent has any health so only define the upper limits of the first animation. You don't need an 'r' var cause you only use the var 1 time. You do not need a bunch of nested ifs to make a switch decision. Just use a ternary statement.

ex ternary statement:
(if this is true)? then do this : (else if this is true) ? then do this : else do this;

Comment

TheKillingJoke
You'll do fine. I'll help you and you'll get real good. I'm out of touch with QC but, I can program my ass off so, whatever you got I'll figure it out.

Dutch
It's only really any good if you just have 2 or 3 singular operations. It can become a pain to read, really fast but, technically you should be able to chain ternaries to infinity. You should also be able to use it after =

MyVar = (some condition)? 500 : 1000;

Note: my 2 parter above is an actual ternary in full. The 3 parter in my original example is actually 2 ternaries chained together. Look at ternaries as ONLY if and else but the else can hold another ternary which makes it a virtual 'else if'. However if we broke it down this is really what's happening when you chain.

Code:

if () {
} else {
if () {
} else {
}
}

You can only have 1 value per condition. There is no way to ternary the below nor would you want or ever need to. It would be a mess.

Code:

If(condition) {
myVar1 = 1;
myVar2 = 2;
} else {
myVar1 = myVar2;
}

Also, you cannot omit any part of a ternary. Let's say you chain a few ternaries and get to the final else but, don't have a final value to use...you better find one... Null, Void, NaN, Empty String, NEGATIVE_INFINITY, something.