Author Topic: Need help optimizing this code.  (Read 3443 times)

Offline Karpov

  • Come Together
Need help optimizing this code.
« on: February 19, 2013, 09:49:01 pm »
Hello. I need help on this programming stuff, I'm not very good at this.

In this part of the script, the idea is to link the Items to the 3d model it is used for each. Originally, many different items used the same model, so there was a list in there for this purpose. But now I linked all of the items to an unique 3d model value, and matched the number on purpose just to keep it easy. This is how I did it:

Code: [Select]
#ifdef PLAYERS_3D
int GetHandleValue( uint16 pid )
{
    if( pid == 0 || ( pid >= 1000 && pid <= 1100 ) )
        return 0;

    int handle = 0;
    switch( pid )
    {
case 1 : handle = 1 ;                break;
case 2 : handle = 2 ;                break;
case 3 : handle = 3 ;                break;
case 4 : handle = 4 ;                break;
...
and so on.
...
}
    return handle;
}
#endif

Does it work? yes, it does. Now, since all of the Items PIDs match the value I set for the 3d models, I think there has to be a better way to solve this.
 What should that be?

Thanks.

JovankaB

  • Guest
Re: Need help optimizing this code.
« Reply #1 on: February 19, 2013, 09:59:52 pm »
if pid is always the same as handle, why don't you just return the pid as handle?

All you need is to cast the type to int:

return int(pid);
« Last Edit: February 19, 2013, 10:01:38 pm by JovankaB »

Offline Karpov

  • Come Together
Re: Need help optimizing this code.
« Reply #2 on: February 19, 2013, 11:16:32 pm »
if pid is always the same as handle, why don't you just return the pid as handle?

All you need is to cast the type to int:

return int(pid);

Why? because I have no idea what I'm doing  ;D 

Obviously you do, thanks a lot! It works.