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

How to avoid overflow in general


Dawntide
 Share

Recommended Posts

hello guys,

I got problems with overflow runtime error with my currency and the title system:

http://www.touchofdeathforums.com/community/index.php?/topic/127866-eo-titles-12/page__hl__title__st__20

When i get too much money i get an overflow error, how to avoid it and just make the player does not get more gold?

When i choose an title and the title reward gives me stats so i would have stats above 255, i get an overflow runtime error, how to avoid that, so it just stops at 255 without oveeflow error?

thanks in advance!
Link to comment
Share on other sites

You either check that you're not exceeding the limit, or you have an error-trap in place, that handles and corrects it.

ie.

```
If ThingHere > Limit Then ThingHere = Limit - 1
```

Or

```
On Error GoTo errorhandler

Exit Sub

errorhandler:

If Err.Number = 6 ' From my memory, this is Overflow.

ValueToCorrect = Limit - 1

' Whatever the hell the resuming line is, I can't remember it. xD

Else

' It's a different error, handle accordingly.

End If

Err.Clear
```

I recommend you use the first method, just for [your] simplicity.
Link to comment
Share on other sites

Okay, but i can not get it to work:

```

Sub UseTitulo(ByVal index As Long, ByVal Slot As Long)

Dim i As Long

' Verificar se está usando o titulo selecionado, se sim sair da sub

If GetPlayerTUsando(index) = GetPlayerTitulo(index, Slot) Then Exit Sub

' Remover recompenças

If GetPlayerTUsando(index) > 0 Then

For i = 1 To Stats.Stat_Count - 1

Call SetPlayerStat(index, i, GetPlayerStat(index, i) - Titulo(GetPlayerTUsando(index)).StatRec(i))

Next

End If

' Recompenças

For i = 1 To Stats.Stat_Count - 1

Call SetPlayerStat(index, i, GetPlayerStat(index, i) + Titulo(GetPlayerTitulo(index, Slot)).StatRec(i))

Next

' Dar o titulo ao jogador

Call SetPlayerTUsando(index, GetPlayerTitulo(index, Slot))

' Atualizar

Call SendPlayerData(index)

Call SendStats(index)

Call SendPlayerTitulos(index)

End Sub

```

Where do i have to paste the first method now?

And where to paste it for currency, because there are so many subs i guess, bank, shop etc.
Link to comment
Share on other sites

this happens because eclipse uses the byte data type for stats if you want your stats to be able to go higher than 255 you have to change it to either integer or long

if you dont want to change the data type use the code below

```

Sub UseTitulo(ByVal index As Long, ByVal Slot As Long)

Dim i As Long

' Verificar se está usando o titulo selecionado, se sim sair da sub

If GetPlayerTUsando(index) = GetPlayerTitulo(index, Slot) Then Exit Sub

' Remover recompenças

If GetPlayerTUsando(index) > 0 Then

For i = 1 To Stats.Stat_Count - 1

Call SetPlayerStat(index, i, GetPlayerStat(index, i) - Titulo(GetPlayerTUsando(index)).StatRec(i))

Next

End If

' Recompenças

For i = 1 To Stats.Stat_Count - 1

if (GetPlayerStat(index, i) + Titulo(GetPlayerTitulo(index, Slot)).StatRec(i)) <= 255 then

Call SetPlayerStat(index, i, GetPlayerStat(index, i) + Titulo(GetPlayerTitulo(index, Slot)).StatRec(i))

end if

Next

' Dar o titulo ao jogador

Call SetPlayerTUsando(index, GetPlayerTitulo(index, Slot))

' Atualizar

Call SendPlayerData(index)

Call SendStats(index)

Call SendPlayerTitulos(index)

End Sub

```
Link to comment
Share on other sites

I guess it removes the actual title stats if you switch the title.

I do not understand how your code avoids an overflow, it just adds the stats.

The if check is completly without effect, isn't it?

I noticed that there is some kind of bug in the title system, but i do not know where and how to fix it.

If i just go to maxlevel (70) and invest my stat points i got this stats:

50 58

40 40

50

Then i choose the first title, which has NO reward stats, then i got this stats:

100 108

90 90

100

Then i choose the second title, which has NO reward stats, then i got this stats:

200 208

190 190

200

If i choose the third title, i get overflow runtime error

This only happens if i am wearing armor, helmet etc.

It just adds 100 stat points completly random.
Link to comment
Share on other sites

my code checks whether the stats points will go beyond 255 if you add the titles points if it does it just doesnt add them

i will go over the tutorial to see if i can find something

Edit: i downloaded the files in the tutorial but the code is different it doesnt add stats anywhere
Link to comment
Share on other sites

```

Public Sub SetPlayerStat(ByVal index As Long, ByVal stat As Stats, ByVal Value As Long)

if value >= 255 then

Player(index).stat(stat) = 255

else

Player(index).stat(stat) = Value

end if

End Sub

```

this should fix the overflow error but not the title system
Link to comment
Share on other sites

Okay, nice. No overflow anymore, but the title system seems buged like bum candy.

It just sums up to 255 on each stats when i change titles, but no title has any rewards. How to fix this?

What a pitty that 99% of all tutorials in this forum are buggy as hell ![:(](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/sad.png)
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...