array script is out of range
Author |
Message |
spencerbr
|
Posted: 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" |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
spencerbr
|
Posted: 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
|
|
|
|
|
|
![](images/spacer.gif) |
Clayton
![](http://compsci.ca/v3/uploads/user_avatars/1718239683472e5c8d7e617.jpg)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
spencerbr
|
Posted: Sat Dec 09, 2006 1:22 pm Post subject: (No subject) |
|
|
i did
if c8 < 1 then
c8 := 10
end if |
|
|
|
|
![](images/spacer.gif) |
Clayton
![](http://compsci.ca/v3/uploads/user_avatars/1718239683472e5c8d7e617.jpg)
|
Posted: Sat Dec 09, 2006 1:25 pm Post subject: (No subject) |
|
|
Can you please highlight where you get the error then? |
|
|
|
|
![](images/spacer.gif) |
Clayton
![](http://compsci.ca/v3/uploads/user_avatars/1718239683472e5c8d7e617.jpg)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
spencerbr
|
Posted: Sat Dec 09, 2006 1:31 pm Post subject: (No subject) |
|
|
ill try that |
|
|
|
|
![](images/spacer.gif) |
spencerbr
|
Posted: Sat Dec 09, 2006 1:38 pm Post subject: (No subject) |
|
|
it works now
it undo and redos every little mouse movement |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|
|