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

Username:   Password: 
 RegisterRegister   
 Flexible array help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Zasalamel




PostPosted: Fri Mar 05, 2010 7:02 pm   Post subject: Flexible array help

What is it you are trying to achieve?
a box drawing program


What is the problem you are having?
it will not draw the boxes


Describe what you have tried to solve this problem
i have tried moving for loops around


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)


Turing:

var box : flexible array 1 .. 0 of
    record
        x1 : int
        y1 : int
        x2 : int
        y2 : int
    end record

for i : lower (box) .. upper (box)
    box (i).x1 := 0
    box (i).y1 := 0
    box (i).x1 := 0
    box (i).y1 := 0
end for
var x1, x2, y1, y2, x, y, b : int
fcn b10 (num : int) : int
    result round (num / 10) * 10
end b10
loop
    Mouse.Where (x, y, b)
    if b = 0 then
        x1 := b10 (x) - 5
        y1 := b10 (y) - 5
        y2 := b10 (y) + 5
        x2 := b10 (x) + 5
    end if
    for i : lower (box) .. upper (box)
        if b = 1 then
            box (i).x1 := x1
            box (i).y1 := y1
            y2 := b10 (y) + 5
            x2 := b10 (x) + 5
            box (i).x2 := x2
            box (i).y2 := y2
        end if
        if box (i).x1 ~= 0 then
            new box, 1
        end if
        drawbox (box (i).x1, box (i).y1, box (i).x2, box (i).y2, black)
    end for
    drawbox (x1, y1, x2, y2, brightred)
    View.Update
%I realize that there is no offscreenonly above
    cls
end loop




Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Superskull85




PostPosted: Fri Mar 05, 2010 7:41 pm   Post subject: Re: Flexible array help

From what I understood you want a program that will draw a on the screen, and that each box would be store in memory. Is this right?

If so then the problem is that you are overwriting the information for every box in memory, and that you are constantly setting the upper bound of the array to one (hence only having one box.

What you want to do is something like the following:

Turing:
%Initialize the array with length one so that it can be written to (ie. var Array : flexible array 1 .. 1 of int).
%Create a procedure to initialize the upper bound when called (passing upper (box) as the index of a array will return the last element in the array)
%Declare your variables and procedures

%Initialize your array by calling the procedure you setup to do this
loop
cls
    Mouse.Where (x, y, b)
    if b = 0 then
        x1 := b10 (x) - 5
        y1 := b10 (y) - 5
        y2 := b10 (y) + 5
        x2 := b10 (x) + 5
    end if
    %Draw your boxes by iterating from 1 to upper (box)
    if b = 1 then
        %Set the upper element of your box array ( box (upper (box)) ) to the current location
    end if
    if box (upper(box)).x1 ~= 0 then
        new box, upper (box) + 1
        %Initialize the last element of your array by calling the procedure you setup to do this
    end if
    drawbox (x1, y1, x2, y2, brightred)
    View.Update
end loop

Hope that helped. Smile
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  [ 2 Posts ]
Jump to:   


Style:  
Search: