By Default a Function will create an Instanced Copy of the Data that you're passing in.
This means that for all intended purpose that data ONLY exists within the Function...
Now we can change this behaviour with the 'Ref' Operator., that no longer creates an Instanced Copy but rather an Instanced Reference., this means that the Data doesn't ACTUALLY existing within the Function; but instead is the original Source Data that we're interacting in that function via said specified Variable.
So let's provide a quick example of what I mean:
Type Float2
X As Float
Y As Float
EndType
ScreenRes As Float2
ScreenRes2 As Float2
Do
ScreenRes = GetResolution()
GetResolutionByRef( ScreenRes2 )
Print( "Regular Output: " + Str( ScreenRes.X, 0 ) + "x" + Str( ScreenRes.Y, 0 ) )
Print( "By Ref Output: " + Str( ScreenRes2.X, 0 ) + "x" + Str( ScreenRes2.Y, 0 ) )
Sync()
Loop
Function GetResolution( )
Local Resolution As Float2
Resolution.X = GetVirtualWidth()
Resolution.Y = GetVirtualHeight()
EndFunction Resolution
Function GetResolutionByRef( Resolution Ref As Float2 )
Resolution.X = GetVirtualWidth()
Resolution.Y = GetVirtualHeight()
EndFunction
Now it's difficult to see what you're doing with your Showcased Functions.
I can tell you that thisEnemyTarget is simply a SINGLE Element Type., not an Array (unless you have an Array within it). (Remember you need [ ] for each Array Dimension to Ref an Array).
The other thing is that at no point do you put data back into thisEnemyTarget., meaning the Ref is complete pointless.
Finally myMachineGun[] isn't being Referenced in., but is clearly a Global Variable (but I don't know if you've ACTUALLY tagged it as Global., you might want to if it is; and you want to use it within Functions without issue; as while it should scope properly... you just never know what behaviour AppGameKit as a Scripting language will exhibit without explicit declaration... Scripters tend to "Auto Predict" your intention and get things wrong; and is a major reason why I dislike them greatly as it make lazy programmers and leads to incorrect behaviours within codebases)
•
In blunt terms... I see no issues with the code., the bigger question is WHAT are you EXPECTING the code to be doing; because the issue I suspect is with your Code Logic., not the Ref Operator; because believe me, when you try to do something it doesn't support the Compiler lets you know and quite verbosely at that.
Ref are NOT Pointers., they're Safe Pointers; keep that in mind, it means they're kinda limited in their functionality support.