ID:164940
 
        if(src.bladelvl == 5)
bladetalent(src)
return


What is the best way to go about programming this to say "Every 5 skillpoints, run bladetalent()?

Will I need to manually do every level?
Pakbaum wrote:
>       if(src.bladelvl == 5)
> bladetalent(src)
> return
>

What is the best way to go about programming this to say "Every 5 skillpoints, run bladetalent()?

Will I need to manually do every level?

Nope, you just need to use a formula:

if(bladelvl % 5 == 0)
bladetalent(src)


Lummox JR
In response to Lummox JR
Oh, wonderful! I guess I never looked at what "%" did. Thanks for your help.
In response to Lummox JR
which would be more efficient...

if(bladelvl % 5 == 0)
bladetalent(src)

or...
if(!(bladelvl % 5))
bladetalent(src)


I know this has nothing to do with the topic of the post, but I use the latter example and was wondering if it really made a difference or not.
In response to KirbyAllStar
The latter approach (! operator) is useless, since the result of the % operator (or most mathematical operators for that matter) will never be an empty text string ("") or null, it will only be 0.
In response to Kaioken
Ok thanks.
In response to KirbyAllStar
Because it's part of a procedure that's probably run very infrequently, there is really no reason to fret about it. If it were part of a recursive procedure that would be run through 500 times every tick, then the tiny difference in calculation time one way or the other might become significant -- but since you're probably only checking this every time you increase bladelvl, there isn't much point stress-testing to see which one is faster.

If you're curious, just try

mob/verb/test()
world << time2text(world.realtime)
for(var/i=1,i<=1000000,++i)
if(i % 5 == 0) ++i
sleep() // to make sure world.realtime catches up
world << time2text(world.realtime)
for(var/i=1,i<=1000000,++i)
if(!(i % 5)) ++i
sleep()
world << time2text(world.realtime)


I really don't know which method would work best, but this might give you better resolution since it doesn't involve world.realtime's inaccuracy.

mob/Login()
..()
world << world.time
spawn()
for(var/i=1,i<=1000000,++i)
if(i % 5 == 0) ++i
world << "i % 5 == 0; time=[world.time]"
spawn()
for(var/i=1,i<=1000000,++i)
if(!(i % 5)) ++i
world << "!(i % 5); time=[world.time]"
In response to PirateHead
Amazingly enough neither took up enough time to let the time change when it was run.

Also I don't use bladelvl, just using that from Lummox Jr's post as an example.
In response to KirbyAllStar
You could try increasing one million to ten million, or one billion, to increase the time to the point where it stalls the processor.