Ironic, since I'm actually coding the little game I mentioned using purely procedural programming. There's no OOP in sight, so don't worry too much about it for now =Dowen wrote:OK I admit it: I am new to oop. In prep for Paul's contribution I am trying to explain some stuff and ran into a question about passing UDT's through subs and functions.
You don't need to specify the 'byref' clause when you pass the parameter, only on the function prototype:owen wrote:Why does draw_ball_2(ByRef b) not work?
Code: Select all
ScreenRes 600,400
Window(0,0)-(600,400)
Type ball
x As Integer
y As Integer
r As Integer
c As Integer
End Type
Declare Sub draw_ball_1(ByVal aball As ball)
Declare Sub draw_ball_2(ByRef aball As ball)
Declare Sub draw_ball_3(aball As ball)
Dim b As ball
b.x=300
b.y=200
b.r=100
b.c=14
Circle(b.x,b.y),b.r,b.c
Print "press any key"
Sleep
Cls
b.c=13
draw_ball_1(b)
Circle(b.x,b.y),b.r,b.c
Print "press any key"
Sleep
draw_ball_2(b)
Circle(b.x,b.y),b.r,b.c
Print "press any key"
Sleep
draw_ball_3(b)
Circle(b.x,b.y),b.r,b.c
Print "press any key"
Sleep
Sub draw_ball_1(ByVal aball As ball)
Circle(aball.x,aball.y),aball.r,aball.c
aball.r=50
End Sub
Sub draw_ball_2(ByRef aball As ball)
Circle(aball.x,aball.y),aball.r,aball.c
aball.r=200
End Sub
Sub draw_ball_3(aball As ball)
Circle(aball.x,aball.y),aball.r,aball.c
aball.r=300
End Sub