Move until you reach defined objects position....

[b][red]This message was edited by porodoro at 2006-1-7 15:53:15[/red][/b][hr]
label1.left:=455;

x:=Label1.left;

if X>I2.Left
then
begin
i2.Left:=i2.Left +5;

end else begin
i2.Left:=i2.Left -5;
end;

whats wrong with my code ?
when it reachs X it goes crazy!


Comments

  • : [b][red]This message was edited by porodoro at 2006-1-7 15:53:15[/red][/b][hr]
    : label1.left:=455;
    :
    : x:=Label1.left;
    :
    : if X>I2.Left
    : then
    : begin
    : i2.Left:=i2.Left +5;
    :
    : end else begin
    : i2.Left:=i2.Left -5;
    : end;
    :
    : whats wrong with my code ?
    : when it reachs X it goes crazy!
    :
    :
    :
    label1.left:=455;
    x:=Label1.left;
    [red]
    // parenthesis () required. also check for X. is it x or X?
    if (X>I2.Left) then[/red]
    begin
    i2.Left:=i2.Left +5;
    end
    else
    begin
    i2.Left:=i2.Left -5;
    end;


    [b]Atul B. Parmar[/b]

  • : : [b][red]This message was edited by porodoro at 2006-1-7 15:53:15[/red][/b][hr]
    : : label1.left:=455;
    : :
    : : x:=Label1.left;
    : :
    : : if X>I2.Left
    : : then
    : : begin
    : : i2.Left:=i2.Left +5;
    : :
    : : end else begin
    : : i2.Left:=i2.Left -5;
    : : end;
    : :
    : : whats wrong with my code ?
    : : when it reachs X it goes crazy!
    : :
    : :
    : :
    : label1.left:=455;
    : x:=Label1.left;
    : [red]
    : // parenthesis () required. also check for X. is it x or X?
    : if (X>I2.Left) then[/red]
    : begin
    : i2.Left:=i2.Left +5;
    : end
    : else
    : begin
    : i2.Left:=i2.Left -5;
    : end;
    :
    :
    : [b]Atul B. Parmar[/b]
    :
    :
    The parenthesis aren't required in the Pascal language, and also Pascal isn't case-sensitive. Thus the variable names x and X are precisely the same.
  • : : : [b][red]This message was edited by porodoro at 2006-1-7 15:53:15[/red][/b][hr]
    : : : label1.left:=455;
    : : :
    : : : x:=Label1.left;
    : : :
    : : : if X>I2.Left
    : : : then
    : : : begin
    : : : i2.Left:=i2.Left +5;
    : : :
    : : : end else begin
    : : : i2.Left:=i2.Left -5;
    : : : end;
    : : :
    : : : whats wrong with my code ?
    : : : when it reachs X it goes crazy!
    : : :
    : : :
    : : :
    : : label1.left:=455;
    : : x:=Label1.left;
    : : [red]
    : : // parenthesis () required. also check for X. is it x or X?
    : : if (X>I2.Left) then[/red]
    : : begin
    : : i2.Left:=i2.Left +5;
    : : end
    : : else
    : : begin
    : : i2.Left:=i2.Left -5;
    : : end;
    : :
    : :
    : : [b]Atul B. Parmar[/b]
    : :
    : :
    : The parenthesis aren't required in the Pascal language, and also Pascal isn't case-sensitive. Thus the variable names x and X are precisely the same.
    :
    Any ideas on how to solve this?
  • : : : : [b][red]This message was edited by porodoro at 2006-1-7 15:53:15[/red][/b][hr]
    : : : : label1.left:=455;
    : : : :
    : : : : x:=Label1.left;
    : : : :
    : : : : if X>I2.Left
    : : : : then
    : : : : begin
    : : : : i2.Left:=i2.Left +5;
    : : : :
    : : : : end else begin
    : : : : i2.Left:=i2.Left -5;
    : : : : end;
    : : : :
    : : : : whats wrong with my code ?
    : : : : when it reachs X it goes crazy!
    : : : :
    : : : :
    : : : :
    : : : label1.left:=455;
    : : : x:=Label1.left;
    : : : [red]
    : : : // parenthesis () required. also check for X. is it x or X?
    : : : if (X>I2.Left) then[/red]
    : : : begin
    : : : i2.Left:=i2.Left +5;
    : : : end
    : : : else
    : : : begin
    : : : i2.Left:=i2.Left -5;
    : : : end;
    : : :
    : : :
    : : : [b]Atul B. Parmar[/b]
    : : :
    : : :
    : : The parenthesis aren't required in the Pascal language, and also Pascal isn't case-sensitive. Thus the variable names x and X are precisely the same.
    : :
    : Any ideas on how to solve this?
    :
    It will be keep jumping between 2 values unless x is divisable by 5. If you run this code on paper, you'll see it. For example: if X = 8 and Left starts at 4, then this will be the results of the code for each run:
    [code]
    Run Comparison Resulting Left
    1 8 > 4 Left = 9
    2 8 > 9 Left = 4
    3 8 > 4 Left = 9
    4 8 > 9 Left = 4
    5 8 > 4 Left = 9
    6 8 > 9 Left = 4
    etc....
    [/code]
    Since I don't know exactly what you want, I don't know how to change the code: Either remove the else part or have the modifier stored in a variable, of which you change the value if the left reaches a certain value.
  • : : : : : [b][red]This message was edited by porodoro at 2006-1-7 15:53:15[/red][/b][hr]
    : : : : : label1.left:=455;
    : : : : :
    : : : : : x:=Label1.left;
    : : : : :
    : : : : : if X>I2.Left
    : : : : : then
    : : : : : begin
    : : : : : i2.Left:=i2.Left +5;
    : : : : :
    : : : : : end else begin
    : : : : : i2.Left:=i2.Left -5;
    : : : : : end;
    : : : : :
    : : : : : whats wrong with my code ?
    : : : : : when it reachs X it goes crazy!
    : : : : :
    : : : : :
    : : : : :
    : : : : label1.left:=455;
    : : : : x:=Label1.left;
    : : : : [red]
    : : : : // parenthesis () required. also check for X. is it x or X?
    : : : : if (X>I2.Left) then[/red]
    : : : : begin
    : : : : i2.Left:=i2.Left +5;
    : : : : end
    : : : : else
    : : : : begin
    : : : : i2.Left:=i2.Left -5;
    : : : : end;
    : : : :
    : : : :
    : : : : [b]Atul B. Parmar[/b]
    : : : :
    : : : :
    : : : The parenthesis aren't required in the Pascal language, and also Pascal isn't case-sensitive. Thus the variable names x and X are precisely the same.
    : : :
    : : Any ideas on how to solve this?
    : :
    : It will be keep jumping between 2 values unless x is divisable by 5. If you run this code on paper, you'll see it. For example: if X = 8 and Left starts at 4, then this will be the results of the code for each run:
    : [code]
    : Run Comparison Resulting Left
    : 1 8 > 4 Left = 9
    : 2 8 > 9 Left = 4
    : 3 8 > 4 Left = 9
    : 4 8 > 9 Left = 4
    : 5 8 > 4 Left = 9
    : 6 8 > 9 Left = 4
    : etc....
    : [/code]
    : Since I don't know exactly what you want, I don't know how to change the code: Either remove the else part or have the modifier stored in a variable, of which you change the value if the left reaches a certain value.
    :
    Im trying to make a small "game" with 2 snakes (2 labels) hunting each other. Player 1 can move the label 2 with arrow keys. label1 follows the label 1.Each time 1 snake hit each other the caption will increased by 1 char (label1.caption := label1.caption + '<').
    When the hunters(CPU) snake position is (<) less than snake2(p1) then it has to increase its position by 1 otherwise - 1.
    The Snake must follow the object.
    i dont want something like that :

    HUNTER : = PLAYER.X -(length(Hunter.caption) * 20)



  • : : : : : : [b][red]This message was edited by porodoro at 2006-1-7 15:53:15[/red][/b][hr]
    : : : : : : label1.left:=455;
    : : : : : :
    : : : : : : x:=Label1.left;
    : : : : : :
    : : : : : : if X>I2.Left
    : : : : : : then
    : : : : : : begin
    : : : : : : i2.Left:=i2.Left +5;
    : : : : : :
    : : : : : : end else begin
    : : : : : : i2.Left:=i2.Left -5;
    : : : : : : end;
    : : : : : :
    : : : : : : whats wrong with my code ?
    : : : : : : when it reachs X it goes crazy!
    : : : : : :
    : : : : : :
    : : : : : :
    : : : : : label1.left:=455;
    : : : : : x:=Label1.left;
    : : : : : [red]
    : : : : : // parenthesis () required. also check for X. is it x or X?
    : : : : : if (X>I2.Left) then[/red]
    : : : : : begin
    : : : : : i2.Left:=i2.Left +5;
    : : : : : end
    : : : : : else
    : : : : : begin
    : : : : : i2.Left:=i2.Left -5;
    : : : : : end;
    : : : : :
    : : : : :
    : : : : : [b]Atul B. Parmar[/b]
    : : : : :
    : : : : :
    : : : : The parenthesis aren't required in the Pascal language, and also Pascal isn't case-sensitive. Thus the variable names x and X are precisely the same.
    : : : :
    : : : Any ideas on how to solve this?
    : : :
    : : It will be keep jumping between 2 values unless x is divisable by 5. If you run this code on paper, you'll see it. For example: if X = 8 and Left starts at 4, then this will be the results of the code for each run:
    : : [code]
    : : Run Comparison Resulting Left
    : : 1 8 > 4 Left = 9
    : : 2 8 > 9 Left = 4
    : : 3 8 > 4 Left = 9
    : : 4 8 > 9 Left = 4
    : : 5 8 > 4 Left = 9
    : : 6 8 > 9 Left = 4
    : : etc....
    : : [/code]
    : : Since I don't know exactly what you want, I don't know how to change the code: Either remove the else part or have the modifier stored in a variable, of which you change the value if the left reaches a certain value.
    : :
    : Im trying to make a small "game" with 2 snakes (2 labels) hunting each other. Player 1 can move the label 2 with arrow keys. label1 follows the label 1.Each time 1 snake hit each other the caption will increased by 1 char (label1.caption := label1.caption + '<').
    : When the hunters(CPU) snake position is (<) less than snake2(p1) then it has to increase its position by 1 otherwise - 1.
    : The Snake must follow the object.
    : i dont want something like that :
    :
    : HUNTER : = PLAYER.X -(length(Hunter.caption) * 20)
    :
    :
    :
    :
    I would use a formula like this:
    [code]
    Hunter.Left := Player.Left - (Hunter.Canvas.TextWidth(Hunter.Text));
    [/code]
  • : [b][red]This message was edited by porodoro at 2006-1-7 15:53:15[/red][/b][hr]
    : label1.left:=455;
    :
    : x:=Label1.left;
    :
    : if X>I2.Left
    : then
    : begin
    : i2.Left:=i2.Left +5;
    :
    : end else begin
    : i2.Left:=i2.Left -5;
    : end;
    :
    : whats wrong with my code ?
    : when it reachs X it goes crazy!
    :
    :
    :
    try to use :

    if X>I2.Left
    then
    begin
    i2.Left:=i2.Left +5;

    end else begin
    i2.Left:=X;
    end;


  • : : Im trying to make a small "game" with 2 snakes (2 labels) hunting each other. Player 1 can move the label 2 with arrow keys. label1 follows the label 1.Each time 1 snake hit each other the caption will increased by 1 char (label1.caption := label1.caption + '<').
    : : When the hunters(CPU) snake position is (<) less than snake2(p1) then it has to increase its position by 1 otherwise - 1.
    : : The Snake must follow the object.
    : : i dont want something like that :
    : :
    : : HUNTER : = PLAYER.X -(length(Hunter.caption) * 20)
    : :
    : :
    : :
    : :
    : I would use a formula like this:
    : [code]
    : Hunter.Left := Player.Left - (Hunter.Canvas.TextWidth(Hunter.Text));
    : [/code]
    :
    not exactly what i wanted but i can modify it a bit so it will fit my needs.

    I'll use a bool var to check whether a keybutton pressed.
    If the result is false then i will use your code to follow it,
    otherwise hunter.x:=hunter.x +4; //to be able to hit the 1st player
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories