Posted: Tue Sep 13, 2005 7:53 pm Post subject: My program's not working..
Hello guys.
I'm new here, first post actually. I'm new to Turing, in Grade 10 right now. I started learning Turing before, but then I gave up.. Anyways, I've taught myself a bunch of things with the help of the tutorials here (arrays, draw commands, loops, ifs, cases, etc.)
I was trying to do movement with keydown and I wrote the code and all and it ran but I after whatever I pressed, my circle didn't move.
code:
var chars : array char of boolean
var ballx, bally : int := 300
color (0)
colorback (7)
drawfill (0,0,7,7)
drawfilloval (ballx,bally,18,18,55)
locate (1,25)
put "Ball Movement. By: Adeel Syed."
loop
setscreen ("offscreenonly")
View.Update
Input.KeyDown (chars)
if chars (KEY_UP_ARROW)
then bally := bally + 2
elsif chars (KEY_DOWN_ARROW)
then bally := bally - 2
elsif chars (KEY_LEFT_ARROW)
then ballx := ballx - 2
elsif chars (KEY_RIGHT_ARROW)
then ballx := ballx + 2
elsif chars (KEY_RIGHT_ARROW) and chars (KEY_UP_ARROW)
then ballx := ballx + 2
bally := bally + 2
elsif chars (KEY_RIGHT_ARROW) and chars (KEY_DOWN_ARROW)
then ballx := ballx + 2
bally := bally - 2
elsif chars (KEY_LEFT_ARROW) and chars (KEY_UP_ARROW)
then ballx := ballx - 2
bally := bally + 2
elsif chars (KEY_LEFT_ARROW) and chars (KEY_DOWN_ARROW)
then ballx := ballx - 2
bally := bally - 2
end if
end loop
That's what I wrote, very noobish indeed. And it won't work. Please don't flame me... Just point out the stupid mistake(s) I am making.
Thank you,
Terror Byte.
Sponsor Sponsor
Cervantes
Posted: Tue Sep 13, 2005 8:05 pm Post subject: (No subject)
Welcome to the forums!
A couple of things:
We prefer if questions are posted in the Help forum, rather than in the Tutorial thread corresponding to the topic in question.
There is no need to put the "setscreen ("offscreenonly")" within your loop. It need only be stated once.
If you want your circle to move, you need to put the code to draw the circle inside the loop. That is crucial.
Instead of using a long if .. elsif .. end if structure to account for diagonals, use four if .. end if statements. There are two reasons you need to do this. First, the diagonal if statements will never be reached, the way you've got it set up. If you are pressing up and left, then the test far above that specific test will be passed, because you are pressing the up arrow. Thus, up and left will never be tested. You could reverse the order of things, if you wanted. Or to make things easier, you do this:
code:
if chars (KEY_UP_ARROW) then
bally += 2 % same as bally := bally + 2
end if
if chars (KEY_DOWN_ARROW) then
bally -= 2
end if
if chars (KEY_RIGHT_ARROW) then
ballx += 2
end if
if chars (KEY_LEFT_ARROW) then
ballx -= 2
end if
This will account for everything, and will also solve the problem of hitting up and down resulting in moving up.
If you have further questions, post them here (for this specific case only!) and I or another mod will move these posts to the Turing Help forum so they can have their own thread.
Terror Byte
Posted: Tue Sep 13, 2005 9:18 pm Post subject: (No subject)
Ah well that makes sense
The circle is refreshed every time inside the loop..
There's still a problem though. The circle leaves a trail, isn't View.Update supposed to take care of that?
EDIT: Drawfill, isn't that supposed to go over it every time in the loop?
It's still not working for me.
[Gandalf]
Posted: Tue Sep 13, 2005 9:27 pm Post subject: (No subject)
I'm not quite sure what your drawfill does, but to remove the trail you have to have a cls (clear screen) inside your loop.
Also, much of your code above the loop is very pointless and removable.
gameover
Posted: Sun Dec 10, 2006 11:27 pm Post subject: (No subject)
i cant run it =.=' it says "update is not in the export list of view"
someone help i rly need to learn this mouse clicking stuff by next week my isu is due =.='
ericfourfour
Posted: Mon Dec 11, 2006 12:57 am Post subject: (No subject)
Are you trying to use View.Update by any chance? Remember, its case sensitive.
Cervantes
Posted: Mon Dec 11, 2006 1:02 am Post subject: (No subject)
Older versions of Turing don't have View.Update, so if you're running a rather old version (I think pre 4.x) then you won't be able to use it.
gameover
Posted: Tue Dec 12, 2006 7:25 pm Post subject: (No subject)
I am using turing 4.0 so it wont work?
Sponsor Sponsor
Cervantes
Posted: Tue Dec 12, 2006 7:57 pm Post subject: (No subject)
No, if you're on version 4.0, it should work. Double check your code to make sure you're using it properly. If you are, try going to C:\program files\Turing\Support\predefs\View.tu and looking to see if Update is in the export list.
gameover
Posted: Wed Dec 13, 2006 6:08 pm Post subject: (No subject)
Update isnt on the export list... so what do i do about it
Clayton
Posted: Wed Dec 13, 2006 8:27 pm Post subject: (No subject)
You'll have to purchase a newer copy yourself, or get a newer copy from your school (if they have it). This is one of the main problems with Turing, it costs money, so as soon as its depreciated, you have to pay another $80+ for a new copy (if your school doesn't have it)
gameover
Posted: Thu Dec 14, 2006 8:12 pm Post subject: (No subject)
oh wow =.=' thanks lol i gotta find some other way to learn how to use the mouse commands
frank26080115
Posted: Tue Dec 26, 2006 2:25 pm Post subject: (No subject)
what if i wanted to use W A S D for movement control?
Cervantes
Posted: Tue Dec 26, 2006 4:13 pm Post subject: (No subject)
frank26080115 wrote:
what if i wanted to use W A S D for movement control?
What if you want to do that? I don't forsee any difficulty. It's the same code as using the arrow pad, except you change