ID:152215
 
I have a quick 'Design' question.

I have a weight system; and say that the total weight is determined by your Strength and Endurance.

Would it lag a lot if I kept a constant check on that;

mob/proc
weightCalc()
while(src)
src.weightTotal = (10+(endurance*5)+(strength))


Something like that?
Heh, er, yer, it would lag... a LOT. The game would be unplayable. Yet even if you put a sleep(20) into that loop it would still be completely unfeasible. Just call the weightCalc() proc every time you change their endurance and strength. It can't be that often, probably (knowing most games) only every level up!

~Ease~
In response to Ease
Well, there's more than just a level up.

Ill call it on Equips too; seeing as I plan to have plenty of enchanted weapons.
First, I think you've made a mistake on how you calculate weight. Wouldn't it make more sense that weight is the weight of the items you're carrying/have on? From there you can calculate the actual effect on stamina/endurance/etc as you wish.

But to your design question, you should only update weight on occasions where an item is picked up or dropped. (Possibly other circumstances, but those for sure)
In response to Cheetoz
Nope, you're looking at the wrong variable.

weightTotal is how much weight you can carry all-in-all.

My other variable; weightCarrying, is how much is being carried.
In response to LucifersHellion
Assuming you're not using this value all the time, the best way to do this is make an accessor for weightTotal; remove the variable entirely, and everywhere you need to use it make a call to:

mob/proc
weightTotal()
return 10 + endurance*5 + strength


Since it's a simple calculation they'll be only a little overhead in calculating it when you need it, and this way you won't have to add an (e.g.) updateWeightTotal() call every time you change the strength or endurance variables.

(Alternately, you can keep the weightTotal variable, and make mutators for setStrength and setEndurance that also update weightTotal, but that is probably not worth the effort.)
In response to LucifersHellion
Sorry about that, but my suggestion on only updating weight when items are picked up or dropped still stands.
Instead of updating a variable in a loop (which is a horrible idea) why not just make a proc to check the weight, or better yet simply check the math any time you check their weight.

//Example:
if( (10+(endurance*5)+(strength)) > 100 )
// This way does your math when you actually check the weight
src<<"You weigh too much fatty!"
else src<<"You could put on a few pounds."


Another less-efficient way (I'd imagine) would be this

mob/proc/weight_check()
return (10+(endurance*5)+(strength))
// I guess this would be easier if you're changing it around alot.

if( weight_check() > 100 ) src<<"You put on a red shirt and the kids yell Kool-Aid!"
else src<<"Make way for Ally McBeil..."


Both ways won't kill your game like that loop will. And for the record, when you do actually decide to use a loop to check things, make sure you include some sort of delay or you're gonna crash and burn the game.