issue passing value. drawpaddle(1) drawpaddle(2) , 2 fails and takes 1's values

Started by LemonWizard, March 26, 2010, 12:46:48 PM

Previous topic - Next topic

LemonWizard

hi.
Okay. I am having a strange strange issue.. this time around o.o

Why is it that I am the only one who runs into these strange errors..

as I understand it when passing a parameter to a function it's supposed to keep the value of that parameter intact and I should be able to pass the value to a new variable that is local to only the function..

so here's my issue

I have an array typed as paddles(2)
the values are x, y, width, and height

easy right?

unfortanately... as far as I can tell I didn't code anything wrong and as I've checked arrays are global to functions..okay moving on

obviously I did do something wrong because it's not working the way I want it to.

drawpaddle(1)
drawpaddle(2)
that's the call I'm making.

the function is drawpaddle(paddle)

I have a variable in there called num
so right underneath drawpaddle(paddle) in the function delcaration I have it doing this
num=paddle
then all calls to the typed array holding the paddles unique x, y, height and width are right here


function drawpaddle(paddle)
num=paddle
x=paddles(num).x
y=paddles(num).y
width=paddles(num).width
height=paddles(num).height
x2=x+width
y2=y+height
y1=y
x1=x
boxc x1, y1, x2, y2, 1, rgb(0,255,0)
print x1
print y1
print x2
print y2


endfunction





now here's what happens to me.

it draws the first paddle but not the second one.
but when I change num=2 and hardcode the value of 2 directly into the function...

it works for some reason.

what the heck did I do wrong? Can't I make this call :

drawpaddle(1)
drawpaddle(2)
and have it change num to that specific value? From my understanding I thought that's what I could do, and even with an array.. what's going on.. it's like I have bad luck or something. lol... or maybe I just don't understand.

Here's the full code I'm using


; PROJECT : CoolPong
; AUTHOR  : LemonWizard
; CREATED : 26/03/2010
; ---------------------------------------------------------------------

type paddle
x
y
width
height
endtype

dim paddles(2) as paddle

type ball
x
y
state
radius
xdirection
ydirection
endtype

dim ball as ball


for temp=1 to 1
width=30
height=25
x=getscreenwidth()-width
y=(getscreenheight()/2)
paddles(temp).x=x
paddles(temp).y=y
paddles(temp).height=height
paddles(temp).width=width
next temp

paddles(2).width=50
paddles(2).height=25
paddles(2).x=0
paddles(2).y=(getscreenheight()/2)



main:
wait 10
drawpaddle(1)
drawpaddle(2)
sync
cls rgb(0,0,0)

goto main


function drawpaddle(paddle)
num=paddle
x=paddles(num).x
y=paddles(num).y
width=paddles(num).width
height=paddles(num).height
x2=x+width
y2=y+height
y1=y
x1=x
boxc x1, y1, x2, y2, 1, rgb(0,255,0)
print x1
print y1
print x2
print y2


endfunction


Anyone who thinks they can help do help.

kevin


The answer is here..

   num=paddle

   PADDLE is a variable or a type identifier ?    I'll give you hint, it's not a variable !



kevin

 Cleaned up code....


PlayBASIC Code: [Select]
   type tball
x
y
state
radius
xdirection
ydirection
endtype

dim ball as tball


Type tPaddle
x
y
Width
Height
EndType

dim paddles(2) as tpaddle


width=30
height=25
y=(getscreenheight()/2)

for temp=1 to 2
if Temp=1
X=0
else
x=getscreenwidth()-width
endif
paddles(temp).x=x
paddles(temp).y=y
paddles(temp).height=height
paddles(temp).width=width
next


Do
cls rgb(0,0,0)
drawpaddle(1)
drawpaddle(2)
sync
loop


Psub drawpaddle(num)

x1=paddles(num).x
y1=paddles(num).y
x2=x1+paddles(num).width
y2=y1+paddles(num).height

boxc x1, y1, x2, y2, 1, rgb(0,255,0)
print x1
print y1
print x2
print y2

endPsub