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

Username:   Password: 
 RegisterRegister   
 Mouse Troubles
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Guest




PostPosted: Fri Jul 21, 2006 11:09 pm   Post subject: Mouse Troubles

Im just wondering, how come if I repeatedly press Up and Down and click many times, eventually my oval will stop growing and can go really big and stuff?

code:

View.Set ("offscreenonly")
Mouse.ButtonChoose ("multibutton")
var x, y, c, button, size, m, back : int := 0
var cnt : real
var keys : array char of boolean
size := 10
cnt := 1
c := black
m := brightred
back := 11

drawfillbox (0, 0, maxx, maxy, back)
loop
    locate (1, 1)
    colourback (back)
    put "X:", x, " Y:", y, " BUTTON:", button, " SIZE:", size, " COLOUR:", c, " SPEED:", cnt
    Mouse.Where (x, y, button)
    Input.KeyDown (keys)
    if button = 1 then
        c := Rand.Int (0, 255)
    elsif button = 10 then
        back := Rand.Int (0, 255)
    elsif button = 100 then
        m := Rand.Int (0, 255)
    end if
    drawfilloval (x, y, size, size, c)
    drawfilloval (x, y, size - 10, size - 10, m)
    if keys (KEY_UP_ARROW) then
        cnt += .1
    elsif keys (KEY_DOWN_ARROW) then
        cnt -= .1
    end if
    View.Update
    drawfilloval (x, y, size, size, back)
    size += round (cnt)
    delay (15)
    if size > 30 then
        cnt := -cnt
    elsif size < 10 then
        cnt := -cnt
    end if
end loop
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Sat Jul 22, 2006 11:59 am   Post subject: (No subject)

vahnx, you really should know by now how to post a meaningful help thread. Asking a question similar to the one you have is all well and good, but without the necassary background to this project, what are we really supposed to do? The code is not commented, so one can't really extrapolate purpose from it. In the future, please include a few lines explaining what the code is supposed to do, and why the problem you're having is troublesom.

I'm going to have to guess that you don't want this oval of yours to grow to large. I don't know if this is true, since you've not said anything to that effect. I'm simply basing this on experience; which though often useful, mightn't apply to your situation. Onwards then.

It appears that you're limiting the growth factor, and not the size of the oval.

code:

    if size > 30 then
        cnt := -cnt
    elsif size < 10 then
        cnt := -cnt
    end if


This limits 'cnt', but 'size' can be indefinitely large or small. Change the code to limit 'size' should stop the oval from ever being too large or small (provided both limits are defined).
Guest




PostPosted: Fri Jul 28, 2006 7:28 pm   Post subject: (No subject)

I dont put in comments in my code just for you Delos. There is no purpose for this code, I am just practicing. The problem I am having is if I click "left, right" and press "up, down" over and over again, eventually my ball gets stuck like this:
Posted Image, might have been reduced in size. Click Image to view fullscreen.

Quote:
I'm going to have to guess that you don't want this oval of yours to grow to large.


What I ment to say was that my Oval will freeze and when I press UP, my oval begins to grow and will not decrease in size.
[/code]
Guest




PostPosted: Fri Jul 28, 2006 7:33 pm   Post subject: (No subject)

Here is an example of it growing, and the speed counter at the top on the right glitches out, and I cannot shrink the ball from this size and have to restart my program:
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Delos




PostPosted: Fri Jul 28, 2006 11:32 pm   Post subject: (No subject)

Hmm...
I sometimes wonder if you actually read the hints people post. Never mind though, let's see where we can get with this.

To start things off, this being 'practice' is no excuse not to comment. Comments, contrary to popular belief, are not for the benefit of other people reading your code (that much). They are there so that when you get back from watching Peter Griffin beat the bajeebaz out of that Yellow Chicken, you'll know what the hell is going on with your code. So start making a habit of dropping a few comments here and there, they'll help.

Since this is 'experimental', a great strategy to adopt is to screw the programme up and see what makes it work again. In this case, it's already screwed up, so you need isolate the error, reproduce it, then debug it.
Also, implement something along the lines of what I said previously, it will help with the size problem. The glitchy graphics is a sinch to fix if you just follow the above three steps.

You should need no further guidance in this to fix this particular problem. If you don't figure it out right away, don't fret, just keep at it. It always helps to leave the code alone for a while, go do something else (like watching Brian and Stewie take a road trip), and come back to it later. Making a fresh start can allow you to look at things in a new light.
Guest




PostPosted: Sat Jul 29, 2006 1:04 am   Post subject: (No subject)

Delos wrote:
Hmm...
I sometimes wonder if you actually read the hints people post.

No I don't, so don't ask me again.

And about commenting, I only do that when I have a large ammount of code which I need to remind myself what that line does.

Besides that, I rarely program. And if I do, it's for like 10 minutes. I am now guessing probably that the cnt grows faster than the if statment reads it. Or since I'm going in small decimal incriments, it might mistake my if statment. It doesn't really matter I guess, I was just messing around.
MysticVegeta




PostPosted: Sat Jul 29, 2006 2:28 pm   Post subject: (No subject)

vahnx wrote:
Delos wrote:
Hmm...
I sometimes wonder if you actually read the hints people post.

No I don't, so don't ask me again.


Confused bad attitude.. relax, or you will become like cornflake lol Laughing

vahnx wrote:
And about commenting, I only do that when I have a large ammount of code which I need to remind myself what that line does.


Delos actually meant, comment it for both your and others sake...

On Topic: I dont understand whats going on since there are no comments, the variables I cannot understand what they are doing. But here are a few tips, why not use "put" and "Input.Pause" after it to get how the value of vars are changing? And then perhaps you could come to a conclusion and comment and repost explaning the problem Smile Or after you figure out the problem, try to do it yourself, even better Razz
Guest




PostPosted: Sun Jul 30, 2006 3:30 am   Post subject: (No subject)

I think when you press UP or DOWN, the speed increases/decreases at the rate of the balls growth. If you move the mouse, the ball moves with it. If you LEFT click, the outside layer of the ball flashes. If you RIGHT click, the center of the ball flashes. But if you mess around with the controls lots, the ball will stop growing and the size variable flickers very fast like it gets stuck. Why does it get stuck like that? Run the program and try messing around with it and see if it stops moving for you. I still can't figure out why.
Sponsor
Sponsor
Sponsor
sponsor
Aziz




PostPosted: Sun Jul 30, 2006 9:44 am   Post subject: (No subject)

You're problem with the keys getting fudging it up, well, is you're delay. Make it (50). When it gets to higher speeds, and you press (down), the rate has already changed negative (because its reached the maximum size) and thus you make it go faster. so, change the delay. and rebuild it, from bottom up. it will help you more than trying to fix what you have already. I built it, and it's working nicely.

Also, instead of changing the pos/neg of cnt (what is it supposed to stand for, cnt?), i used a 'dir' variable, either 1 or -1. i keep the cnt value between 0 and some maximum (MAX_CNT := 10). the up/down arrows simply change that. Then, the size is increased by cnt * dir. Also, you need limiting statments. you want cnt to stay between 0 and MAX_CNT and size to stay between MIN_SIZE and MAX_SIZE. An algorithm to limit something like this:

code:
if value < MIN_VALUE
   value = MIN_VALUE
else if value > MAX_VALUE
   value = MAX_VALUE
end


in this way, the user simply change the speed, and the program takes care of the rest. I did it for you, but I'm not going to show you. If you learn it it works better. I'll work with you through this. You can PM if need be. I'll help you till you get it right, but I'm not going to give you the code. I'll give you bits of the code at a time, perhaps, and explain what they do, like i did above. Here's the effect I achieved (and I hope you wanted)



The Extension 'exe' was deactivated by an board admin, therefore this Attachment is not displayed.

Guest




PostPosted: Sun Jul 30, 2006 8:16 pm   Post subject: (No subject)

Yeah your program fixed the growth rate. I guess I can make mine similar to that and change the delay. Changing the delay was my last resort, but thanks for the help. I can easily figure it out. I just wanted someone to explain to me why it would do that other than the speed.
Aziz




PostPosted: Sun Jul 30, 2006 10:10 pm   Post subject: (No subject)

Go through it, it was more than just the delay. Work on it tonight and tommorow, then post you problems and when I'm done work (and EverQuest) I'll take a look.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: