Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Subscript out of range? why?


ryono
 Share

Recommended Posts

hey people of eclipse. I need some help. I made a script that is basically a regular attack script. the script will get whoevever you attacking's index and then attack them. basically the same as the standard ctrl attack. but without the animation. so yeah here it is, see if you can find anything wrong:

```
Sub RegularAttack(Index, High, Low, HitAnim, MissAnim, CritAnim, RevAnim, HitSound, MissSound, CritSound, RevSound)
Dim TR
Dim I
Dim TI
Dim Dmg
Dim M
Dim PX
Dim PY
Dim TX
Dim TY
Dim CH
Dim HT

I = Index
TR = TargetReverse(I)
TI = TargetIndex(I)
Dmg = Rand(High, Low)
M = GetPlayerMap(I)
PX = GetPlayerX(I)
PY = GetPlayerY(I)
TX = GetPlayerX(TI)
TY = GetPLayerY(TI)
CH = IsCriticalHit(I)
HT = HitType(I)

If HT = 2 Then
Call SpellAnim(CritAnim, M, TX, TY)
Call DamagePlayer(TI, Dmg + 12)
Call PlaySoundToMap(I, CritSound)
ElseIf HT = 1 Then
If TR = 1 Then
Call DamagePlayer(I, Dmg)
Call SpellAnim(RevAnim, M, PX, PY)
Call PlaySoundToMap(I, RevSound)
Else
Call SpellAnim(HitAnim, M, TX, TY)
Call DamagePlayer(TI, Dmg)
Call PlaySoundToMap(I, HitSound)
End If
Else
If Dir = 0 Then
Call SpellAnim(MissAnim, M, PX, PY - 1)
ElseIf Dir = 1 Then
Call SpellAnim(CritAnim, M, PX, PY + 1)
ElseIf Dir = 2 Then
Call SpellAnim(CritAnim, M, PX - 1, PY)
Else
Call SpellAnim(CritAnim, M, PX + 1, PY)
End If
Call PlaySoundToMap(I, MissSound)
End If
End Sub

Function TargetIndex(Index)
Dim Count
Dim I
Dim Map
Dim Players
Dim Dir
Dim PX
Dim PY
Dim T
Dim TX
Dim TY

I = Index
Map = GetPlayerMap(I)
Players = GetPlayersOnMap(Map)
Dir = GetPlayerDir(I)
PX = GetPlayerX(I)
PY = GetPlayerY(I)
TX = GetPlayerX(Count)
TY = GetPlayerY(Count)
TargetIndex = 0

For Count = 0 to Players
Select Case Dir
Case 0
If PX = TX And PY = TY + 1 Then
TargetIndex = Count
Exit Function
End If
Case 1
If PX = TX And PY = TY - 1 Then
TargetIndex = Count
Exit Function
End If
Case 2
If PX = TX + 1 And PY = TY Then
TargetIndex = Count
Exit Function
End If
Case Else
If PX = TX - 1 And PY = TY Then
TargetIndex = Count
Exit Function
End If
End Select
Next
End Function

Function IsCriticalHit(Index)
Dim PD
Dim TD
Dim I
Dim TI

I = Index
TI = TargetIndex(I)
PD = GetPlayerDir(I)
TD = GetPlayerDir(TI)
IsCriticalHit = 0

If PD = 0 And TD = 0 Or _
PD = 1 And TD = 1 Or _
PD = 2 And TD = 2 Or _
PD = 3 And TD = 3 Then
IsCriticalHit = 1
End If
End Function

Function HitType(Index)
Dim TI
Dim CH

TI = TargetIndex(Index)
CH = IsCriticalHit(Index)

If TI > 0 Then
If CH = 1 Then
HitType = 2
Else
HitType = 1
End If
Else
HitType = 0
End If
End Function

Function TargetReverse(Index)
Dim I
Dim TI
Dim TN
Dim TR

I = Index
TI = TargetIndex(I)
TN = GetPlayerName(TI)
TR = GetVar("Reverse.ini", "REVERSE", TN)

If TR = "1" Then
TargetReverse = 1
End If
End Function
```
thank you for whoever tries to help me, or to whoever even looks at this post.
Link to comment
Share on other sites

The entire thing? anyway, I think I know what it might be. its looking for the player dir, but if the index = 0 then it will get a syntax error, becasue there is no index. so. i'll try that and see if it works. Thank you very much for your input, I appreciate it.

Edit: It still does not work.
Link to comment
Share on other sites

@ryono:

> The entire thing? anyway, I think I know what it might be. its looking for the player dir, but if the index = 0 then it will get a syntax error, becasue there is no index. so. i'll try that and see if it works. Thank you very much for your input, I appreciate it.

Yea, look:
![](http://i41.tinypic.com/21l7sb5.jpg)
Anyway, I'm not the best at sadscript, but what is that "Or _" for?
Link to comment
Share on other sites

Found the problem.

```
Players = GetPlayersOnMap(Map)

...

For Count = 0 to Players
```
_Players_ is set equal to the number of players on a map. This is NOT an array of their respective indices. As such, when you're trying to retrieve a player's index from their position on the map, you are not succeeding. For example, someone in map slot 2 might be right in front of player _Index_, but their true index number could be something far different, like 11\. Only by pure coincidence will you actually receive their true index value.
The only way to counter this is to run the check for ALL indices. However, one more error prevents even that from working.

```
TX = GetPlayerX(Count)
TY = GetPlayerY(Count)
```
These two declarations are _outside_ the for-statement. As such, when Count changes, the values do not. Simply move them inside to fix this.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...