only on numbers that end in 0
Author |
Message |
Shyfire

|
Posted: Sun Jul 24, 2005 7:50 pm Post subject: only on numbers that end in 0 |
|
|
ok im trying to make it so when you press the mouse ot only draws the square on numbers that end in 0 (eg. 10,20,30,40........)
how would i go about this
heres what i have so far
code: |
var x, y,c,button : int:=2
proc block(x,y,c:int)
drawfillbox(x-5,y-5,x+5,y+5,c)
end block
loop
Mouse.Where (x, y, button)
Text.Locate (1, 1)
if button = 0 then
else
block(x,y,c)
end if
end loop
|
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Flikerator
|
Posted: Sun Jul 24, 2005 10:29 pm Post subject: (No subject) |
|
|
First of all ill edit your code a bit...
code: | var x, y, c, button : int := 2
proc block (x, y, c : int)
drawfillbox (x - 5, y - 5, x + 5, y + 5, c)
end block
loop
Mouse.Where (x, y, button)
Text.Locate (1, 1)
if button ~= 0 then
block (x, y, c)
end if
end loop |
If button ~= 0 then it takes out the else. ~= is the same as not= but im sure that not= is a process and it take sup more memory or somthing. It also is less characters decreasing the size of the program.
I don't know why you want a procedure for one line of code, but if you want it ill keep it in.
From what I understand you want the square only to draw if the number ends in 0? Meaning a multiple of ten. This is easily done but i don't know which number you are talking about. If you mean the x and y coordinates this is what you should do.
Quote: var x, y, c, button : int := 2
proc block (x, y, c : int)
drawfillbox (x - 5, y - 5, x + 5, y + 5, c)
end block
loop
Mouse.Where (x, y, button)
locate (1, 1)
put x, " ", y
if button ~= 0 then
if x mod 10 = 0 and y mod 10 = 0 then
block (x, y, c)
end if
end if
end loop
I changed Text.Locate to plain locate so I could display the x and y coordinates of your mouse so you can make sure that what I did is correct to what I think you want.
You will notice an if statement asking "if the x coordinate mod (divided) by 10 has a remainder of 0 (mod divides the number and returns a value equal to the remainder, not the decimal value).
It also has a an AND in there doing the same thing using y. Therfore if both are correct and the mouse is pressed, it will draw a square.
You could also but the ~= 0 in the same if statement by adding another and.
If you need help or have more questions just ask. |
|
|
|
|
 |
TokenHerbz

|
Posted: Mon Jul 25, 2005 1:07 am Post subject: (No subject) |
|
|
how your you do this without a proceadure???
Because i dont want to use it, and im cerious... |
|
|
|
|
 |
Shyfire

|
Posted: Mon Jul 25, 2005 1:58 am Post subject: (No subject) |
|
|
could you make round it to the nearest 10
plz |
|
|
|
|
 |
Delos

|
Posted: Mon Jul 25, 2005 1:42 pm Post subject: (No subject) |
|
|
tokenherbz wrote: how your you do this without a proceadure???
Because i dont want to use it, and im cerious...
You shouldn't. You'd have to use an extraneous if structure that would be, well, just not worth it. If you can use a function/procedure, then do so, you shouldn't try to reduce your code to a state where you don't.
fatboi wrote:
could you make round it to the nearest 10
plz
I believe the 'x mod 10 = 0 and y mod 10 = 0' has already accomplished this. |
|
|
|
|
 |
person
|
Posted: Mon Jul 25, 2005 7:06 pm Post subject: (No subject) |
|
|
round also works |
|
|
|
|
 |
Flikerator
|
Posted: Mon Jul 25, 2005 7:34 pm Post subject: (No subject) |
|
|
Simple instead of having;
code: |
var x, y, c, button : int := 2
proc block (x, y, c : int)
drawfillbox (x - 5, y - 5, x + 5, y + 5, c)
end block
loop
Mouse.Where (x, y, button)
Text.Locate (1, 1)
if button ~= 0 then
block (x, y, c)
end if
end loop
|
Do this;
code: | var x, y, c, button : int := 2
loop
Mouse.Where (x, y, button)
Text.Locate (1, 1)
if button ~= 0 then
Draw.FillBox (x - 5, y - 5, x + 5, y + 5, c)
end if
end loop |
If you are going to use a procedure make sure you need it. If you only use lines of code once there is no point in making a procedure to use it. |
|
|
|
|
 |
[Gandalf]

|
Posted: Mon Jul 25, 2005 9:45 pm Post subject: (No subject) |
|
|
Delos wrote: fatboi wrote:
could you make round it to the nearest 10
plz
I believe the 'x mod 10 = 0 and y mod 10 = 0' has already accomplished this.
I think you misunderstood him, either way, this is an improved version of the code.
Turing: | var x, y, c, button : int
loop
Mouse.Where (x, y, button )
locate (1, 1)
put x, " ", y
if button ~ = 0 then
drawfillbox ((x - (x mod 10)) - 5, (y - (y mod 10)) - 5, (x - (x mod 10)) + 5, (y - (y mod 10) + 5), blue)
end if
end loop |
*edit* also, fatboi, please make your avatar smaller so that it doesn't shrink the actual post frame. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Flikerator
|
Posted: Tue Jul 26, 2005 7:49 pm Post subject: (No subject) |
|
|
Okay I get what he wanted now. I didn't really get why he would want that code, it was hard use... |
|
|
|
|
 |
[Gandalf]

|
Posted: Tue Jul 26, 2005 9:24 pm Post subject: (No subject) |
|
|
Well, it is a bit off (oops), but at least it doesn't depend on very specific coordinates for it to draw anything. This way it draws something no matter what and snaps it to the grid - useful for snake games, rpg's and many other things. |
|
|
|
|
 |
|
|