Author Topic: Little sample of coding mistakes.  (Read 3871 times)

Offline adumbperson

  • Turn around in orbit!
Little sample of coding mistakes.
« on: May 25, 2019, 03:52:35 am »
Hello,

I wanted to show you galz and guyz, some error that I found while reading the many fonline sdk's that I've.

I wont say to which sdk the code belong... This post is done to help people write better code while implementing their dreams.

Code: [Select]
    uint16 centerhexX = 0;
    uint16 centerhexY = 0;
    if( valid( chosen ) && valid( target ) && !target.IsDead() && !target.IsChosen() )
    {
        centerhexX = target.HexX;
        centerhexY = target.HexY;
    }
    for( int i = 0; i < 6; i++ )
    {
        targethexX = centerhexX;
        targethexY = centerhexY;
        MoveHexByDir( targethexX, targethexY, i, radius );
        if( !GetHexPos( targethexX, targethexY,  drawx,    drawy  ) )
            return;
        coordsX[ i ] = drawx;
        coordsY[ i ] = drawy;
    }
    uint j;
    for( uint i = 0; i < 6; i++ )
    {
        j = i + 1;
        if( j > 5 )
            j = 0;
        int[] coords = { coordsX[ i ], coordsY[ i ], int(COLOR_RED), coordsX[ j ], coordsY[ j ], int(COLOR_RED) };
        DrawPrimitive( DRAW_PRIMITIVE_LINESTRIP, coords );
    }

This statement is wrong way to proceed...
Code: [Select]
    uint16 centerhexX = 0;
    uint16 centerhexY = 0;
    if( valid( chosen ) && valid( target ) && !target.IsDead() && !target.IsChosen() )
    {
        centerhexX = target.HexX;
        centerhexY = target.HexY;
    }

If there is an invalid pointer or/and that target is dead or/and target is chosen
centerhexX/Y wont be set to the right hexes... AND THE CODE STILL CONTINUE PROCESSING...

Hope this help.
The Death After Life.
About me. I hate people generally I still may have respectful talk and recognize the good persons. Careful to what you say, I'm not a kid. My experiences defines me.
[Awaxx] -2024/10/17-

Offline Wipe

  • Rotator
  • Random is god
Re: Little sample of coding mistakes.
« Reply #1 on: May 25, 2019, 03:32:35 pm »
What you skipped is probably important.

If that's the same server i'm looking at, this is DrawDmgRadius() which contains
Code: [Select]
    if( !GetMonitorHex( __MouseX, __MouseY, centerhexX, centerhexY ) )
        return;
called some lines before part you pasted.

If there is an invalid pointer or/and that target is dead or/and target is chosen
centerhexX/Y wont be set to the right hexes... AND THE CODE STILL CONTINUE PROCESSING...
Isn't it exactly how it should be?

Take VC turret made as Critter as example:
If your cursor is over its "head", and you attack it, Client will change attack position to Critter's hex position, at turret's "feet", which is good few hexes below a cursor.
If your cursor is over its "head", but turret is dead already, nothing changes. You cannot attack dead Critters, so you attack hex under cursor instead - amount of care about rockets/nades/etc. in this function hints that it's connected to hexshooting.

This is a feedback function for players, so they know exactly where their attack, which might include splash damage, will end. It has to be consisted with Client/combat logic or it's worthless.

Just a wild guess, obviously. You didn't mention server name (i wonder why... :7), or any details after all. And it always could be copypaste from one server to another... which, in the end, does different things.
« Last Edit: May 25, 2019, 08:01:44 pm by Wipe »
Games are meant to be created, not played...

Offline adumbperson

  • Turn around in orbit!
Re: Little sample of coding mistakes.
« Reply #2 on: May 28, 2019, 05:47:28 am »
What you skipped is probably important.

If that's the same server i'm looking at, this is DrawDmgRadius() which contains
Code: [Select]
    if( !GetMonitorHex( __MouseX, __MouseY, centerhexX, centerhexY ) )
        return;
called some lines before part you pasted.
Isn't it exactly how it should be?

And... you are right.
I dunno how the hell i didn't see that call before posting this...
I must have been drunk or something while posting...
SHAME ON ME

Quote
Just a wild guess, obviously. You didn't mention server name (i wonder why... :7), or any details after all. And it always could be copypaste from one server to another... which, in the end, does different things.

It is fo2 sdk
The Death After Life.
About me. I hate people generally I still may have respectful talk and recognize the good persons. Careful to what you say, I'm not a kid. My experiences defines me.
[Awaxx] -2024/10/17-