Yes, use functions wherever you can instead of any other type of code...
Atm, im making a BreakOut game for the 20liner challenge, and this is all that is in my main loop (due to function useage):
Do
If launched = 1
_wall_reflection()
_paddle_reflection()
_block_reflection()
rem Movement control of ball.
If theta <> 0 Then YRotate Object ball,WrapValue(theta)
Move Object ball,ballspeed
Else
_launch()
EndIf
_control()
_options()
Sync
Loop
That is all, out of 380 lines that gets called in the loop.
That is what you should aim for. It is the best kind of codeing you can do.
Also, functions a re reusable, and can be used for all sorts of different projects. They are very universal.
To answer your first question, im going to convert your bulletlife code from the other thread into a function for you:
pistol_attack:
if mouseclick() = 1 and bulletlife=0
bx# = x#
bz# = z#
by# = get ground height(1,x#,z#)+player_height#
bya# = a# : `this is the .B.ullet .Y. .A.ngle, the direction it is pointing
`bPitch# is the characters X rotation or the angle at which the character is looking either up or down.
bPitch# = 360.0-camera angle x() : `will eventually use "object angle x()" on page 121
bulletlife=200
show object 2
Set object to camera orientation 2
position object 2,bx#,by#,bz#
endif
if bulletlife > 0
bulletx# = object position x(2)
bulletz# = object position z(2)
bullety# = object position y(2)
Move object 2,20
dec bulletlife
floorheight = get ground height(1,bulletx#,bulletz#)
If bullety# =< floorheight then bulletlife=0
endif
If bulletlife <= 0
position object 2, 0,0,0
Hide object 2
endif
return
It's not too hard, but requires a bit of thought. This is the function version:
Function pistol_attack(x#,z#,player_height#,a#,bulletlife,objnum)
if mouseclick() = 1 and bulletlife=0
bx# = x#
bz# = z#
by# = get ground height(1,x#,z#)+player_height#
bya# = a# : `this is the .B.ullet .Y. .A.ngle, the direction it is pointing
`bPitch# is the characters X rotation or the angle at which the character is looking either up or down.
bPitch# = 360.0-camera angle x() : `will eventually use "object angle x()" on page 121
bulletlife=200
show object objnum
Set object to camera orientation objnum
position object objnum,bx#,by#,bz#
endif
if bulletlife > 0
bulletx# = object position x(objnum)
bulletz# = object position z(objnum)
bullety# = object position y(objnum)
Move object objnum,20
dec bulletlife
floorheight = get ground height(1,bulletx#,bulletz#)
If bullety# =< floorheight then bulletlife=0
endif
If bulletlife <= 0
position object objnum, 0,0,0
Hide object objnum
endif
EndFunction bulletlife
To call that, put in your main loop, something like:
bulletlifemain = pistol_attack(x#,z#,player_height#,a#,bulletlifemain,2)
What that does, is it passes all teh information needed by the function into it, and can be changed by you each time you call teh function, say you had 5 bullets, you could put in a different number for objnum each function call.
The part where it has
bulletlifemain = ...
When the function returns the variable stored in bulletlife from inside the function, it needs to be stored in a variable in the main loop (since variables inside functions are not global).
That just puts the value of bulletlife into the variable bulletlifemain which is then used for determining the bulletlife in the function the next loop (you can see, it is one of the parameters)
Hope I Helped...
PS sorry bout the long post...

Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy