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

Username:   Password: 
 RegisterRegister   
 Bugs in code
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
sarm2005




PostPosted: Wed Mar 05, 2008 9:58 am   Post subject: Bugs in code

For some reason the Pic.FileNew command stops working after I press a key a few times. could someone help me fix it.

code:

setscreen ("graphics:800,600")
View.Set ("offscreenonly")
var fishx, fishy, angle, fishpic, fishangle : int := 0
var value, count : int := 1
var ch : string (1)
var chars : array char of boolean
randint (fishx, 1, maxx - 64)
randint (fishy, 1, maxy - 35)
fishpic := Pic.FileNew ("Fish_" + intstr (count) + "_G.bmp")
Pic.Draw (fishpic, fishx, fishy, picMerge)
loop
    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) then
        fishpic := Pic.FileNew ("Fish_" + intstr (count) + "_G.bmp")
        Pic.Draw (fishpic, fishx, fishy, picMerge)
        if count > 0 and count < 10 then
            count := count + 1 * value
            fishy := fishy + 10
            delay (75)
            View.Update
            cls
        elsif count > 9 then
            value := -1
            count := 8
        elsif count < 1 then
            value := 1
            count := 2
        end if
    elsif chars (KEY_RIGHT_ARROW) then
        fishpic := Pic.FileNew ("Fish_" + intstr (count) + "_G.bmp")
        fishangle := Pic.Rotate (fishpic, angle, -1, -1)
        Pic.Draw (fishangle, fishx, fishy, picCopy)
        Pic.Free (fishpic)
        Pic.Free (fishangle)
        angle := angle - 10
        if count > 0 and count < 10 then
            count := count + 1 * value
            delay (75)
            View.Update
            cls
        elsif count > 9 then
            value := -1
            count := 8
        elsif count < 1 then
            value := 1
            count := 2
        end if
    elsif chars (KEY_LEFT_ARROW) then
        fishpic := Pic.FileNew ("Fish_" + intstr (count) + "_G.bmp")
        fishangle := Pic.Rotate (fishpic, angle, -1, -1)
        Pic.Draw (fishangle, fishx, fishy, picMerge)
        angle := angle + 10
        if count > 0 and count < 10 then
            count := count + 1 * value
            delay (75)
            View.Update
            cls
        elsif count > 9 then
            value := -1
            count := 8
        elsif count < 1 then
            value := 1
            count := 2
        end if
    end if
end loop
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Wed Mar 05, 2008 10:42 am   Post subject: RE:Bugs in code

You are not using Pic.Free -- your code should stop working after 1000 or so Pic.New calls.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
riveryu




PostPosted: Wed Mar 05, 2008 8:50 pm   Post subject: RE:Bugs in code

Just adding a tiny bit to Tony, there should be as many Pic.Free as there is Pic.FileNew. U should use them as if they are brackets.
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  [ 3 Posts ]
Jump to:   


Style:  
Search: