Passing alot of variables to a function...

BlitzMax Forums/BlitzMax Beginners Area/Passing alot of variables to a function...

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Two advantages:

1) If you're passing in multiple types of parameters (strings, floats, etc.), a Type can be made typesafe.

2) By using a type, you can use named parameters, which will make it more clear what is going on. Consider (and sorry if my syntax is slightly screwed up)

Type ParticleParams
  Field xLoc:Int
  Field yLoc:Int
  Field Speed:Float
  Field RGB:Long
End Type
...

Local params:ParticleParams = new ParticleParams
params.xLoc = 100
params.yLoc = 200
params.Speed = 2.0
params.RGB = 48723 ' okay, this could be cleaner.

CreateParticle params


In this case, without even looking at the definition of CreateParticle, you know exactly what the code is doing. In comparison:

Local params[ 4 ]
params[ 0 ] = 100
params[ 1 ] = 200
params[ 2 ] = 2.5
params[ 3 ] = 34212

CreateParticle params


Less clear, and far more likely for you to misorder something (which simply can't happen with a Typed parameter)