Star Enlarge problem
Author |
Message |
chrispminis
|
Posted: Thu Dec 15, 2005 10:12 pm Post subject: Star Enlarge problem |
|
|
Well im creating a christmas tree program that has some oddities and one of them is that... when you click one of the stars, it will grow, and grow as long as you click it. For some reason tho, it will neither grow, nor change colour when the mouse is moved over it. Please debug, its probly something dumb i overlooked but i cant think of it atm.
code: | %starenlarge
var starenlargex1, starenlargey1, starenlargex2, starenlargey2, starenlargecol : int
starenlargex1 := 100
starenlargey1 := 320
starenlargex2 := 120
starenlargey2 := 340
starenlargecol := 14
var mx, my, mb : int
%star enlarge
loop
Mouse.Where (mx, my, mb)
if mx > starenlargex1 and mx < starenlargex2 then
if mx > starenlargey1 and my < starenlargey2 then
starenlargecol := black
end if
end if
if mx > starenlargex1 and mx < starenlargex2 then
if mx > starenlargey1 and my < starenlargey2 then
if mb = 1 then
starenlargex1 := starenlargex1 - 5
starenlargex2 := starenlargex2 + 5
starenlargey1 := starenlargey1 - 5
starenlargey2 := starenlargey2 + 5
end if
end if
end if
Draw.FillStar (starenlargex1, starenlargey1, starenlargex2, starenlargey2, starenlargecol)
end loop
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Bored
|
Posted: Thu Dec 15, 2005 10:17 pm Post subject: (No subject) |
|
|
look at your if staments closely and the variables your comparing. One of them is wrong and I'll leave up to you to find it for yourself. Other then that your program works fine altough I would suggest adding in a delay. |
|
|
|
|
|
chrispminis
|
Posted: Thu Dec 15, 2005 10:54 pm Post subject: (No subject) |
|
|
Is it really that obvious? Did you actually find it or are you assuming that's the problem. Because either im blind to my follies or there isnt an error, which there obviously is so thus im just blind to my follies. Help. |
|
|
|
|
|
[Gandalf]
|
Posted: Fri Dec 16, 2005 1:50 am Post subject: (No subject) |
|
|
Here, I fixed up your program a bit. I didn't really look too much into it, just rewrote the logic. The problem, as mentioned, is a simple variable mixup:
if mx > starenlargey1 and my < starenlargey2 then
should be:
if my > starenlargey1 and my < starenlargey2 then
code: | %star enlarge
var starenlargex1, starenlargey1, starenlargex2, starenlargey2, starenlargecol : int
starenlargex1 := 100
starenlargey1 := 320
starenlargex2 := 120
starenlargey2 := 340
starenlargecol := 14
var mx, my, mb : int
loop
Mouse.Where (mx, my, mb)
if mx > starenlargex1 and mx < starenlargex2 and my > starenlargey1 and my < starenlargey2 and mb > 0 then
starenlargex1 -= 5
starenlargex2 += 5
starenlargey1 -= 5
starenlargey2 += 5
starenlargecol := black
end if
Draw.FillStar (starenlargex1, starenlargey1, starenlargex2, starenlargey2, starenlargecol)
delay (40)
end loop |
Next time, look into the problem more yourself. It may not seem simple at the moment, but once you figure it out it'll be no problem. |
|
|
|
|
|
chrispminis
|
Posted: Fri Dec 16, 2005 1:36 pm Post subject: (No subject) |
|
|
Oh wow, that was a simple mistake, thx. It works well now Ill post my christmas tree program next tuesday after i hand it in
Also, why did you put mb > 0 instead of mb = 1? what difference does it make? |
|
|
|
|
|
[Gandalf]
|
Posted: Fri Dec 16, 2005 5:18 pm Post subject: (No subject) |
|
|
It doesn't, at least not under the current settings, but I rewrote it, and I find that way comes to mind quicker. It only makes a difference when you are using the multibutton mouse setting, so mb = 1 is the left mouse button, mb=10 is the middle, and mb = 100 is the right button. In that case, mb > 0 would be true if any of the buttons are pressed. |
|
|
|
|
|
|
|