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

Engine is jealous of my money


Dawntide
 Share

Recommended Posts

hey,

The engine is jealous of all my money

If i spawn 2 billion gold everything is fine, but if i spawn another billion gold the game crashes.

debug highlighting:

```

Call SetPlayerInvItemValue(Index, n, GetPlayerInvItemValue(Index, n) + MapItem(mapnum, i).Value)

```

runtime error overflow

how to fix it and how to set a limit for currency without getting crash if you try to get more money

thanks!
Link to comment
Share on other sites

This is because there is a limit on how much a Long can hold. Just write a check before you hand out gold every time if the amount doesn't go over a specified cap, and hand it out if it does not.. If it does, set the money to the cap and notify the user.
Link to comment
Share on other sites

The limit of a Long is 2,147,483,647

And you'll need to add the limit check everywhere manually. No other way really, unless you write a sub that hands out gold and checks it, then replace every place that hands out gold with that sub.
Link to comment
Share on other sites

> The limit of a Long is 2,147,483,647
>
> And you'll need to add the limit check everywhere manually. No other way really, unless you write a sub that hands out gold and checks it, then replace every place that hands out gold with that sub.

Writing a sub would probably be easier and cleaner to be honest.

Edit: You could also just start a second stack of cash if the user hits the cap.
Link to comment
Share on other sites

> to make the money to go unlimited go into the Public Type ItemRec(i think)
>
> and look for the currency amount and if there, delete the part that says As Long
>
> Should work

This, is the most stupid and dumb was to do this ever, because such large numbers will crash the bloody socket system still. We're sending longs there, and we can't push such large things. Actually, even then it's not unlimited but whatever. You really shouldn't try "fixing" stuff by removing declarations, they're there for a reason, memory management and faster calculations. Don't remove such things.
Link to comment
Share on other sites

You could just check for overflow, here's a quick example function. Note that it only works for a, b > 0, and integer a and b.

It wouldn't let you go over 2 billion, but it will prevent the wrapping to negative numbers.

```

' Returns 0, if there is no overflow, or the overflow, if one exists. '

Function AddCheckOverflow(ByVal a As Currency, ByVal b As Currency) As Long ' Currency is 8 bytes, as opposed to Long's 4 bytes. ''

If a + b > MAX_LONG Then

AddCheckOverflow = CLng((a - MAX_LONG) + ![B)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/cool.png)

Else

AddCheckOverflow = 0

End If

End Function

```

You could then put the overflow in another stack, and then add on to the other stack (note that you should edit the inventory system to merge stacks when possible).

Some other options:

* Add to the packet engine to allow Currency (~1015 gold)
* Put the overflow in other stacks.
* Add a new system (like 1,000,000 gold -> 1 billagold; 1,000,000 billagold -> 1 quadgold) to allow a maximum of ~1027 gold, more than you'll ever need.
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...