Jump to content

Arrays and User Defined Functions


paladicprince

Recommended Posts

Hmm. It looks like there was a bit of code left in there. I actually am calling to a User-Defined function now which is labelled PPEnemyScan.

 

Here's the code copy-pasted from CS (instead of semi-editted like the above was):

(Also note the runbatchscript defines the *Key variables)

 

scn PPTargettingScript

Float fQuestDelayTime

Array_Var EnemyTargets

Short ClearKey

Short NextEnemyKey
Short PrevEnemyKey

Short CurrentEnemy
Short Position

Ref PlayerCell
Ref Target
Ref Temp


Begin GameMode

If (fQuestdelayTime != .01)
Let fQuestDelayTime := .01
EndIf

If (GetGameLoaded)
RunBatchScript "Data\PPTargetting.ini"
Let EnemyTargets := Ar_Construct Array 
Let EnemyTargets := Call PPEnemyScan

Let PlayerCell := Player.GetParentCell
EndIf

If (Player.GetParentCell != PlayerCell)
Let EnemyTargets := Call PPEnemyScan
Let PlayerCell := Player.GetParentCell
EndIf

If (OnKeyDown ClearKey)
Print "ClearKey Pressed"
Print $ CurrentEnemy
Ar_Dump EnemyTargets
Let PlayerCell := 0
Let Target := 0
ElseIf (OnKeyDown NextEnemyKey)
Print "NextEnemyKey Pressed"
Let CurrentEnemy := (Ar_Next EnemyTargets CurrentEnemy)
If (CurrentEnemy == -99999)
	Let CurrentEnemy := (Ar_First EnemyTargets)
EndIf
Print $ CurrentEnemy
Let Target := EnemyTargets[CurrentEnemy]
Print $ Target

ElseIf (OnKeyDown PrevEnemyKey)
Print "PrevEnemyKey Pressed"
If TestExpr (Ar_Prev EnemyTargets CurrentEnemy)
	Let CurrentEnemy := (Ar_Prev EnemyTargets CurrentEnemy)
	If (CurrentEnemy == -99999)
		Let CurrentEnemy := (Ar_Last EnemyTargets)
	EndIf
	Print $ CurrentEnemy
	Let Target := EnemyTargets[CurrentEnemy]
	Print $ Target
EndIf
EndIf

End

 

And here's the User-defined function:

 

scn PPEnemyScan

Array_Var EnemyTargets

Short Position

Ref Temp


Begin Function {}

Let EnemyTargets := Ar_Construct Array
Let Temp := GetFirstRef 69 1

While (Temp)
If (Temp.GetDead == 0)
	Let EnemyTargets[Position] := Temp
	Let Position += 1
EndIf

Let Temp := GetNextRef
Loop

SetFunctionValue EnemyTargets

End

 

And since it's a function the Position is stored localy and deleted once the function is done running. Thus it self resets.

 

Good input thanks.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...