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

Runtime error 6 overflow


sweetboy
 Share

Recommended Posts

uhm sorry if im asking too much, i got an error again at this line

Function GetPlayerExp(ByVal index As Long) As Long

    GetPlayerExp = Player(index).EXP

End Function

then another error at

GetWeapon = GetPlayerEquipment(attacker, weapon)

im using eclipse Final Frontier thanks >.<
Link to comment
Share on other sites

overflow means that you are trying to fit data into something that it can not fit into. hence overflowing data.

This means that Player(index).EXP is Larger or smaller than GetPlayerExp so it throws this error.

Same for the other one GetWeapon is smaller or just can hold a big negative value that GetPlayerEquipment can.  Just make sure the data types match up and that you are not trying to Go over the size limit the data type is.

Byte = 0 to 255

Integer = -32,768 to 32,767

Long = -2,147,483,648 to 2,147,483,647
Link to comment
Share on other sites

A good way to help solve this is to educate yourself on basic programming principles and why certain things work and certain things break.

Google or YouTube VB6 learning tutorials and that should get you started on the right path. This might seem like a lot or even hard, but it's well worth it to learn to fix some problems on your own rather than being spoon fed everything, trust me. :D

If you can learn the basics it will go a long way for helping you make games and you'll find yourself asking stuff in the Q&A section less and less.

But to help solve your current problem: Hold your mouse over every part of the yellowed line slowly moving it over until it shows exactly what part is broken. This way it lets you see exactly what all the values are for each variable.
Link to comment
Share on other sites

  • 1 month later...
i got this

Public Sub GivePlayerEXP(ByVal index As Long, ByVal EXP As Long)

    ' give the exp

    Call SetPlayerExp(index, GetPlayerExp(index) + EXP)

    SendEXP index

    SendActionMsg GetPlayerMap(index), "+" & EXP & " EXP", White, 1, (GetPlayerX(index) * 32), (GetPlayerY(index) * 32)

    ' check if we've leveled

    CheckPlayerLevelUp index

End Sub

Sub SendEXP(ByVal index As Long)

Dim buffer As clsBuffer

    Set buffer = New clsBuffer

    buffer.WriteLong SPlayerEXP

    buffer.WriteLong GetPlayerExp(index)

    buffer.WriteLong GetPlayerNextLevel(index)

    SendDataTo index, buffer.ToArray()

    Set buffer = Nothing

End Sub

Sub CheckPlayerLevelUp(ByVal index As Long)

    Dim i As Long

    Dim expRollover As Long

    Dim level_count As Long

    level_count = 0

    Do While GetPlayerExp(index) >= GetPlayerNextLevel(index)

        expRollover = GetPlayerExp(index) - GetPlayerNextLevel(index)

        ' can level up?

        If Not SetPlayerLevel(index, GetPlayerLevel(index) + 1) Then

            Exit Sub

        End If

        Call SetPlayerPOINTS(index, GetPlayerPOINTS(index) + 3)

        Call SetPlayerExp(index, expRollover)

        level_count = level_count + 1

    Loop

    If level_count > 0 Then

        If level_count = 1 Then

            'singular

            GlobalMsg GetPlayerName(index) & " has gained " & level_count & " level!", Brown

        Else

            'plural

            GlobalMsg GetPlayerName(index) & " has gained " & level_count & " levels!", Brown

        End If

        SendEXP index

        SendPlayerData index

        SendPlayerSound index, GetPlayerX(index), GetPlayerY(index), SoundEntity.seLevelUp, 1

    End If

End Sub

Public Sub KillPlayer(ByVal index As Long)

Dim EXP As Long

    ' Calculate exp to give attacker

    EXP = GetPlayerExp(index) \ 5

    ' Make sure we dont get less then 0

    If EXP < 0 Then EXP = 0

    If EXP = 0 Then

        Call PlayerMsg(index, "You lost no exp.", BrightRed)

    Else

        Call SetPlayerExp(index, GetPlayerExp(index) - EXP)

        SendEXP index

        Call PlayerMsg(index, "You lost " & EXP & " exp.", BrightRed)

    End If

    Call OnDeath(index)

End Sub

Sub SetPlayerExp(ByVal index As Long, ByVal EXP As Long)

    Player(index).EXP = EXP

    If GetPlayerLevel(index) = MAX_LEVELS And Player(index).EXP > GetPlayerNextLevel(index) Then

        Player(index).EXP = GetPlayerNextLevel(index)

    End If

End Sub
Link to comment
Share on other sites

For GetPlayerExp, it's trying to read a value that can not fit into its variable type.

You'll need to find the value that you're trying to grab and change it, because that is what's causing the error.

GetWeapon = GetPlayerEquipment(attacker, weapon)

This error may happen if there is no weapon equipped, so you need to run a check to see if the weapon is even equipped before you can call it.

Also make sure that (attacker) is being used in the above sub list of variables, otherwise it should be (index)

If GetPlayerEquipment(attacker, weapon) > 0 Then GetWeapon = GetPlayerEquipment(attacker, weapon)
Link to comment
Share on other sites

GetWeapon = GetPlayerEquipment(attacker, weapon)

ah i manage to solve this one the engine put the GetWeapon As Byte i change it to As Long

the left problem left is

Function GetPlayerExp(ByVal index As Long) As Long

    GetPlayerExp = Player(index).EXP

End Function
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...