ID:178681
 
i cant stop the "cash" variable from going below 0 how do i stop this?
Akarat wrote:
i cant stop the "cash" variable from going below 0 how do i stop this?


Here's an example:

if(src.cash < 0)
src.cash = 0
In response to Nadrew
k where would i put that?
In response to Akarat
Akarat wrote:
k where would i put that?

You might want to try posting the proc you are having the problem with cost in. It would make it easier for people to show you where to apply the fix.

PS: Look... You can't leave someone with a setup like that. You just can't do it. ;)
Akarat wrote:
i cant stop the "cash" variable from going below 0 how do i stop this?

Where exactly is it dropping below 0?

If this happens while shopping, you need to put in a limit so that the buyer can't spend more than they have:
...
if(price>usr.cash)
usr << "You don't have enough money."
return
...

If this is happening when giving cash to another player, you need to account for that too:
verb/GiveCash(n as num)
n=max(min(round(n,1),usr.cash),0)
usr.cash-=n
src.cash+=n

Basically it all boils down to being careful how you use your vars. If you could give us more information about what's going wrong and where, we can be of more assistance.

Lummox JR