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

Username:   Password: 
 RegisterRegister   
 Locate, Dissapear!
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Guest




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

Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Fri Jul 07, 2006 12:53 am   Post subject: (No subject)

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




PostPosted: Fri Jul 07, 2006 1:01 am   Post subject: (No 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.
Clayton




PostPosted: Fri Jul 07, 2006 10:30 am   Post subject: (No 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().
Delos




PostPosted: Fri Jul 07, 2006 10:51 am   Post subject: (No 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.
Cervantes




PostPosted: Fri Jul 07, 2006 11:22 am   Post subject: (No 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")
McKenzie




PostPosted: Fri Jul 07, 2006 2:50 pm   Post subject: (No 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.
Cervantes




PostPosted: Fri Jul 07, 2006 5:54 pm   Post subject: (No 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
Sponsor
Sponsor
Sponsor
sponsor
Guest




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




PostPosted: Fri Jul 07, 2006 10:19 pm   Post subject: (No 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.
Clayton




PostPosted: Fri Jul 07, 2006 10:28 pm   Post subject: (No 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
Guest




PostPosted: Sat Jul 08, 2006 1:12 am   Post subject: (No 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.
NikG




PostPosted: Sat Jul 08, 2006 1:53 am   Post subject: (No 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.
NikG




PostPosted: Sat Jul 08, 2006 1:59 am   Post subject: (No 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.
McKenzie




PostPosted: Sat Jul 08, 2006 7:48 am   Post subject: (No 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.
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 2  [ 20 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: