
-----------------------------------
vi3t_4ever
Sat May 28, 2005 12:24 pm

How Do U Make A Box Go Up and Down
-----------------------------------
Hey...im new here...i was just wondering if anyone can help me asap....i want to know how can u get a box moving up and down...like a elevator for the CN tower...plz help....I REALLY NEED THIS ASAP!!!!!!!!!!!

-----------------------------------
StarGateSG-1
Sat May 28, 2005 12:51 pm


-----------------------------------
I need more information, do you control the box?
for one. Second we do not right code for you here this is were you get help!

-----------------------------------
vi3t_4ever
Sat May 28, 2005 12:57 pm


-----------------------------------
ok...first...i need it to go up by it self...second...i know that...i just want to know wat code can can move the box up by itslef....u dont need to do it for me...and i just need something basic...not so difficult like the other ones....my teacher didnt teach me those

-----------------------------------
StarGateSG-1
Sat May 28, 2005 1:03 pm


-----------------------------------
Ok clear the box and redraw it in a loop.

-----------------------------------
Cervantes
Sat May 28, 2005 1:18 pm


-----------------------------------
If you want to move a box around, you cannot use hardcoded values for the x and y coordinates of the box.  That is, code such as this,

Draw.FillBox (100, 100, 200, 200, black)

will not move a box around, no matter how many times you draw it.  So much should be self-evident.
To move the box, you need the x and y coordinates to change.  Thus, we cannot hardcode integers such as 100, 100, 200, 200.  Instead, we need variables.

var x1 := 100  %same as var x : int := 100
var y2 := 100
var x2 := 200
var y2 := 200
Draw.FillBox (x1, y1, x2, y2, black)

This does the same as the code above.  However, we could now change the variables, and thereby change the position of the box.
If we want to actually move the box, we need to draw the box in one position, then clear that image and draw it in another position, and repeat this process over and over.  To do this, we use a loop.

var x1 := 100  %same as var x : int := 100
var y2 := 100
var x2 := 200
var y2 := 200
loop
     y1 += 1  %same as y1 := y1 + 1
     y2 += 1
     cls
     Draw.FillBox (x1, y1, x2, y2, black)
    delay (10)
end loop

Yay, the box moves up.  Now, the thing is we probably don't want to have to incriment two variables just to move one box.  Let's change the format of this a bit:

var x := 100
var y := 100
var width := 100
var height := 100
loop
    y += 1
    cls
    Draw.FillBox (x, y, x + width, y + height, black)
    delay (10)
end loop

Now we only have to worry about one coordinate position, and with that the box will position itself.
Now, to make this look smoother, we need to use View.Update.  Here's how:

View.Set ("offscreenonly")  %this must be typed exactly like this.  
% Also, it must be placed before we do any View.Updating
var x := 100
var y := 100
var width := 100
var height := 100
loop
    y += 1
    cls
    Draw.FillBox (x, y, x + width, y + height, black)
    View.Update  %flip everything from the back buffer to the fron buffer
    %this gives the illusion of everything being drawn simotaneously, though really, everything
    %is drawn in the back buffer at different times and then flipped onto the front buffer (the screen)
    delay (10)
end loop

There are tutorials on these topics (View.Update, loops, variables, basic graphics) in the Turing Tutorials forum.  Search for them if you wish.

-----------------------------------
axej
Wed Jun 08, 2005 5:45 pm


-----------------------------------
search is now my new best friend! :lol: 
ok i agree this tread is old, but how do i make it stop at a certain height?

-----------------------------------
Cervantes
Wed Jun 08, 2005 5:57 pm


-----------------------------------
There are a few ways.  The method you choose depends on what else is happening in your program.

Method 1

View.Set ("offscreenonly")
var x := 100
var width := 100
var height := 100
for y : 100 .. 300
    cls
    Draw.FillBox (x, y, x + width, y + height, black)
    View.Update
    delay (10)
end for

This method I detest.  If you want to do ANYTHING else at the same time as moving a box (such as moving a different box, drawing stuff, processing stuff, getting input, etc.) you should not use this method.

Method 2

View.Set ("offscreenonly")
var x := 100
var y := 100
var width := 100
var height := 100
loop
    y += 1
    cls
    Draw.FillBox (x, y, x + width, y + height, black)
    View.Update
    delay (10)
   
    exit when y >= 300
end loop

This method is much better.  It allows the "object" to behave as its properties define, all while in a general loop.  This allows other "objects" to be behaving as they should at the same time.

Method 3

View.Set ("offscreenonly")
var x := 100
var y := 100
var vy := 1         %velocity of the box in the y plane
var width := 100
var height := 100
loop

    y += vy

    if y >= 300 then
        vy := 0
    end if
    
    cls
    Draw.FillBox (x, y, x + width, y + height, black)
    View.Update
    delay (10)

end loop

This method is essentially the same as Method 2, except it does not force us to exit when the box reaches a certain point.  This allows the loop to have some other means of exitting.

-----------------------------------
axej
Wed Jun 08, 2005 6:09 pm


-----------------------------------
thnx 
method one is so easy! wow. 
i think i'll use that so i won't have to explain everything to my teacher :lol:  i don't need to do other stuff while the box moves.  parallel put still works while that happens right?
btw: "offscreenonly" stops flickering right?

-----------------------------------
Cervantes
Wed Jun 08, 2005 6:18 pm


-----------------------------------
thnx 
method one is so easy! wow. 
i think i'll use that so i won't have to explain everything to my teacher :lol:  i don't need to do other stuff while the box moves.  parallel put still works while that happens right?
btw: "offscreenonly" stops flickering right?
parallelput will still work, but you'll have to code it directly into the for loop, which may or may not be so pleasent.
offscreenonly does not stop the flickering.  To stop it, you need to set offscreenonly, then use View.Update (in the correct place, if you want to see what you intend to show).

-----------------------------------
axej
Wed Jun 08, 2005 8:24 pm


-----------------------------------
thnx
what do you think of my uber simple culminating that nobody in my class has started yet?
*Edit* if your wondering why the "%parallelput", its because the actual thingy im building isn't really wired yet.  i still have to get that seven segment display working. :roll:

ok, second addition. the locate thingy is messed it doesn't do anything except end the program which its no tsupposed to do, any er suggestions?

the code looks noobish too i just realised that, but its easy to explain it to  my teacher :)

-----------------------------------
Drakain Zeil
Wed Jun 08, 2005 9:53 pm


-----------------------------------
You can shorten that code by... I'd say about 4/5ths.

Use a for..next loop to increment that one number that you add 50 to each time.

Edit: Aslo, I think you only need to set the View.Set once.

Edit again!: I just took a real look into your code, and oh boy did you ever over-do it!.
Try this...


put "Welcome to The Office Building where employees get stuffed into cubicles, please use the elevator since we have no stairs"
%We don't need delays here...
cls

var flr :int
loop
   put"please select floor number (1-6)"
   get flr
   exit when flr =1 OR flr =2 OR flr =3 OR flr =4 OR flr =5 OR flr = 6
cls
%We don't need delays here...
  locate (150,200: int)
  put "Enter a number between 1 and 6."
%We don't need delays here...
cls
end loop

View.Set ("offscreenonly")

var x := 100
var width := 100
var height := 100
for y : 0 .. (flr*50) %Use math, it's good for you.
    cls
    Draw.FillBox (x, y, x + width, y + height, black)
    View.Update
    delay (20)
end for 


-----------------------------------
axej
Wed Jun 08, 2005 9:56 pm


-----------------------------------
ok, how about the locate part?

-----------------------------------
[Gandalf]
Thu Jun 09, 2005 3:54 pm


-----------------------------------
It's alright.

(150,200: int) 
should be
(150,200) 
don't know why you have the :int...

-----------------------------------
axej
Thu Jun 09, 2005 4:02 pm


-----------------------------------
i figured that one out already thanks

-----------------------------------
axej
Thu Jun 09, 2005 4:22 pm


-----------------------------------
ok i have another problem i can't get my seven segment display to work can anyone help me?

-----------------------------------
Drakain Zeil
Thu Jun 09, 2005 5:35 pm


-----------------------------------
Blah, I just cut/paste around his code, didn't look at vars.

What is the problem then? Be specific, don't just say "i need help." That's great, but I have no idea what you need.

-----------------------------------
axej
Thu Jun 09, 2005 6:23 pm


-----------------------------------
&#8238;*problem solved*

-----------------------------------
axej
Fri Jun 10, 2005 7:57 pm


-----------------------------------
ok problem three how do i get the progarm to output the floors as it goes along instead of just displaying the final floor at the very end?

-----------------------------------
ZeroPaladn
Sat Jun 11, 2005 8:45 am


-----------------------------------
ya, im a newb but i know a newbish way to fix your problem. just when the "elevator" reaches a certain co-ordinates make it display the floor.
i'll post an example


setscreen ("graphics:200,400")
View.Set ("offscreenonly")


for i : 1..400
cls
drawfillbox (90, i, 110, i+20, black)
if i = 100 then 
put "1"
delay (200)
else i = 200 then
put "2"
delay (200)
else i = 300 then
put "3" 
delay (300)
else i= 400 then
put "top floor"
View.Update
end for

i used Turing 3 for this (its all i got  :cry: ) so if the code doesn't work then dont blame me blame my turing!

EDIT

Remind me again why were MAKING the program for you? :x

-----------------------------------
Cervantes
Sat Jun 11, 2005 9:09 am


-----------------------------------
Why make the for loop count from 1 to 400 when all you need is 1 to 4?


setscreen ("graphics:200,450, offscreenonly")
for i : 1 .. 4
    cls
    drawfillbox (90, i * 100, 110, i * 100 + 20, black)
    locate (1, 1)
    put "level ", i
    View.Update
    delay (1000)
end for

Also, you were missing an end if in your code, and you had lots of else.  You can only have one per if statement.

-----------------------------------
axej
Sat Jun 11, 2005 9:44 am


-----------------------------------
what if i wanted to make it output through the parallel port like to a seven segment display?

oh and i fixed my code.import GUI

procedure Use

cls

var x := 100 
var width := 100 
var height := 100 
var flr :int

loop
parallelput(4)
locate (10,15)
put"please select floor number (1-6) you are currently on floor 0"
get flr
exit when flr =1 or flr =2 or flr =3 or flr =4 or flr =5 or flr = 6
cls
    locate (10,15)
    put "You're a n00b since there are no floors higher than 6"
    delay (2000)
cls
end loop

View.Set ("offscreenonly") 
for y : 0 .. (flr*50) 
    cls 
    Draw.FillBox (x, y, x + width, y + height, black) 
    View.Update 
    delay (50) 
end for 

if flr=1 then
    parallelput (2+4+16+32+64)
end if

if flr=2 then
    parallelput (1+32)
end if

if flr=3 then
    parallelput (2+32)
end if

if flr=4 then
    parallelput (2+16+64)
end if

if flr=5 then
    parallelput (2+8)
end if

if flr=6 then
    parallelput (8)
   
end if

View.Set("nooffscreenonly") 

    delay (2000)
    cls
        var button4:int:=GUI.CreateButton(200,18,0,"leave",GUI.Quit)
        var button3:int:=GUI.CreateButton(19,20,0,"Take the elevator again!",Use)    
   locate(10,15)
    put "thank you for taking the elevator"


loop
exit when GUI.ProcessEvent 
end loop

end Use


var button1:int:=GUI.CreateButton(50,18,0,"Take the elevator!",Use) 
var button2:int:=GUI.CreateButton(200,18,0,"leave",GUI.Quit) 
put "Welcome to The Office Building where employees get stuffed into cubicles, please use the elevator since we have no stairs"

loop
exit when GUI.ProcessEvent 
end loop


-----------------------------------
Drakain Zeil
Sat Jun 11, 2005 11:17 am


-----------------------------------
what if i wanted to make it output through the parallel port like to a seven segment display?

oh and i fixed my code.import GUI

procedure Use

cls

var x := 100 
var width := 100 
var height := 100 
var flr :int

loop
parallelput(4)
locate (10,15)
put"please select floor number (1-6) you are currently on floor 0"
get flr
exit when flr =1 or flr =2 or flr =3 or flr =4 or flr =5 or flr = 6
cls
    locate (10,15)
    put "You're a n00b since there are no floors higher than 6"
    delay (2000)
cls
end loop

View.Set ("offscreenonly") 
for y : 0 .. (flr*50) 
    cls 
    Draw.FillBox (x, y, x + width, y + height, black) 
    View.Update 
    delay (50) 
end for 

if flr=1 then
    parallelput (2+4+16+32+64)
end if

if flr=2 then
    parallelput (1+32)
end if

if flr=3 then
    parallelput (2+32)
end if

if flr=4 then
    parallelput (2+16+64)
end if

if flr=5 then
    parallelput (2+8)
end if

if flr=6 then
    parallelput (8)
   
end if

View.Set("nooffscreenonly") 

    delay (2000)
    cls
        var button4:int:=GUI.CreateButton(200,18,0,"leave",GUI.Quit)
        var button3:int:=GUI.CreateButton(19,20,0,"Take the elevator again!",Use)    
   locate(10,15)
    put "thank you for taking the elevator"


loop
exit when GUI.ProcessEvent 
end loop

end Use


var button1:int:=GUI.CreateButton(50,18,0,"Take the elevator!",Use) 
var button2:int:=GUI.CreateButton(200,18,0,"leave",GUI.Quit) 
put "Welcome to The Office Building where employees get stuffed into cubicles, please use the elevator since we have no stairs"

loop
exit when GUI.ProcessEvent 
end loop


Why'd you use parallelput?

-----------------------------------
axej
Sat Jun 11, 2005 2:13 pm


-----------------------------------
i'm supposed to use turing with the parallel prot to control something. in my case its a seven segment display to show the user which floor there on

-----------------------------------
axej
Sat Jun 11, 2005 7:08 pm


-----------------------------------
Remind me again why were MAKING the program for you?  :x 

your not MAKING the program for me and you never will. you're pointing out stupid things in MY program and helping me with things i don't knoe how to do and btw don't use caps please. :roll:
&#8238;this is fun
