scripting problem?

You must understand the Game Editor concepts, before post here.

scripting problem?

Postby PooAs » Thu May 01, 2008 7:55 am

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
If you try
to fix violence
with violence
you do nothing
but create violence
User avatar
PooAs
 
Posts: 29
Joined: Thu Apr 03, 2008 10:24 am
Score: 3 Give a positive score

Re: scripting problem?

Postby DarkParadox » Sat May 03, 2008 11:43 pm

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
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score

Re: scripting problem?

Postby PooAs » Sun May 04, 2008 10:57 am

how do ya mean?
which ones?
lol
If you try
to fix violence
with violence
you do nothing
but create violence
User avatar
PooAs
 
Posts: 29
Joined: Thu Apr 03, 2008 10:24 am
Score: 3 Give a positive score

Re: scripting problem?

Postby DarkParadox » Sun May 04, 2008 11:40 am

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...
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score

Re: scripting problem?

Postby PooAs » Mon May 05, 2008 10:11 pm

thanks lol
but this still doesnt fix my problem..
If you try
to fix violence
with violence
you do nothing
but create violence
User avatar
PooAs
 
Posts: 29
Joined: Thu Apr 03, 2008 10:24 am
Score: 3 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest