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

Username:   Password: 
 RegisterRegister   
 need help with my enemy plane again, this time i've the code
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
yingmu




PostPosted: Sat Jun 11, 2005 1:03 pm   Post subject: need help with my enemy plane again, this time i've the code

however at the loop part it says that my interceptor variable for the procedure addInterceptor haveny been declared, but i did my code based on my partners code which is flying gun shots, and he didnt decalre his shots(interceptor) variable either but his worked, so plz tell me how to fix it, thx a million.

code:

var planeReady : boolean

type interceptorType :
    record
        x, y : int
        live : boolean
    end record

setscreen ("offscreenonly")

process coolGun
    delay (200)
    planeReady := true
end coolGun

proc addInterceptor (var x : int, var interceptor : array 1 .. 5 of interceptorType)
    if planeReady then
        for i : 1 .. 10
            if not interceptor (i).live then
                planeReady := false
                fork coolGun
                interceptor (i).live := true
                interceptor (i).x := maxx div 2
                interceptor (i).y := maxy
                exit
            end if
        end for
    end if
end addInterceptor

proc trackInterceptor (var interceptor : array 1 .. 10 of interceptorType)
    for i : 1 .. 10
        if interceptor (i).live then
            if interceptor (i).y < 0 then
                interceptor (i).live := false
            else
                interceptor (i).y += 3
            end if
        end if
    end for
end trackInterceptor

proc drawInterceptor (var interceptor : array 1 .. 10 of interceptorType)
    for i : 1 .. 10
        if interceptor (i).live then
            drawfillbox (interceptor (i).x, interceptor (i).y, interceptor (i).x - 20, interceptor (i).y - 20, brightblue)
        end if
    end for
end drawInterceptor

loop
    cls
    addInterceptor (interceptor)
    trackInterceptor (interceptor)
    drawInterceptor (interceptor)
    View.Update
end loop
Embarassed
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sat Jun 11, 2005 1:38 pm   Post subject: (No subject)

You never declared a interceptor array. You made the interceptorType, but no actual variable. To make a variable from a type, follow this example:
code:

type foo :
  record
    x, y : int
  end record
var bar : foo
var bars : array 1 .. 10 of foo
yingmu




PostPosted: Sat Jun 11, 2005 5:02 pm   Post subject: (No subject)

wait wat do u mean, u mean like this?

code:

var planeReady : boolean

type interceptorType :
    record
        x, y : int
        live : boolean
    end record
   
    var interceptor: interceptorType

setscreen ("offscreenonly")

process coolGun
    delay (200)
    planeReady := true
end coolGun

proc addInterceptor ( var interceptors : array 1 .. 5 of interceptorType)
    if planeReady then
        for i : 1 .. 10
            if not interceptors (i).live then
                planeReady := false
                fork coolGun
                interceptors (i).live := true
                interceptors (i).x := maxx div 2
                interceptors (i).y := maxy
                exit
            end if
        end for
    end if
end addInterceptor

proc trackInterceptor (var interceptors : array 1 .. 10 of interceptorType)
    for i : 1 .. 10
        if interceptors (i).live then
            if interceptors (i).y < 0 then
                interceptors (i).live := false
            else
                interceptors (i).y += 3
            end if
        end if
    end for
end trackInterceptor

proc drawInterceptor (var interceptors : array 1 .. 10 of interceptorType)
    for i : 1 .. 10
        if interceptors (i).live then
            drawfillbox (interceptors (i).x, interceptors (i).y, interceptors (i).x - 20, interceptors (i).y - 20, brightblue)
        end if
    end for
end drawInterceptor

loop
    cls
    addInterceptor (interceptor)
    trackInterceptor (interceptor)
    drawInterceptor (interceptor)
    View.Update
end loop


but it still doesnt work, plz explain it further
Cervantes




PostPosted: Sat Jun 11, 2005 5:13 pm   Post subject: (No subject)

Yeah, the problem now is you've got a variable that you're trying to pass into your procedures as an array. Change the variable to an array. Now, we get another problem because the upper bounds of your parameter arrays and the upper bounds of your actual array are different.

We can use an asterisk (*) to symbolize the upper bounds end of the array. You might recognize this because you can use it when dealing with strings to symbolize the last character:
code:

var myString := "Hello"
put myString (*)

This works because a string is essentially an array of characters.
So, you'll need to apply this concept to your program. Try following this example. Smile
Turing:

var myArray : array 1 .. 5 of int

proc initArray (var list : array 1 .. * of int)
    for i : 1 .. upper (list)
        list (i) := i * 2
    end for
end initArray

proc printArray (var list : array 1 .. * of int)
    for i : 1 .. upper (list)
        put list (i)
    end for
end printArray

initArray (myArray)
printArray (myArray)
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  [ 4 Posts ]
Jump to:   


Style:  
Search: