variable has no value :(
Author |
Message |
Clayton
|
Posted: Wed Jun 07, 2006 11:28 am Post subject: variable has no value :( |
|
|
hey, im working on a game right now and ive come upon a little "snag", you see whenever my game calls the DrawLine procedure from within the Ball module, the Draw.ThickLine command is highlighted and the error "variable has no value" occurs, anybody have any idea why this might be? (i think it might be the array being passed to the procedure..but i dont see what that has to do with it) any help would be appreciated
Turing: |
module Ball
export Initialize, Move
View.Set ("offscreenonly,graphics:max;max")
type line :
record
x, y : int
flag : boolean
end record
proc DrawLine (lineArray : array 1 .. * of line )
for x : 1 .. upper (lineArray )
%error here "variable has no value"
Draw.ThickLine (lineArray (x ).x - 25, lineArray (x ).y - 25, lineArray (x ).x + 25, lineArray (x ).y + 25, 3, black)
end for
end DrawLine
const lengtH : int := 25
const radius : int := 10
const thickness : int := 3
var x, y, xx, yy, b : int
var xVel, yVel : int := 1
var LineArray : flexible array 1 .. 1 of line
proc Initialize (xVal, yVal : int)
x := xVal
y := yVal
end Initialize
proc CheckCollision
if View.WhatDotColor (x + radius, y ) = black then
xVel * = - 1
elsif View.WhatDotColor (x - radius, y ) = black then
xVel * = - 1
elsif View.WhatDotColor (x, y + radius ) = black then
yVel * = - 1
elsif View.WhatDotColor (x, y - radius ) = black then
yVel * = - 1
end if
end CheckCollision
proc CheckMouse
if b = 1 then
LineArray (upper (LineArray )).x := xx
LineArray (upper (LineArray )).y := yy
LineArray (upper (LineArray )).flag := true
end if
DrawLine (LineArray )
View.Update
new LineArray, upper (LineArray ) + 1
end CheckMouse
proc Move
loop
Mouse.Where (xx, yy, b )
Draw.Cls
Draw.Box (0, 0, maxx, maxy, black)
Draw.FillOval (x, y, radius, radius, green)
x + = xVel
y + = yVel
CheckMouse
CheckCollision
exit when hasch
end loop
end Move
end Ball
import Ball
Ball.Initialize (maxx div 2, maxy div 2)
loop
Ball.Move
end loop
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Delos
|
Posted: Wed Jun 07, 2006 12:38 pm Post subject: (No subject) |
|
|
code: |
proc CheckMouse
if b = 1 then
LineArray (upper (LineArray)).x := xx
LineArray (upper (LineArray)).y := yy
LineArray (upper (LineArray)).flag := true
end if
DrawLine (LineArray)
|
What about when b != 1? What happens then? Right now, LineArray will be uninitialized unless the mouse button is held down.
Some other comments (to work on once you have things working):
- you've used types for your lines, use them for the ball as well. Compartmentalization is good.
- your Initialize proc should take more values than that! You have too many hard-coded values.
- I would also suggest changing Init from a proc to a fcn. Much, much cleaner.
- I haven't run this yet, so I don't know if there are any potential hiccups from having those two loops...
- I don't particularly like the idea that the module changes the settings of the window. Nor do I like that it has any extraneous code...you should look into that. |
|
|
|
|
|
Clayton
|
Posted: Wed Jun 07, 2006 12:59 pm Post subject: (No subject) |
|
|
its only a chunk of code that i took from what i have, its not the whole thing, i just gave you what was needed to run, i dont know why theres a View.Set in there but anyway, ya i kinda forgot about the non initialized values so oh well, i guess ill just give it some obscure value off the screen until i can figure out a cleaner, better way of doing things |
|
|
|
|
|
|
|