Function won't run
Author |
Message |
ScribbleS
|
Posted: Fri Jun 19, 2009 10:20 am Post subject: Function won't run |
|
|
What is it you are trying to achieve?
I am trying to create a pseudo-3D environment with keyboard controls. It's for fun. xD
What is the problem you are having?
A function in a class I wrote wouldn't run. Every time I try to run it Turing says "variable has no value".
Describe what you have tried to solve this problem
I read all the tutorials I could find but could not find what was wrong with it. I checked through the code and wasn't able to detect anything. Then again, I'm not a very experienced programmer and could've easily missed some stupid mistakes.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Here's what I have so far...(the Pikachu image is just for testing. )
Turing: |
class engine
import Input
export draw, update
function jump (glvl : int, var posy : int, var v : int) : int
if posy >= glvl then
if v >= 0 then
posy + = v ** 2
else
posy - = v ** 2
end if
v - = 1
result posy
end if
result jump (glvl, posy, v )
end jump
fcn move (var key : array char of boolean, var x, y, z : int) : int
if key (KEY_LEFT_ARROW) then
x - = 1
elsif key (KEY_RIGHT_ARROW) then
x + = 1
elsif key ('z') then
var rate : int := 3
y := jump (y, y, rate )
elsif key (KEY_UP_ARROW) then
z + = 1
elsif key (KEY_DOWN_ARROW) then
z - = 1
end if
var pos : int := 10 ** 6 * x + 10 ** 3 * y + z
result pos
end move
fcn update (x, y, z: int): int
var pos : int := 10 ** 6 * x + 10 ** 3 * y + z
result pos
end update
proc draw (pic: int, var currentpos : int)
var posx, posy, posz, pos, passx, passy, passz : int
var key : array char of boolean
Input.KeyDown (key )
passx := currentpos div 10** 6
passy := (currentpos - 10** 6* (currentpos div 10** 6))div 10** 3
passz := (currentpos - 10** 3* (currentpos div 10** 3))
pos := move (key, passx, passy, passz )
posx := pos div 10** 6
posy := (pos - 10** 6* (pos div 10** 6)) div 10** 3
posz := (pos - 10** 3* (pos div 10** 3))
var newpic : int := Pic.Scale (pic, Pic.Width (pic ) div posz, Pic.Height (pic ) div posz )
Pic.Draw (newpic, round (posx ), round (posy ), 0)
end draw
end engine
var picID : int := Pic.FileNew ("Pikachu.bmp")
var px, py, pz : int
var k : array char of boolean
var pt: pointer to engine
var enafcn: int:= 0
px := maxx div 2
py := maxy div 2
pz := 1
enafcn:=engine (pt ).update (px, py, pz ) % ALWAYS GETS STUCK HERE. SAYS THAT "enafcn" HAS NO VALUE. =.="
engine (pt ).draw (picID, enafcn )
|
Please specify what version of Turing you are using
Turing 4.1.1. I'm trying to "wean" myself off of Turing, but that's evidently going to take some time... ![Embarassed Embarassed](images/smiles/icon_redface.gif) |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
corriep
|
Posted: Fri Jun 19, 2009 2:41 pm Post subject: Re: Function won't run |
|
|
Turing: | var pt : pointer to engine
new engine, pt
|
You need the second line to make a new instance of engine. Also to shorten this you can write : Turing: | var pt : ^engine
new pt
|
|
|
|
|
|
![](images/spacer.gif) |
|
|