Exiting a script

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

Exiting a script

Postby motorollin » Sun Aug 12, 2007 2:27 pm

How do I exit a script before it gets to the end? I have looked in the scripting reference but I can't find a command to do it.

TIA
moto
motorollin
 
Posts: 54
Joined: Sun Aug 12, 2007 8:05 am
Score: 1 Give a positive score

Postby d-soldier » Sun Aug 12, 2007 3:57 pm

I don't understand... give a "for example".
User avatar
d-soldier
 
Posts: 703
Joined: Sun Apr 08, 2007 2:13 am
Score: 61 Give a positive score

Postby motorollin » Sun Aug 12, 2007 4:03 pm

Code: Select all
char *key = GetKeyState();

if(key[KEY_GP2X_BUTTON_RIGHT])
{
x = x + 5;
end;
}

//checks for other directions go here


The "end" command is the one I am looking for - to break execution of the script at that point.
motorollin
 
Posts: 54
Joined: Sun Aug 12, 2007 8:05 am
Score: 1 Give a positive score

Postby d-soldier » Sun Aug 12, 2007 4:54 pm

ahhh, i see... If you are using an IF statement (which you are) the script should execute that section of the script and stop, because the IF variable following won't be valid. Like if you're saying "if x == 2, then do this, and if x == 3 do this, etc. If X=2, it will only execute that part of the IF script and not continue to the next because X doesn't = 3... Seems like too easy of an answer, maybe it doesn't help given the circumstances you are scripting?
User avatar
d-soldier
 
Posts: 703
Joined: Sun Apr 08, 2007 2:13 am
Score: 61 Give a positive score

Postby motorollin » Sun Aug 12, 2007 5:11 pm

That does help somewhat. I might be able to get around it by using else statements. The problem I have is that I can't have a separate event for each direction on the GP2X joystick because I can't press that 'key' when I create the event. So I had to create an 'any key' event and use IF statements to check for each direction on the GP2X joystick. So my 'any key' event is a string of IF statements which check for each direction and move the sprite accordingly.

The problem comes with diagonals. When it checks, for example, for diagonal down-and-right, it moves the sprite in that direction, but then when it checks for the down key this also gets triggered. It does the same thing when it comes to check for the right direction. The upshot is that the sprite moves twice as quickly in diagonal directions as it does in horizontal and vertical directions.

I suppose I can code around this by doing this:


Code: Select all

if (key[key_GP2X_BUTTON_UPRIGHT])
{
  x = x + 10;
  y = y - 10;
} else if (key[key_GP2X_BUTTON_UPLEFT])
{
  x = x - 10;
  y = y - 10;
} else if (key[key_GP2X_BUTTON_DOWNRIGHT])
{
  x = x + 10;
  y = y + 10;
} else if (key[key_GP2X_BUTTON_DOWNLEFT])
{
  x = x - 10;
  y = y + 10;
} else if (key[key_GP2X_BUTTON_UP])
{
  y = y - 10;
} else if (key[key_GP2X_BUTTON_DOWN])
{
  y = y + 10;
} else if (key[key_GP2X_BUTTON_LEFT])
{
  x = x - 10;
} else if (key[key_GP2X_BUTTON_RIGHT])
{
  x = x + 10;
}



I assume that once it finds a statement which is true (i.e. that button is pressed) it will execute the code within the else statement and then stop checking the other else conditions? Or will it check them anyway in case any of the rest of them are true?
motorollin
 
Posts: 54
Joined: Sun Aug 12, 2007 8:05 am
Score: 1 Give a positive score

Postby motorollin » Sun Aug 12, 2007 5:39 pm

Ok this doesn't seem to work. It still moves twice as quickly in diagonal directions than it does in horizontal or vertical directions. It is intermittent though and seems to occur more often if I quickly go from a horizontal or vertical direction to a diagonal one. Any ideas?
motorollin
 
Posts: 54
Joined: Sun Aug 12, 2007 8:05 am
Score: 1 Give a positive score

Postby d-soldier » Sun Aug 12, 2007 5:46 pm

You may need to wait until one of the gp2x guys gets on here...
User avatar
d-soldier
 
Posts: 703
Joined: Sun Apr 08, 2007 2:13 am
Score: 61 Give a positive score

Postby motorollin » Sun Aug 12, 2007 6:11 pm

I'll also contact berighteous on the gp32 forum as I know he uses GE to develop GP2X games. The controls in his OidZone game seem ok so I'll contact him and see if he would share his key-capture code.

I have just tried this:

Code: Select all
if(key[KEY_GP2X_BUTTON_DOWNLEFT] & !key[KEY_GP2X_BUTTON_DOWN] & !key[KEY_GP2X_BUTTON_LEFT])
{
    ChangeAnimation("Event Actor", "playerdownleft", FORWARD);
    x = x - 10;
    y = y + 10;
}


to see if it would work to capture ONLY a diagonal, but it is still intermittently too fast in diagonal directions.
motorollin
 
Posts: 54
Joined: Sun Aug 12, 2007 8:05 am
Score: 1 Give a positive score

Re: Exiting a script

Postby makslane » Sun Aug 12, 2007 7:13 pm

motorollin wrote:How do I exit a script before it gets to the end


Use the return command:

Code: Select all
return;
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby motorollin » Sun Aug 12, 2007 7:19 pm

Ahhh, return, thanks :D I'm not sure it will help now though since berighteous on the gp32 forum has said that my problem might be due to the flakiness of the GP2X joystick :shock:
motorollin
 
Posts: 54
Joined: Sun Aug 12, 2007 8:05 am
Score: 1 Give a positive score

Postby motorollin » Sun Aug 12, 2007 9:13 pm

Berighteous helped me out on the gp2x forum. The following code works great:

Code: Select all
if ( key[KEY_w] & key[KEY_a] | key[KEY_GP2X_BUTTON_UPLEFT] )
{
    ChangeAnimation("Event Actor", "playerupleft", FORWARD);
    angle=135;
    directional_velocity=speed;
    return;
}

if ( key[KEY_a] & key[KEY_s] | key[KEY_GP2X_BUTTON_DOWNLEFT] )
{
    ChangeAnimation("Event Actor", "playerdownleft", FORWARD);
    angle=225;
    directional_velocity=speed;
    return;
}

if ( key[KEY_s] & key[KEY_d] | key[KEY_GP2X_BUTTON_DOWNRIGHT] )
{
    ChangeAnimation("Event Actor", "playerdownright", FORWARD);
    angle=315;
    directional_velocity=speed;
    return;
}

if ( key[KEY_w] & key[KEY_d] | key[KEY_GP2X_BUTTON_UPRIGHT] )
{
    ChangeAnimation("Event Actor", "playerupright", FORWARD);
    angle=45;
    directional_velocity=speed;
    return;
}

if ( key[KEY_w] | key[KEY_GP2X_BUTTON_UP] )
{
    ChangeAnimation("Event Actor", "playerup", FORWARD);
    angle=90;
    directional_velocity=speed;
    return;
}

if ( key[KEY_s] | key[KEY_GP2X_BUTTON_DOWN] )
{
    ChangeAnimation("Event Actor", "playerdown", FORWARD);
    angle=270;
    directional_velocity=speed;
    return;
}

if ( key[KEY_a] | key[KEY_GP2X_BUTTON_LEFT] )
{
    ChangeAnimation("Event Actor", "playerleft", FORWARD);
    angle=180;
    directional_velocity=speed;
    return;
}

if ( key[KEY_d] | key[KEY_GP2X_BUTTON_RIGHT] )
{
    ChangeAnimation("Event Actor", "playerright", FORWARD);
    angle=0;
    directional_velocity=speed;
    return;
}
motorollin
 
Posts: 54
Joined: Sun Aug 12, 2007 8:05 am
Score: 1 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest