Log in

View Full Version : hey it doesnt work



wantonman
12-11-2012, 01:09 AM
hey guys here i have an example that doesnt work... this is my basic script but theres an issue, i thought it was scar but its not working even in simba...
here ill try to elaborate as much as possible

var
buf,img,xpos,ypos:integer;
procedure procedure2(pos,int:integer); //rite here... the int as you can
begin //see , okay well the calculation
pos:=int //does not happen, i can supply
FastDrawTransparent(xpos,ypos,img,buf) //more examples but if you
DrawBitmapDebugImg(buf) //writeln(pos)somewhere in there
end; //you can see nothing happens...
function function1:integer;
var
i:integer;
begin
for i:=37 to 40 do
begin
if IsKeyDown(i)then
result:=i;
end;
end;
procedure procedure1;
begin
case function1 of
37:begin
writeln('1')
procedure2(xpos,xpos-1)
end;
38:begin
writeln('2')
procedure2(ypos,ypos-1)
end;
39:begin
writeln('3')
procedure2(xpos,xpos+1)
end;
40:begin
writeln('4')
procedure2(ypos,ypos-1)
end;
end;
end;
begin
img:=BitmapFromString(10,10,'')
buf:=CreateBitmap(300,300)
FastDrawClear(img,255)
xpos:=150
ypos:=150
displaydebugimgwindow(300,300)
procedure2(xpos,xpos+0)
repeat
procedure1
until IsKeyDown(27)
end.

kazhual
12-11-2012, 09:37 AM
procedure2 is kinda working, but:
xpos / ypos will become 149, 150 or 151
The variables xpo, ypos is never stored
Meaning: your program only shifts the pixel by one, but dont worry.

Ive got it working:



program Testing;

{$DEFINE SMART}

var
buf, img, xpos ,ypos : Integer ;

procedure procedure2 ;
begin

FastDrawTransparent( xpos, ypos, img, buf )
DrawBitmapDebugImg( buf )

end;

function function1 : integer ;
var
i : Integer ;
begin

for i:=37 to 40 do begin
if IsKeyDown(i)then
Result:=i;
end;
end;

procedure procedure1;
begin

case function1 of

37:begin
writeln('left')
dec( xpos ) ;
procedure2 ;
end;

38:begin
writeln('Up')
dec( ypos );
procedure2 ;
end;

39:begin
writeln('Right')
inc( xpos ) ;
procedure2 ;
end;

40:begin
writeln('Down')
inc( ypos );
procedure2 ;
end;

end;

end;

begin

img:=BitmapFromString(10,10,'') ;
buf:=CreateBitmap(300,300) ;
FastDrawClear(img,255) ;
xpos:=150 ;
ypos:=150 ;
displaydebugimgwindow(300,300) ;
procedure2 ;

repeat
procedure1
until IsKeyDown(27)

FreeBitmap( buf ) ;

end.

NKN
12-11-2012, 11:45 AM
procedure procedure2(pos,int:integer); //rite here... the int as you can
begin //see , okay well the calculation
pos:=int //does not happen, i can supply
FastDrawTransparent(xpos,ypos,img,buf) //more examples but if you
DrawBitmapDebugImg(buf) //writeln(pos)somewhere in there
end;

Change to:

procedure procedure2(pos:integer); //rite here... the int as you can
begin //see , okay well the calculatio
FastDrawTransparent(xpos,ypos,img,buf) //more examples but if you
DrawBitmapDebugImg(buf) //writeln(pos)somewhere in there
end;

Now, when you are like procedure2(10);
Pos = 10; You had an extra variable in there for no reason.

kazhual
12-11-2012, 11:52 AM
procedure procedure2(pos,int:integer); //rite here... the int as you can
begin //see , okay well the calculation
pos:=int //does not happen, i can supply
FastDrawTransparent(xpos,ypos,img,buf) //more examples but if you
DrawBitmapDebugImg(buf) //writeln(pos)somewhere in there
end;

Change to:

procedure procedure2(pos:integer); //rite here... the int as you can
begin //see , okay well the calculatio
FastDrawTransparent(xpos,ypos,img,buf) //more examples but if you
DrawBitmapDebugImg(buf) //writeln(pos)somewhere in there
end;

Now, when you are like procedure2(10);
Pos = 10; You had an extra variable in there for no reason.

The script will stil get a xpos / ypos with the following values: 149-150-151.
xpos and ypos are relative from 150,150

NKN
12-11-2012, 11:55 AM
The script will stil get a xpos / ypos with the following values: 149-150-151.
xpos and ypos are relative from 150,150
Okay...?
What's your point?
I fixed what he asked.

kazhual
12-11-2012, 12:00 PM
Okay...?
What's your point?
I fixed what he asked.

Yes i know,
But the sqaure wasn't moving ( as i asumend he wanted to move the square )

NKN
12-11-2012, 12:01 PM
repeat
procedure1
until IsKeyDown(27)


If you're using SMART, this will never end. (Your inputs are blocked in SMART IIRC)


As with this: function function1:integer;
var
i:integer;
begin
for i:=37 to 40 do
begin
if IsKeyDown(i)then
result:=i;
end;
end; It'll never even go off

kazhual
12-11-2012, 12:04 PM
Well i thaught it would fail but i tried it and it works.

Try it out yourself:




program Testing;
{$DEFINE SMART}

var
buf, img, xpos ,ypos : Integer ;

procedure procedure2 ;
begin

FastDrawTransparent( xpos, ypos, img, buf )
DrawBitmapDebugImg( buf )

end;

function function1 : integer ;
var
i : Integer ;
begin

for i:=37 to 40 do begin
if IsKeyDown(i)then
Result:=i;
end;
end;

procedure procedure1;
begin

case function1 of

37:begin
writeln('left')
dec( xpos ) ;
procedure2 ;
end;

38:begin
writeln('Up')
dec( ypos );
procedure2 ;
end;

39:begin
writeln('Right')
inc( xpos ) ;
procedure2 ;
end;

40:begin
writeln('Down')
inc( ypos );
procedure2 ;
end;

end;

end;

begin

img:=BitmapFromString(10,10,'') ;
buf:=CreateBitmap(300,300) ;
FastDrawClear(img,255) ;
xpos:=150 ;
ypos:=150 ;
displaydebugimgwindow(300,300) ;
procedure2 ;

repeat
procedure1
until IsKeyDown(27)

FreeBitmap( buf ) ;

end.

NKN
12-11-2012, 12:06 PM
Well i thaught it would fail but i tried it and it works.

Try it out yourself:




program Testing;
{$DEFINE SMART}

var
buf, img, xpos ,ypos : Integer ;

procedure procedure2 ;
begin

FastDrawTransparent( xpos, ypos, img, buf )
DrawBitmapDebugImg( buf )

end;

function function1 : integer ;
var
i : Integer ;
begin

for i:=37 to 40 do begin
if IsKeyDown(i)then
Result:=i;
end;
end;

procedure procedure1;
begin

case function1 of

37:begin
writeln('left')
dec( xpos ) ;
procedure2 ;
end;

38:begin
writeln('Up')
dec( ypos );
procedure2 ;
end;

39:begin
writeln('Right')
inc( xpos ) ;
procedure2 ;
end;

40:begin
writeln('Down')
inc( ypos );
procedure2 ;
end;

end;

end;

begin

img:=BitmapFromString(10,10,'') ;
buf:=CreateBitmap(300,300) ;
FastDrawClear(img,255) ;
xpos:=150 ;
ypos:=150 ;
displaydebugimgwindow(300,300) ;
procedure2 ;

repeat
procedure1
until IsKeyDown(27)

FreeBitmap( buf ) ;

end.
Giving the answer is cheating. :(
Help them learn it, so they understand, not just copy/paste

kazhual
12-11-2012, 12:10 PM
I did mention why I didn't work and gave an solution,
Next time I won't cheat :cool: