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

Username:   Password: 
 RegisterRegister   
 array script is out of range
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
spencerbr




PostPosted: Sat Dec 09, 2006 12:37 pm   Post subject: array script is out of range

code:

setscreen ("graphics:max,max")

var undoRedo : array 1 .. 10 of int
var x, y, button : int
var c8 : int := 0

% Undo Redo
if button = 1 and x > 100 and y > 20 then
    c8 += 1
    if x > 10 then
        x := 0
    end if
    undoRedo (c8) := Pic.New (101, 21, maxx, maxy)
end if
% Undo
if x >= 5 and x <= 45 and y >= 295 and y <= 335 and button = 1 then
    c8 := c8 - 1
    if c8 < 1 then
        c8 := 10
    end if
    Pic.Draw (undoRedo (c8), 101, 21, picCopy)
end if
% Redo
if x >= 55 and x <= 95 and y >= 295 and y <= 335 and button = 1 then
    c8 += 1
    if x > 10 then
        x := 0
    end if
    Pic.Draw (undoRedo (c8), 101, 21, picCopy)
end if


I tried adding this into my paint program but it lags the program, screws up the tools, and then cuts out after 10 buttons and says "array script is out of range"
Sponsor
Sponsor
Sponsor
sponsor
spencerbr




PostPosted: Sat Dec 09, 2006 12:43 pm   Post subject: (No subject)

already found 1 flaw in the code
code:

setscreen ("graphics:max,max")
Mouse.ButtonChoose ("multibutton")

var undoRedo : array 1 .. 10 of int
var x, y, button : int
var c8 : int := 0

% Undo Redo
if button = 1 and x > 100 and y > 20 then
    c8 += 1
    if c8 > 10 then
        c8 := 0
    end if
    undoRedo (c8) := Pic.New (101, 21, maxx, maxy)
end if
% Undo
if x >= 5 and x <= 45 and y >= 295 and y <= 335 and button = 1 then
    c8 := c8 - 1
    if c8 < 1 then
        c8 := 10
    end if
    Pic.Draw (undoRedo (c8), 101, 21, picCopy)
end if
% Redo
if x >= 55 and x <= 95 and y >= 295 and y <= 335 and button = 1 then
    c8 += 1
    if c8 > 10 then
        c8 := 0
    end if
    Pic.Draw (undoRedo (c8), 101, 21, picCopy)
end if
Clayton




PostPosted: Sat Dec 09, 2006 1:03 pm   Post subject: (No subject)

It's either because your variable c8 goes above 10 or below 0, check to make sure which it is, then post back here.
spencerbr




PostPosted: Sat Dec 09, 2006 1:22 pm   Post subject: (No subject)

i did


if c8 < 1 then
c8 := 10
end if
Clayton




PostPosted: Sat Dec 09, 2006 1:25 pm   Post subject: (No subject)

Can you please highlight where you get the error then?
Clayton




PostPosted: Sat Dec 09, 2006 1:26 pm   Post subject: (No subject)

Actually, I figured it out, when c8 > 10, you set it to 0, then right away you use it to make a new picture, but your array only goes from 1 .. 10, so therefore 0 is out of bounds of the array.
spencerbr




PostPosted: Sat Dec 09, 2006 1:31 pm   Post subject: (No subject)

ill try that
spencerbr




PostPosted: Sat Dec 09, 2006 1:38 pm   Post subject: (No subject)

it works now
it undo and redos every little mouse movement
Sponsor
Sponsor
Sponsor
sponsor
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  [ 8 Posts ]
Jump to:   


Style:  
Search: