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

Annoying error appearing.


bintin
 Share

Recommended Posts

Hello,

I've been looking through the code and I can't find anything wrong with it, I also tried some apparent "solutions" but I still get the same error.

The error I get is a run time error (9) subscript out of range and it highlights "If NPC(npcNum).QuestNum = i Then"

I use Project Vertigo and this started when I added Alatar's Quest system (which doesn't work as NPC's don't want to give me the quest.)
Link to comment
Share on other sites

Indeed I shall

>! Public Sub DrawPlayerName(ByVal Index As Long)
>! Dim TextX As Long
>! Dim TextY As Long
>! Dim color As Long
>! Dim Name As String
>! ' If debug mode, handle error then exit out
>! If Options.Debug = 1 Then On Error GoTo errorhandler
>! ' Check access level
>! If GetPlayerPK(Index) = NO Then
>! Select Case GetPlayerAccess(Index)
>! Case 0
>! color = RGB(255, 96, 0)
>! Case 1
>! color = QBColor(DarkGrey)
>! Case 2
>! color = QBColor(Cyan)
>! Case 3
>! color = QBColor(BrightGreen)
>! Case 4
>! color = QBColor(Yellow)
>! End Select
>! Else
>! color = QBColor(BrightRed)
>! End If
>! Name = Trim$(Player(Index).Name)
>! ' calc pos
>! TextX = ConvertMapX(GetPlayerX(Index) * PIC_X) + Player(Index).XOffset + (PIC_X \ 2) - getWidth(TexthDC, (Trim$(Name)))
>! If GetPlayerSprite(Index) < 1 Or GetPlayerSprite(Index) > NumCharacters Then
>! TextY = ConvertMapY(GetPlayerY(Index) * PIC_Y) + Player(Index).YOffset - 16
>! Else
>! ' Determine location for text
>! TextY = ConvertMapY(GetPlayerY(Index) * PIC_Y) + Player(Index).YOffset - (DDSD_Character(GetPlayerSprite(Index)).lHeight / 6) + 16
>! End If
>! ' Draw name
>! Call DrawText(TexthDC, TextX, TextY, Name, color)
>! Dim i As Long
>! Dim npcNum As Long
>! For i = 1 To MAX_QUESTS
>! 'check if the npc is the next task to any quest: [?] symbol
>! If Quest(i).Name <> "" Then
>! If Player(MyIndex).PlayerQuest(i).Status = QUEST_STARTED Then
>! If Quest(i).Task(Player(MyIndex).PlayerQuest(i).ActualTask).NPC = npcNum Then
>! Name = "[?]"
>! TextX = ConvertMapX(MapNpc(Index).x * PIC_X) + MapNpc(Index).XOffset + (PIC_X \ 2) - getWidth(TexthDC, (Trim$(Name)))
>! If NPC(npcNum).Sprite < 1 Or NPC(npcNum).Sprite > NumCharacters Then
>! TextY = ConvertMapY(MapNpc(Index).Y * PIC_Y) + MapNpc(Index).YOffset - 16
>! Else
>! TextY = ConvertMapY(MapNpc(Index).Y * PIC_Y) + MapNpc(Index).YOffset - (DDSD_Character(NPC(npcNum).Sprite).lHeight / 4)
>! End If
>! Call DrawText(TexthDC, TextX, TextY, Name, QBColor(Yellow))
>! Exit For
>! End If
>! End If
>! 'check if the npc is the starter to any quest: [!] symbol
>! 'can accept the quest as a new one?
>! If Player(MyIndex).PlayerQuest(i).Status = QUEST_NOT_STARTED Or Player(MyIndex).PlayerQuest(i).Status = QUEST_COMPLETED_BUT Then
>! 'the npc gives this quest?
>! If NPC(npcNum).QuestNum = i Then
>! Name = "[!]"
>! TextX = ConvertMapX(MapNpc(Index).x * PIC_X) + MapNpc(Index).XOffset + (PIC_X \ 2) - getWidth(TexthDC, (Trim$(Name)))
>! If NPC(npcNum).Sprite < 1 Or NPC(npcNum).Sprite > NumCharacters Then
>! TextY = ConvertMapY(MapNpc(Index).Y * PIC_Y) + MapNpc(Index).YOffset - 16
>! Else
>! TextY = ConvertMapY(MapNpc(Index).Y * PIC_Y) + MapNpc(Index).YOffset - (DDSD_Character(NPC(npcNum).Sprite).lHeight / 4)
>! End If
>! Call DrawText(TexthDC, TextX, TextY, Name, QBColor(Yellow))
>! Exit For
>! End If
>! End If
>! End If
>! Next
>! ' Error handler
>! Exit Sub
>! errorhandler:
>! HandleError "DrawPlayerName", "modText", Err.Number, Err.Description, Err.Source, Err.HelpContext
>! Err.Clear
>! Exit Sub
>! End Sub
Link to comment
Share on other sites

You're using npcNum, without actually assigning it a value, hence the subscript errors. You're attempting to use a structure that doesn't exist. (In this case, NPC #0\. ![:P](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/tongue.png))

Also, why are you iterating through each quest, in the player name drawing procedure? Not mentioning that it's going to render with -each player on the map-, rather than loop through a large amount of quests, loop through your map NPCs when your map loads, and grab whether it has a quest, then (Known as caching. It's better to get what's needed beforehand, not constantly!), and use said stored variables to draw.

Although, if that's from a tutorial, shouldn't that code be in DrawNPCName, not DrawPlayerName? I think a npcNum argument exists there, hence the need for it. ![:P](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/tongue.png)

Pseudo-code:

Public CacheQuestNpcsVar(1 To Max_Map_Npcs) As Byte

Public Sub CacheQuestNpcs()

Dim i As Long

For i = 1 To Max_Map_Npcs

If Npc(i).QuestNum > 0 Then

' Check for players quest details here, to grab [!]/[?].

'For [!], make CacheQuestNpcsVar(i) = 1.

'For [?], make CacheQuestNpcsVar(i) = 2.

Else

' Here, the NPC has no quest. We can clear it.

CacheQuestNpcsVar(i) = 0

End If

Next

End Sub

Then, in it's OWN SUB

Public Sub DrawQuestNpcs

For i = 1 To Max_Map_Npcs

Select Case CacheQuestNpcsVar(i)

Case 1

' Draw [!] here!

case 2

' Draw [?] here!

End Select

Next

End Sub

EDIT: Sorry 'bout the nesting. No idea what happened there.
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...