Computer Science Canada

Locate, Dissapear!

Author:  Anonymous [ Thu Jul 06, 2006 11:29 pm ]
Post subject:  Locate, Dissapear!

Im just wondering, is there a way to specify a locate for a certain length so my put won't overlap all the space to the right of it? Here is a little thing I'm trying to do, and I don't remember at the moment how I would re-draw the blue boxes after. My intension is going to be able to drag each box and give them their seperate variable stored in an array that changes as you drag each specific box. But as I said before, when I click a red box, the "BOX i = redbox(i)" overlaps the blue boxes on the other side. Help on my program or my little problem would be highly appreciated.

code:

var mousex, mousey, button : int
var maxRedBoxes : int := 10
var redbox, redboxX, redboxY : array 1 .. maxRedBoxes of int
var box : int := 25

for i : 1 .. maxRedBoxes
    drawfillbox (10, box, 45, box + 35, brightred)
    drawbox (10, box, 45, box + 35, black)
    drawfillbox (maxx - 10, box, maxx - 45, box + 35, brightblue)
    drawbox (maxx - 10, box, maxx - 45, box + 35, black)
    redbox (i) := box
    box += 35
end for

loop
    Mouse.Where (mousex, mousey, button)
    locate (maxrow - 1, 15)
    put "X:", mousex, "    Y:", mousey
    if whatdotcolour (mousex, mousey) = brightred and button = 1 then
        for i : 1 .. maxRedBoxes
            locate (i, 10)
            put "BOX ", i, " = ", redbox (i)
        end for
    end if
end loop


Author:  [Gandalf] [ Fri Jul 07, 2006 12:53 am ]
Post subject: 

Best answer I can give you:
Use Font.Draw().

Author:  NikG [ Fri Jul 07, 2006 1:01 am ]
Post subject: 

There is another way. Just add the double-dot after your put statement.
code:
put "BOX ", i, " = ", redbox (i)..

You might need to add a 'put ""' if you plan to do any input after that.

Author:  Clayton [ Fri Jul 07, 2006 10:30 am ]
Post subject: 

NikG thats not exactly going to work, because with the put command, it clears the entire row that it is putting to, so you end up with a big long streak across the screen in your background color (normally white), to fix this:

[Gandalf] wrote:

Best answer I can give you:
Use Font.Draw().

Author:  Delos [ Fri Jul 07, 2006 10:51 am ]
Post subject: 

SuperFreak82 wrote:
NikG thats not exactly going to work, because with the put command, it clears the entire row that it is putting to, so you end up with a big long streak across the screen in your background color (normally white), to fix this:

[Gandalf] wrote:

Best answer I can give you:
Use Font.Draw().


Actually, notice that he's used the form:
code:

put string_goes_here..
% Notice ..


This does not return to the next line, which stops any graphics on that line from being cleared.

Nonetheless, I still will maintain that you should not use these text commands for your programme, there's really no difference between using them and using Font.Draw(), seeing as you're using locates. Essentially, you're still running a graphical-output programme, hence why not use commands that are more flexible and allow you to be more precise with your placements? And they won't give you these problems either Wink.

Author:  Cervantes [ Fri Jul 07, 2006 11:22 am ]
Post subject: 

A simple text environment is in many ways nicer, though. If you make a procedure to handle this problem for you, it's no harder than simply using put.

code:

Draw.FillBox (maxx div 2, 0, maxx, maxy, black)
procedure puts (str : string)
    put str ..
    locate (whatrow + 1, 1)
end puts
puts("Hello World")
puts("Booga booga booga")

% The only trouble is if your line is so long
% the text overlaps the graphics
puts("Booga booga booga booga booga booga booga booga booga")

Author:  McKenzie [ Fri Jul 07, 2006 2:50 pm ]
Post subject: 

Why do you guys insist on complicating things? NikG had the correct answer (although locate is better for the input.) vahnx read it, tried it, liked it. Leave it alone, the topic is over.

Author:  Cervantes [ Fri Jul 07, 2006 5:54 pm ]
Post subject: 

McKenzie wrote:
Why do you guys insist on complicating things? NikG had the correct answer (although locate is better for the input.)


Actually, what NikG had wasn't quite right. Wink

See, his solution only worked for one line of output.
NikG wrote:
You might need to add a 'put ""' if you plan to do any input after that.

But if you
code:
put ""

after your initial put "text" .. line, you've defeated the purpose of using the `..'. You'll get the same destruction of your beautiful graphics.

You have to locate down one row.

McKenzie wrote:
vahnx read it, tried it, liked it. Leave it alone, the topic is over.

I don't see vahnx having replied. Confused

Author:  Anonymous [ Fri Jul 07, 2006 8:56 pm ]
Post subject:  Updated Code

Ok I tried it, now how would I be able to give the boxes seperate values so I can drag them around? Im having trouble with that.

code:

var mousex, mousey, button, down : int
var maxBoxes, maxRedBoxes, maxBlueBoxes : int := 10
var redbox, redboxX, redboxY, bluebox, blueboxX, blueboxY : array 1 .. maxRedBoxes of int
var box : int := 25

for i : 1 .. maxBoxes
    drawfillbox (10, box, 45, box + 35, brightred)
    drawbox (10, box, 45, box + 35, black)
    drawfillbox (maxx - 10, box, maxx - 45, box + 35, brightblue)
    drawbox (maxx - 10, box, maxx - 45, box + 35, black)
    redbox (i) := box
    bluebox (i) := box
    box += 35
end for

loop
    Mouse.Where (mousex, mousey, button)
    locate (maxrow - 1, 35)
    put "X:", mousex, "    Y:", mousey
    if whatdotcolour (mousex, mousey) = brightred and button = 1 then
        down := 3
        for i : 1 .. maxRedBoxes
            exit when down = 23
            locate (down, 10)
            down += 2
            put "RED BOX ", i, " = ", redbox (i) ..
        end for
    elsif whatdotcolour (mousex, mousey) = brightblue and button = 1 then
        down := 3
        for i : 1 .. maxBlueBoxes
            exit when down = 23
            locate (down, 55)
            down += 2
            put "BLUE BOX ", i, " = ", bluebox (i) ..
        end for
    end if
end loop



Mod edit: Combined a triple post into here.

Author:  NikG [ Fri Jul 07, 2006 10:19 pm ]
Post subject: 

Your question isn't clear vahnx. Do you want to be able to drag each of the red and blue boxes? Then you need an array for each box's x and y coordinates.

To McKenzie: Cervantes is right that it's not a perfect solution. But if vahnx controls all the text being output (as in uses a locate statement before every put), the double-dot works.

Author:  Clayton [ Fri Jul 07, 2006 10:28 pm ]
Post subject: 

wow triple post...

ok anyways, why not just make box its own type? then we can have an array of boxes so that we can drag it around, a type for your box might look something like this:

code:

var boxes : flexible array 1..0 of
    record
        x, y, box_color : int
    end record


from there on, you can simply use a combination of Mouse.Where and a little know-how to have a box follow your mouse when clicked Very Happy If you dont know about anything i just suggested i suggest you take a quick peek at the Turing Walkthrough Wink

Author:  Anonymous [ Sat Jul 08, 2006 1:12 am ]
Post subject: 

What a flexible array? Huh. I'm only firmillar with records and types when used with files and not sure there of any real use. Sorry. Turings walkthrough is boring.

Author:  NikG [ Sat Jul 08, 2006 1:53 am ]
Post subject: 

vahnx wrote:
What a flexible array? Huh. I'm only firmillar with records and types when used with files and not sure there of any real use. Sorry. Turings walkthrough is boring.
Ummm... so are you expecting us to write a new tutorial just for you over here when a perfectly good one exists? Or perhaps you want us to implement flexi arrays into your code for you...

Go read the Cervantes tutorial on flexible arrays, I guarantee you'll find it useful.

Author:  NikG [ Sat Jul 08, 2006 1:59 am ]
Post subject: 

(sorry for the double post)
If the number of boxes in your array is fixed, then forget flexible arrays (or learn it some other time).
Right now, the types and records tutorial is what you really need.

Author:  McKenzie [ Sat Jul 08, 2006 7:48 am ]
Post subject: 

Obviously NikG had a minor error (thats why I said so in brackets), and obviously vahnx hadn't tried it yet (he would probably said thanks.) My point is
code:
..

is all he realy needed to see. This will set him on the right road. This gives vahnx a chance to keep the solution as much his own as possible. When you spam the topic it doesn't help the original poster it just muddies the water.

Author:  Cervantes [ Sat Jul 08, 2006 4:05 pm ]
Post subject: 

Sure, you've got a point. I don't agree completely with it, but I see where you're coming from.

But what confuses me is why you chose to make a statement like this in this particular topic. There are many topics that are far more spamish than this in [Turing Help].

vahnx wrote:

Turings walkthrough is boring.

How could it be improved?

Author:  TokenHerbz [ Sat Jul 08, 2006 6:04 pm ]
Post subject: 

It is fine how it is...

Wonderful coulors, good links.. what more could you ask for?

Author:  McKenzie [ Sun Jul 09, 2006 9:50 am ]
Post subject: 

Well, they are entirely different issues. Oh I agree that complaining about the walkthrough is akin to saying "I'm lazy, I couldn't be bothered reading the walkthrough, please hold my hand." If I complained about every post I didn't agree with that's all I would be posting. As you may know, I've been teaching Computer Science for eleven years. What I key into are issues that effect learing. From what vahnx wrote, I'd imagine that he would prefer you just take his code and fix it. I don't think that's in his best interests however.

Author:  Anonymous [ Tue Jul 11, 2006 11:49 am ]
Post subject: 

You people do not understand. The Turing Walkthrough isn't good help because each explination links to other explinations of terms it's using to explain, therefore and endless loop until it redirects you to the "put" statement. I am computer illeterate. I want things to explain like a retard.

Author:  Cervantes [ Tue Jul 11, 2006 3:46 pm ]
Post subject: 

vahnx wrote:
You people do not understand. The <a href="http://www.compsci.ca/v2/viewtopic.php?t=8808">Turing Walkthrough</a> isn't good help because each explination links to other explinations of terms it's using to explain, therefore and endless loop until it redirects you to the "put" statement. I am computer illeterate. I want things to explain like a retard.


I don't think it is a loop. Sure, the tutorial on arrays requires that you understand variables and the primative data types, but the introductory tutorial that teaches variables and primitive data types does not require that you know arrays.

Rather than being circular, it's linear.


: