Raised This Month: $ Target: $400
 0% 

Run time error 11: divide


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
JuanitoAlimana
Senior Member
Join Date: Aug 2021
Old 06-09-2024 , 01:46   Run time error 11: divide
Reply With Quote #1

Displaying debug trace (plugin "piss.amxx", version "2.0")
[AMXX] Run time error 11: divide
[AMXX] [0] piss.sma::make_pee (line 89)

How to solve this?

PHP Code:
public make_pee(ids[]) 

    new 
id=ids[0]
    new 
vec[3
    new 
aimvec[3
    new 
velocityvec[3
    new 
length 
    get_user_origin
(id,vec
    
get_user_origin(id,aimvec,3
    new 
distance get_distance(vec,aimvec
    new 
speed floatround(distance*1.9)

    
velocityvec[0]=aimvec[0]-vec[0
    
velocityvec[1]=aimvec[1]-vec[1
    
velocityvec[2]=aimvec[2]-vec[2

    
length=sqrt(velocityvec[0]*velocityvec[0]+velocityvec[1]*velocityvec[1]+velocityvec[2]*velocityvec[2]) 

    
velocityvec[0]=velocityvec[1]*speed/length /// line 89
    
velocityvec[1]=velocityvec[2]*speed/length 
    velocityvec
[2]=velocityvec[0]*speed/length 
JuanitoAlimana is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-09-2024 , 11:29   Re: Run time error 11: divide
Reply With Quote #2

Quote:
Originally Posted by JuanitoAlimana View Post
Displaying debug trace (plugin "piss.amxx", version "2.0")
[AMXX] Run time error 11: divide
[AMXX] [0] piss.sma::make_pee (line 89)

How to solve this?

PHP Code:
public make_pee(ids[]) 

    new 
id=ids[0]
    new 
vec[3
    new 
aimvec[3
    new 
velocityvec[3
    new 
length 
    get_user_origin
(id,vec
    
get_user_origin(id,aimvec,3
    new 
distance get_distance(vec,aimvec
    new 
speed floatround(distance*1.9)

    
velocityvec[0]=aimvec[0]-vec[0
    
velocityvec[1]=aimvec[1]-vec[1
    
velocityvec[2]=aimvec[2]-vec[2

    
length=sqrt(velocityvec[0]*velocityvec[0]+velocityvec[1]*velocityvec[1]+velocityvec[2]*velocityvec[2]) 

    
velocityvec[0]=velocityvec[1]*speed/length /// line 89
    
velocityvec[1]=velocityvec[2]*speed/length 
    velocityvec
[2]=velocityvec[0]*speed/length 
When you need to debug an error think about what may be happening. First thing that comes to mind is division by zero, which will produce an error.

So you can either do a server_print() or log() of the speed and length variables to ensure they are valid/expected values, or just ensure they are non-zero before executing that code.

PHP Code:
//Identify if division by zero is the issue, and then adjust code to ensure this doesnt happen to begin with
server_print"speed=%d length=%d" speed length )

//or if this is expected, just have alternate code in place if you cannot do what is expected.
if ( speed && length )
{
    
velocityvec[0]=velocityvec[1]*speed/length /// line 89
    
velocityvec[1]=velocityvec[2]*speed/length 
    velocityvec
[2]=velocityvec[0]*speed/length 
}
else
{
    
//speed or length was zero so do something else.

__________________

Last edited by Bugsy; 06-09-2024 at 11:31.
Bugsy is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:44.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode