bindentity problem for boards (trick solution)

White Dragon

New member
PROBLEM:
To make a surf board for an entity I use changeentityproperty(self,"position",x,z,NULL());
but if I use bindentity(self,parent,x_relative,z_relative,NULL()) altitude is setted to 0 always (relative value).
This is an engine BUG.
The problem is the asynchronous movements. WHY? Because the engine updates entity A in a frame and entity B in another (or same) frame. But if the engine renders A before or after B, the movements are async.
The real solution would be to make bindentity(self,parent,x_relative,z_relative,NULL()) working (bindentity updates all concurrently).
When the problem is visible?  When the game contains many scripts.

SOLUTION (trick):
to use:
changeentityproperty(self,"position",parent_x,parent_z,NULL());
changeentityproperty(self,"velocity",parent_xdir/2,parent_zdir/2,NULL());
(the order is important, and remember to set the board entity type to none)

It seems to work well guys ;)
 
I found a trick.
First I store in entityvars all coords (x,z,y,base etc...) and then I get them with the board script from the stored entityvars and not directly from getentityprop. It works but it's a bit sketchy! =)
 
It depends - I'd have to see the whole thing, but there are cases when you'd be better off scripting your own bind.

DC
 
None really, except that to achieve a true bind you have to run it on update and it doesn't have the automation or a couple of the other extras of bindentity().

With bindentity(), it's "set it and forget it", and there are some other advantages beyond this discussion.

But yes, when all you want is simple position matching bindentity() can be a bit like trying to swat flies with a sledgehammer. That's when you are probably better off to do it yourself.

DC
 
mmm ... no forget it.
when I move, for example Z-axis there is a mismatch between the player and the board.
An instant before the player moves hisself and in the next moment the board adjusts his position.
bindentity only works but I don't want to bind the altitude.
How can I do?
Can we add the function bindentity(self, target, x, z, NULL ()) ??
There is another way to avoid the problem?
 
Unless something else is interfering, there's no reason using changeentityproperty(self,"position",x,z,NULL()) shouldn't work. That's exactly how binding works internally anyway.

I used this exact method to make grappling moves and simulate Joe Musashi riding his horse back before we even had bindentity(). The horse followed Joe through movement and normal jumps - but for his evade (U,U) / D,D) move Joe would leap into/out of screen independently while his horse followed him along the ground. Same thing you are trying to do now. It all worked with pixel perfect precision. 

DC
 
unfortunately the problem persists.
DC can you add the ability to make a bindentity NULL () in new openBOR releases?
Example in the image:
index.php


[attachment deleted by admin]
 
It's not really that simple. The bindentity() command merely sends instructions to the engine's built in bind system, and that system has been in place since BOR. It has no provision for binding on only one or two of the axises. I will look into it, but it may take some ground up redesign to make it work like that. Nothing stops me from just adding a second set of bind code, but that's bloatware and not a route I'm willing to take over one pixel.

In the meantime, why don't you post your text and and script. As I said before, there is no reason why pseudo binding with changentityproperty() shouldn't be able to do the job precisely.

DC
 
Damon Caskey said:
In the meantime, why don't you post your text and and script.

OK,
spawnscript (for player):
Code:
void main() {
    void self = getlocalvar("self");
    int anim_id = getentityproperty(self, "animationid");
    int p = getentityproperty(self, "playerindex");
    int inv_eta = openborvariant("game_speed")*3;
    /*char cText = getentityproperty(self, "model");
    char cFind = "STOP";
    char substr = strinfirst(cText, cFind);*/

    // Check Time-Reset
    changeentityproperty(self, "invincible", 1);
    changeentityproperty(self, "invinctime", openborvariant("elapsed_time")+get_next_time(inv_eta)); //makes entity invincible for 1.5 seconds, change decimal number to change time length
    changeentityproperty(self, "aiflag", "blink", 1); // makes entity blink until invinctime is reached

    if ( getglobalvar("in_menu") != 1 && getlevelproperty("type") != 2 ) { // Waiting, Select
        set_board(self);
    }
}

int set_board(void self) {
    void subent;
    char board = "";
    int type = getentityproperty(self,"type");
    int board_level = check_board_level();

    //board_level = 3;

    if ( type == openborconstant("TYPE_PLAYER") ) {
        char defaultmodel = getentityproperty(self,"defaultmodel");

        if ( defaultmodel == "RAPH" || defaultmodel == "LEO" || defaultmodel == "DON" || defaultmodel == "MIKE" ) {
            if ( board_level == 1 ) {
                board = "surf";
            } else if ( board_level == 2 ) {
                board = "skate";
            } else if ( board_level == 3 ) {
                board = "ufo";
            } else return 0;
        } else {
            if ( board_level == 1 ) {
                board = "esurf";
            } else if ( board_level == 2 ) {
                board = "eskate";
            } else if ( board_level == 3 ) {
                board = "eufo";
            } else return 0;
        }
    } else if ( type == openborconstant("TYPE_ENEMY") ) {
        if ( board_level == 1 ) {
            board = "esurf";
        } else if ( board_level == 2 ) {
            board = "eskate";
        } else if ( board_level == 3 ) {
            board = "eufo";
        } else return 0;
    } else return 0;

    clearspawnentry();
    setspawnentry("name", board);
    subent = spawn();
    changeentityproperty(subent, "parent", self);
    changeentityproperty(subent, "setlayer", getentityproperty(self,"setlayer")-1);
    if ( type == openborconstant("TYPE_PLAYER") ) set_board_map(self,subent);
    //setentityvar(self,"board",subent);
}

int check_board_level() {
    char branch_name = openborvariant("current_branch");
    int board_level = 0;

    if ( branch_name != NULL() ) {
        char surf_lv = "surf_lv", skate_lv = "skate_lv", ufo_lv = "ufo_lv";
        char surf_branch = strinfirst(branch_name, surf_lv);
        char skate_branch = strinfirst(branch_name, skate_lv);
        char ufo_branch = strinfirst(branch_name, ufo_lv);

        if ( surf_branch != -1 ) {
            board_level = 1;
        } else if ( skate_branch != -1 ) {
            board_level = 2;
        } else if ( ufo_branch != -1 ) {
            board_level = 3;
        } else board_level = 0;
    }

    if ( getglobalvar("board_level") == NULL() ) setglobalvar("board_level",board_level);
    if ( board_level == 0 ) setglobalvar("board_level",NULL());

    return board_level;
}

ondrawscript (for board):
Code:
void main() {
    void self = getlocalvar("self");
    void parent = getentityproperty(self,"parent");

    if ( getentityvar(self,"scene") != 1 ) check_position(self,parent);
    check_existence(self,parent);
}

int check_existence(void self, void parent) {
    if ( !getentityproperty(parent,"exists") && getlocalvar("candie") != NULL() ) {
        bindentity(self,NULL());
        killentity(self);
    } else {
        setlocalvar("candie",1);
    }
}

int check_position(void self, void parent) {
    if ( getentityproperty(parent,"exists") ) {
        float x = getentityproperty(self,"x");
        float z = getentityproperty(self,"z");
        float a = getentityproperty(self,"y");
        float base = getentityproperty(self,"base");
        int dir = getentityproperty(self,"direction");
        float px = getentityvar(parent,"x");
        float pz = getentityvar(parent,"z");
        float pa = getentityvar(parent,"y");
        float pbase = getentityvar(parent,"base");
        int pdir = getentityvar(parent,"direction");
        int p_ent_type = getentityproperty(parent,"type");
        char defaultmodel = getentityproperty(self,"defaultmodel");
        float scr_posy = openborvariant("ypos");
        float xshift = 0, zshift = 0, new_dir = 0;

        if ( px == NULL() ) px = getentityproperty(parent, "x");
        if ( pz == NULL() ) pz = getentityproperty(parent, "z");
        if ( pa == NULL() ) pa = getentityproperty(parent, "y");
        if ( pbase == NULL() ) pbase = getentityproperty(parent, "base");
        if ( pdir == NULL() ) pdir = getentityproperty(parent, "direction");

        if ( p_ent_type == openborconstant("TYPE_PLAYER") ) {
            new_dir = 1;
        } else if ( p_ent_type == openborconstant("TYPE_ENEMY") ) {
            new_dir = 0;
        }

        if ( defaultmodel == "surf" ) {
            xshift = 5;
            if ( !dir ) xshift *= 1;
            zshift = 20;
        } else if ( defaultmodel == "esurf" ) {
            xshift = 0;
            if ( !dir ) xshift *= 1;
            zshift = 18;
        } else if ( defaultmodel == "skate" ) {
            xshift = 2;
            if ( !dir ) xshift *= 1;
            zshift = 10;
        } else if ( defaultmodel == "eskate" ) {
            xshift = -1;
            if ( !dir ) xshift *= 1;
            zshift = 10;
        } else if ( defaultmodel == "ufo" ) {
            xshift = 5;
            if ( !dir ) xshift *= 1;
            zshift = 20;
        } else if ( defaultmodel == "eufo" ) {
            xshift = -2;
            if ( !dir ) xshift *= 1;
            zshift = 20;
        }


        //drawstring( 10,50,0,"Var (board x):  "+px );
        //drawstring( 10,60,0,"Var (board z):  "+pz );

        //bindentity(self,parent,xshift,zshift,-1*(pa-pbase),0,0);
        //bindentity(self,NULL());

        /*float threshold = 0.001, inc = 1;
        float decimal_px, decimal_pz;
        decimal_px = px-trunc(px);
        decimal_pz = pz-trunc(pz);
        if ( decimal_px >= threshold ) {
            if ( !pdir ) inc *= -1;
            px = px + inc;
        } else px = px;
        if ( decimal_pz >= threshold ) {
            if ( getentityproperty(parent,"zdir") < 0 ) inc *= -1;
            pz = pz + inc;
        } else pz = pz;*/

        changeentityproperty(self,"position",px+xshift,pz+zshift,NULL()); // pbase
        if ( dir != new_dir ) changeentityproperty(self,"direction",new_dir);
    }
}

Thanks DC for your support!!

Ps. The problem is that there is a persistent mismatch and it is ugly to look at.
mismatching isn't continuous of a 1 pixel, infact the two images, which I posted, alternate continuously over time. 
I'd like to solve this problem ...
 
WD, this could sound stupid, but have you tried to use that code as SCRIPT and not ONDRAWSCRIPT? I say this because I remember I had problems with a script when I've put it as ondraw, but as SCRIPT it worked.
 
O Ilusionista said:
WD, this could sound stupid, but have you tried to use that code as SCRIPT and not ONDRAWSCRIPT? I say this because I remember I had problems with a script when I've put it as ondraw, but as SCRIPT it worked.

+1, the pseudo bind should be in script. That's how I did it.

DC
 
O Ilusionista said:
WD, this could sound stupid, but have you tried to use that code as SCRIPT and not ONDRAWSCRIPT? I say this because I remember I had problems with a script when I've put it as ondraw, but as SCRIPT it worked.

Tested, unfortunately the problem persists.
The problem is that there is a persistent mismatch and it is ugly to look at.
mismatching isn't continuous of a 1 pixel, infact the two images, which I posted, alternate continuously over time. 
I'd like to solve this problem ...
 
I can't remember, but I may have even had this on the main update. I'll have to go back into my older archives to see - it may take a few days to find the right one; I have dozens of copies - each time I updated it became a new copy and they span over years.

DC
 
Back
Top Bottom