Page 1 of 1

scripting problem?

PostPosted: Thu May 01, 2008 7:55 am
by PooAs
ok so heres my main players script, enabling him to walk, jump, crawl

Code: Select all
char*key=GetKeyState();
int spd = 5;
yvelocity += gravity;
if(damage > 100)DestroyActor("Event Actor");
if(wt > 0)wt--;
else

if (lay2 == 0)
{
if(key[KEY_LEFT] == 1 && key[KEY_RIGHT] == 0)
{
    if(j == 0 && xvelocity > -spd)xvelocity--;
    if(j == 1)x -= spd;
    if(ld == 1)
    {
        ld = 0;
        af = 1;
    }
    if(af == 1)
    {
        ChangeAnimation("player", "charLeft", FORWARD);
        af = 0;
    }
}
if(key[KEY_LEFT] == 0 && key[KEY_RIGHT] == 1)
{
    if(j == 0 && xvelocity < spd)xvelocity++;
    if(j == 1)x += spd;
    if(ld == 0)
    {
        ld = 1;
        af = 1;
    }
    if(af == 1)
    {
        ChangeAnimation("player", "charRight", FORWARD);
        af = 0;
    }
}
if(key[KEY_LEFT] == 0 && key[KEY_RIGHT] == 0)
{
    af = 1;
    if(ld == 0)ChangeAnimation("player", "charStopLeft", FORWARD);
    else ChangeAnimation("player", "charStopRight", FORWARD);
}
if(key[KEY_LEFT] == 1 && key[KEY_RIGHT] == 1)
{
    af = 1;
    if(ld == 0)ChangeAnimation("player", "charStopLeft", FORWARD);
    else ChangeAnimation("player", "charStopRight", FORWARD);
}
}
if(j == 1 && key[KEY_z] == 1 && lay2 == 0)
{
    if(key[KEY_LEFT] == 1)xvelocity = -spd;
    if(key[KEY_RIGHT] == 1)xvelocity = spd;
    yvelocity = -(gravity * 13);
    j = 0;
}
if(j == 1 && key[KEY_z] == 1 && lay2 == 1)
{
    if(key[KEY_LEFT] == 1)xvelocity = -spd;
    if(key[KEY_RIGHT] == 1)xvelocity = spd;
    yvelocity = -(gravity * 0);
    j = 0;
}
else

if (lay2 == 1)
{
if(key[KEY_LEFT] == 1 && key[KEY_RIGHT] == 0)
{
    if(j == 0 && xvelocity > -spd)xvelocity--;
    if(j == 1)x -= spd;
    if(ld == 1)
    {
        ld = 0;
        af = 1;
    }
    if(af == 1)
    {
        ChangeAnimation("player", "lay_left", FORWARD);
        af = 0;
    }
}
if(key[KEY_LEFT] == 0 && key[KEY_RIGHT] == 1)
{
    if(j == 0 && xvelocity < spd)xvelocity++;
    if(j == 1)x += spd;
    if(ld == 0)
    {
        ld = 1;
        af = 1;
    }
    if(af == 1)
    {
        ChangeAnimation("player", "lay_right", FORWARD);
        af = 0;
    }
}
if(key[KEY_LEFT] == 0 && key[KEY_RIGHT] == 0)
{
    af = 1;
    if(ld == 0)ChangeAnimation("player", "lay_left", FORWARD);
    else ChangeAnimation("player", "lay_right", FORWARD);
}
if(key[KEY_LEFT] == 1 && key[KEY_RIGHT] == 1)
{
    af = 1;
    if(ld == 0)ChangeAnimation("player", "lay_left", FORWARD);
    else ChangeAnimation("player", "lay_right", FORWARD);
}
if(j == 1 && key[KEY_z] == 1)
{
    if(key[KEY_LEFT] == 1)xvelocity = -spd;
    if(key[KEY_RIGHT] == 1)xvelocity = spd;
    yvelocity = -(gravity * 0);
    j = 0;
 
}
}


it all works fine

but when the character is crawling normally when i take my finger off key_down
he stands back up
but
if i holf down right then take my finger off down he keeps staying down??????
how d i prevent this??

btw, key down 'down' make lay2=1
and key up 'down' makes lay2 =2

Re: scripting problem?

PostPosted: Sat May 03, 2008 11:43 pm
by DarkParadox
well, i'm just saying this, but stop using useless elses
it sucks up processing speed doing useless calculations, making the game slower.
EX:
Code: Select all
else

Re: scripting problem?

PostPosted: Sun May 04, 2008 10:57 am
by PooAs
how do ya mean?
which ones?
lol

Re: scripting problem?

PostPosted: Sun May 04, 2008 11:40 am
by DarkParadox
if(j == 1 && key[KEY_z] == 1 && lay2 == 1)
{
if(key[KEY_LEFT] == 1)xvelocity = -spd;
if(key[KEY_RIGHT] == 1)xvelocity = spd;
yvelocity = -(gravity * 0);
j = 0;
}
else//you put nothing after this...

Re: scripting problem?

PostPosted: Mon May 05, 2008 10:11 pm
by PooAs
thanks lol
but this still doesnt fix my problem..