Dawntide Posted August 22, 2012 Author Share Posted August 22, 2012 hey,The engine is jealous of all my moneyIf 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 overflowhow to fix it and how to set a limit for currency without getting crash if you try to get more moneythanks! Link to comment Share on other sites More sharing options...
Joyce Posted August 22, 2012 Share Posted August 22, 2012 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 More sharing options...
Dawntide Posted August 22, 2012 Author Share Posted August 22, 2012 I want the limit to be 999.999.999 Gold.How to do it? I do not want to add this check in 100 subs where gold is handed out Link to comment Share on other sites More sharing options...
Joyce Posted August 22, 2012 Share Posted August 22, 2012 The limit of a Long is 2,147,483,647And 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 More sharing options...
Ecto Posted August 22, 2012 Share Posted August 22, 2012 > 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 More sharing options...
Dawntide Posted August 22, 2012 Author Share Posted August 22, 2012 Ok so how would the code look like? I can not find a single code where gold is handed outonly something like this at bank etc.```tmpCurrencyItem = InvNum``` Link to comment Share on other sites More sharing options...
Growlith1223 Posted August 24, 2012 Share Posted August 24, 2012 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 LongShould work Link to comment Share on other sites More sharing options...
Joyce Posted August 24, 2012 Share Posted August 24, 2012 > 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 workThis, 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 More sharing options...
Dawntide Posted August 24, 2012 Author Share Posted August 24, 2012 Then tell me how to do it, please. Link to comment Share on other sites More sharing options...
blkcrow Posted August 25, 2012 Share Posted August 25, 2012 you can use the currency data type i dont know how the socket system is gonna take it thou Link to comment Share on other sites More sharing options...
Ruins of Hell Posted August 25, 2012 Share Posted August 25, 2012 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 = 0End IfEnd 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 More sharing options...
Dawntide Posted August 26, 2012 Author Share Posted August 26, 2012 I just want to want stop the overflow crash, so the player simply just can not get more gold. 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