Justin Knight Posted March 9, 2016 Author Share Posted March 9, 2016 I'm getting a subscript out of range error in handletradeitem. Does anyone have any idea why?The error is at "TempPlayer(TempPlayer(index).InTrade).AcceptTrade = False" I have it pointed out in the code below. The index =6, Intrade=0, but acceptTrade is out of range.```Sub HandleTradeItem(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long) Dim Buffer As clsBuffer Dim invSlot As Long Dim amount As Long Dim EmptySlot As Long Dim itemnum As Long Dim i As Long Set Buffer = New clsBuffer Buffer.WriteBytes Data() invSlot = Buffer.ReadLong amount = Buffer.ReadLong Set Buffer = Nothing If invSlot <= 0 Or invSlot > MAX_INV Then Exit Sub itemnum = GetPlayerInvItemNum(index, invSlot) If itemnum <= 0 Or itemnum > MAX_ITEMS Then Exit Sub ' make sure they have the amount they offer If amount < 0 Or amount > GetPlayerInvItemValue(index, invSlot) Then Exit Sub End If If Item(itemnum).Type = ITEM_TYPE_CURRENCY Then ' check if already offering same currency item For i = 1 To MAX_INV If TempPlayer(index).TradeOffer(i).Num = invSlot Then ' add amount TempPlayer(index).TradeOffer(i).Value = TempPlayer(index).TradeOffer(i).Value + amount ' clamp to limits If TempPlayer(index).TradeOffer(i).Value > GetPlayerInvItemValue(index, invSlot) Then TempPlayer(index).TradeOffer(i).Value = GetPlayerInvItemValue(index, invSlot) End If ' cancel any trade agreement TempPlayer(index).AcceptTrade = False TempPlayer(TempPlayer(index).InTrade).AcceptTrade = False SendTradeStatus index, 0 SendTradeStatus TempPlayer(index).InTrade, 0 SendTradeUpdate index, 0 SendTradeUpdate TempPlayer(index).InTrade, 1 ' exit early Exit Sub End If Next Else ' make sure they're not already offering it For i = 1 To MAX_INV If TempPlayer(index).TradeOffer(i).Num = invSlot Then PlayerMsg index, "You've already offered this item.", BrightRed Exit Sub End If Next End If ' not already offering - find earliest empty slot For i = 1 To MAX_INV If TempPlayer(index).TradeOffer(i).Num = 0 Then EmptySlot = i Exit For End If Next TempPlayer(index).TradeOffer(EmptySlot).Num = invSlot TempPlayer(index).TradeOffer(EmptySlot).Value = amount ' cancel any trade agreement and send new data TempPlayer(index).AcceptTrade = False 'trade error >>>>>>>>>>>>>>>>>>>TempPlayer(TempPlayer(index).InTrade).AcceptTrade = False<<<<<<<<<<<<<<<<<<<<<<<<<<<<< SendTradeStatus index, 0 SendTradeStatus TempPlayer(index).InTrade, 0 SendTradeUpdate index, 0 SendTradeUpdate TempPlayer(index).InTrade, 1End Sub``` Link to comment Share on other sites More sharing options...
BeNjO Posted March 9, 2016 Share Posted March 9, 2016 Looks like needs to be```TempPlayer(index).AcceptTrade = False``` Link to comment Share on other sites More sharing options...
Justin Knight Posted March 10, 2016 Author Share Posted March 10, 2016 hmm well that line is right above it so i commented out the line giving the error for now. No one has reported any new errors so for now I guess it's fine. Link to comment Share on other sites More sharing options...
Coyote Posted March 10, 2016 Share Posted March 10, 2016 Lol error is so stupid.It is looking for player , hid index = intrade and intrade = 0 so there is the error.Player index cant be 0.So just put If TempPlayer(index).InTrade > 0 and error is solved!Hope this helps Link to comment Share on other sites More sharing options...
Justin Knight Posted March 11, 2016 Author Share Posted March 11, 2016 Thanks for this solution. I ended up needing to do checks like this all over the trade codes cause there are a lot of little errors players can cause. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now