User Defined Types and Functions
Blitz3D Forums/Blitz3D Beginners Area/User Defined Types and Functions
| ||
Alright. Ive been using blitzbasic for a while, but i am no pro yet. I just have two quick questiosn i hope someone can help me out with. Am i correct in assuming that passing *ANY* variable into a function, that it is being passed byREF always? And if so, when i try and pass in UserDefined Types it does not allow me to do so. Is there a trick to passing user defiend types into functions? or will i have to make the user defined type that holds the object/entity global? If anyone could answer i would be really appreciative. |
| ||
Function parameters are all passed by value. BUT, type objects are essentially pointers to the data, so they are effectively passed by reference. To pass a type into a function: Type thing Field x,y End Type t.thing = New thing doit(t) Print t\x ; should display "20" End Function doit(athing.thing) athing\x = 20 End Function |
| ||
As always, the BlitzForums never fail to produce good help. Thanks MasterBeaker. U rock man. Good call. |
| ||
It's not really the way I prefer, but I guess it does work... I really prefer the direct thing like other languages support... But I found my ways to live with the miss... |
| ||
??? What is essentially different (apart from the super super syntax in Blitz, myInstance\myField...WTF???) Can you be clearer? |
| ||
When a variable is passed by reference any changes to the variable are kept when the function exits. In some small way its the same as using a global. The following psuedo (Blitz / VB hyrbid ) functions should make things clearer...ammo = 47 ShootWeapon( ammo ) ; ammo now equals 46 Function ShootWeapon( byREF ammo ) ammo = ammo - 1 ; Actually changes the value MakeBullet End Function ammo = 47 ammo = ShootWeapon( ammo ) Function ShootWeapon( byVAL ammo ) MakeBullet Return ammo - 1 ; Has to return the value End Function Hope it makes things clearer... |
| ||
Yes, exactly like in any other language that supports pointer and/or reference... that is almost any useable language. Thanks NeoGenesis10 but I wasn't requesting any explanation here, types are pretty straight forward to use when you already know languages like Java or C++. I was asking Tricrokra what difference he sees in this. |