Raised This Month: $51 Target: $400
 12% 

Run time error 11: divide


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Gasa
Senior Member
Join Date: Sep 2013
Old 06-14-2014 , 16:01   Run time error 11: divide
Reply With Quote #1

[AMXX] Run time error 11: divide
[AMXX] [0] amx_fire.sma::fire_flamethrower (line 179)

179 line is:
PHP Code:
velocityvec[0]=velocityvec[0]*speed/length 
Any help pls! What exactly means divide error?
PHP Code:
fire_flamethrower(id){

        
emit_sound(idCHAN_WEAPON"ambience/flameburst1.wav"1.0ATTN_NORM0PITCH_NORM)
        
//client_cmd(id, "bind mouse3 lallamitaywea")
        
new vec[3]
        new 
aimvec[3]
        new 
velocityvec[3]
        new 
length
        
new speed 10
        get_user_origin
(id,vec)
        
get_user_origin(id,aimvec,2)
        new 
dist get_distance(vec,aimvec)

        new 
speed1 160
        
new speed2 350
        
new radius 105

        
if(dist 50){
            
radius 0
            speed 
5
        
}
        else if(
dist 150){
            
speed1 speed2 1
            speed 
5
            radius 
50
        
}
        else if(
dist 200){
            
speed1 speed2 1
            speed 
5
            radius 
90
        
}
        else if(
dist 250){
            
speed1 speed2 90
            speed 
6
            radius 
90
        
}
        else if(
dist 300){
            
speed1 speed2 140
            speed 
7
        
}
        else if(
dist 350){
            
speed1 speed2 190
            speed 
7
        
}
        else if(
dist 400){
            
speed1 150
            speed2 
240
            speed 
8
        
}
        else if(
dist 450){
            
speed1 150
            speed2 
290
            speed 
8
        
}
        else if(
dist 500){
            
speed1 180
            speed2 
340
            speed 
9
        
}
        else if(
dist 550){
            
speed1 180
            speed2 
340
            speed 
10
        
}
        else if(
dist 600){
            
speed1 250
            speed2 
360
            speed 
11
        
}
        else if(
dist 660){
            
speed1 280
            speed2 
390
            speed 
12
        
}
        
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[0]*speed/length
        velocityvec
[1]=velocityvec[1]*speed/length
        velocityvec
[2]=velocityvec[2]*speed/length

        
new args[8]
        
args[0] = vec[0]
        
args[1] = vec[1]
        
args[2] = vec[2]
        
args[3] = velocityvec[0]
        
args[4] = velocityvec[1]
        
args[5] = velocityvec[2]
        
set_task(0.1,"te_spray",0,args,8,"a",2)
        
check_burnzone(id,vec,aimvec,speed1,speed2,radius)
        
//set_task(0.5,"client_bind",id)
                
        
return PLUGIN_CONTINUE



Last edited by Gasa; 06-14-2014 at 16:01.
Gasa is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 06-14-2014 , 16:19   Re: Run time error 11: divide
Reply With Quote #2

It is simple math. You have multiplication and dividing in one expression. Just put some brackets () on the multiplication or in the dividing. Depends of what you want but in this case I think you should put the multiplication expression in the brackets.
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
Gasa
Senior Member
Join Date: Sep 2013
Old 06-14-2014 , 16:29   Re: Run time error 11: divide
Reply With Quote #3

Hm can u give me example?
Gasa is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 06-14-2014 , 16:36   Re: Run time error 11: divide
Reply With Quote #4

PHP Code:
velocityvec[0]= (velocityvec[0]*speed) / length 
or
PHP Code:
velocityvec[0]= velocityvec[0] * (speed/length
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
Gasa
Senior Member
Join Date: Sep 2013
Old 06-14-2014 , 16:58   Re: Run time error 11: divide
Reply With Quote #5

Thx for help, this means if u dont follow math rules in dividing u will get error!
Gasa is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 06-14-2014 , 23:08   Re: Run time error 11: divide
Reply With Quote #6

I think it's because you're dividing by 0.
__________________
Black Rose is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-14-2014 , 23:15   Re: Run time error 11: divide
Reply With Quote #7

Quote:
Originally Posted by Flick3rR View Post
It is simple math. You have multiplication and dividing in one expression. Just put some brackets () on the multiplication or in the dividing. Depends of what you want but in this case I think you should put the multiplication expression in the brackets.
This should not be necessary. Order of operations is handled correctly by the compiler (afaik). In light of that, there is no difference between multiplying first or dividing first.

However, one major flaw here is that the variables are not floating point variables which will result in integer division. This is occasionally beneficial but not in this case. The sqrt() outputs a floating point value but "length" is not floating point.

The error is probably occurring from a division by zero.
__________________

Last edited by fysiks; 06-15-2014 at 22:11. Reason: typo
fysiks is offline
Gasa
Senior Member
Join Date: Sep 2013
Old 06-15-2014 , 07:34   Re: Run time error 11: divide
Reply With Quote #8

Quote:
Originally Posted by Black Rose View Post
I think it's because you're dividing by 0.
You are right same error even with () .But if i check is lenght == 0 ,flame not working!

Last edited by Gasa; 06-15-2014 at 07:36.
Gasa is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 06-15-2014 , 08:33   Re: Run time error 11: divide
Reply With Quote #9

Then, you should not divide by 0.
HamletEagle is offline
Kiske
Veteran Member
Join Date: May 2009
Old 06-15-2014 , 21:35   Re: Run time error 11: divide
Reply With Quote #10

Quote:
Originally Posted by Gasa View Post
But if i check is lenght == 0 ,flame not working!
PHP Code:
velocityvec[0]=velocityvec[0]*speed/length
velocityvec
[1]=velocityvec[1]*speed/length
velocityvec
[2]=velocityvec[2]*speed/length 
->

PHP Code:
if(length != 0) {
    
velocityvec[0]=velocityvec[0]*speed/length
    velocityvec
[1]=velocityvec[1]*speed/length
    velocityvec
[2]=velocityvec[2]*speed/length
} else {
    
velocityvec[0]=velocityvec[0]*speed
    velocityvec
[1]=velocityvec[1]*speed
    velocityvec
[2]=velocityvec[2]*speed

__________________

Kiske is offline
Send a message via Skype™ to Kiske
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 20:41.


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