Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 [tutorial] movement (getch,keydown,mouse)
Index -> Programming, Turing -> Turing Tutorials
Goto page Previous  1, 2, 3
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Terror Byte




PostPosted: 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 Very Happy (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
Sponsor
sponsor
Cervantes




PostPosted: Tue Sep 13, 2005 8:05 pm   Post subject: (No subject)

Welcome to the forums!

A couple of things:

  1. We prefer if questions are posted in the Help forum, rather than in the Tutorial thread corresponding to the topic in question.

  2. There is no need to put the "setscreen ("offscreenonly")" within your loop. It need only be stated once.

  3. If you want your circle to move, you need to put the code to draw the circle inside the loop. That is crucial. Wink

  4. 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. Smile
Terror Byte




PostPosted: Tue Sep 13, 2005 9:18 pm   Post subject: (No subject)

Ah well that makes sense Very Happy

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]




PostPosted: 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




PostPosted: 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 =.=' Exclamation
ericfourfour




PostPosted: 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




PostPosted: 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




PostPosted: Tue Dec 12, 2006 7:25 pm   Post subject: (No subject)

I am using turing 4.0 Confused so it wont work? Question
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: 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




PostPosted: Wed Dec 13, 2006 6:08 pm   Post subject: (No subject)

Update isnt on the export list... so what do i do about it Question
Clayton




PostPosted: 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) Confused
gameover




PostPosted: 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 Shocked
frank26080115




PostPosted: 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




PostPosted: 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
code:
if keys (KEY_UP_ARROW) then

to
code:
if keys ('w') then
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 3 of 3  [ 44 Posts ]
Goto page Previous  1, 2, 3
Jump to:   


Style:  
Search: