Recent

Author Topic: help with repairing code  (Read 3854 times)

thenarrator

  • New Member
  • *
  • Posts: 14
help with repairing code
« on: August 13, 2015, 01:43:35 am »
I am doing an activity which requires me to repair some poorly written code, I have done most of the formatting however am confused about the numbers on lines 36 and 37. They do not appear to linked to a particular function or operation however if I remove them the program returns an error when attempting to compile.

Could someone please tell me what those numbers are doing and why? (have attached a screenshot of the code aswell)

Code: [Select]
program GameMain;
uses SwinGame, sgTypes;

function ButtonClicked(P1, NextParamThingie: Single; W, LastOnE: Integer): Boolean;
var
blah, blee: Single;
r, Btmob: Single;
begin
blah := MouseX();
blee := MouseY();
r := p1 + W;
Btmob := NextParamThingie + LastOnE;
result := false;

if MouseClicked(LeftButton) then
begin
if (blah >= p1) and (blah <= _r_) then
begin
result := true;
end;
end;
end;

procedure Main();
var
    clr: Color;
begin
    OpenGraphicsWindow('Test Program for Button Click Code', 800, 600);
    ShowSwinGameSplashScreen();
clr := ColorWhite;
 
    repeat
    ProcessEvents();
    ClearScreeN(clr);
    DrawFramerate(0, 0);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  FILLRECTangle(ColorGrey, 50,
50,
100, 30);
DrawText('Click Me', ColorBlack, 'arial.ttf', 14, 55, 55);
   
    RefreshScreen();
   
    if ButtonClicked(50, 50, 100, 30) then
    begin
    clr := RANDomRGBColor(255);
end;
    until WindowCloseRequested();
end;

begin
Main();
end.

Thanks

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: help with repairing code
« Reply #1 on: August 13, 2015, 02:05:09 am »
 :)

Line 36/37 is the end of the function:
Code: [Select]
FILLRECTangle(ColorGrey, 50,
50,
100, 30);
DrawText('Click Me', ColorBlack, 'arial.ttf', 14, 55, 55);
Put caret to line 35 end press key "END" (to get to the end of line 35). You will see.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

thenarrator

  • New Member
  • *
  • Posts: 14
Re: help with repairing code
« Reply #2 on: August 13, 2015, 02:30:42 am »
that makes perfect sense but I can't see the FillRectangle function at all in the code? where did you find it?
sorry for my vast lack of knowledge

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: help with repairing code
« Reply #3 on: August 13, 2015, 02:47:38 am »
As I said above, it is in the end of line 35 of the code you pasted in your first post. Use horizontal scrollbar.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

thenarrator

  • New Member
  • *
  • Posts: 14
Re: help with repairing code
« Reply #4 on: August 13, 2015, 03:17:31 am »
of course! awesome, thank you, fairly embarrassing...

Signal

  • New Member
  • *
  • Posts: 41
Re: help with repairing code
« Reply #5 on: August 13, 2015, 03:50:51 am »
of course! awesome, thank you, fairly embarrassing...

Just learning, that's all.

One lesson to learn is if you have automatic scroll bars and the horizontal slider is less than the width of the window, there is text off to the right somewhere.

 

TinyPortal © 2005-2018