Raised This Month: $18 Target: $400
 4% 

Run time error 4: index out of bounds


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
AnimalMonster
Member
Join Date: May 2020
Old 08-01-2020 , 15:43   Run time error 4: index out of bounds
Reply With Quote #1

PHP Code:
public hud(id)
{
    new 
cooldown countdown[id] + 1
    
new cooldown1 countdown1[id] + 1

    
if(cooldown == 0)
    {
        
set_hudmessage(12725585, -1.00.8306.00.9)
        
show_hudmessage(id"[Berserk - Ready] [G]")
        
ready[id] = 1
    
}
    else {
        
set_hudmessage(12725585, -1.00.8306.00.9)
        
show_hudmessage(id"[Berserk - %d] [G]",countdown[id] + 1)
    }
    
    if(
cooldown1 == 0)
    {
        
set_hudmessage(12725585, -1.00.8306.00.9)
        
show_hudmessage(id"^n[Reproduce - Ready] [R]")
        
ready1[id] = 1
    
}
    else {
        
set_hudmessage(12725585, -1.00.8306.00.9)
        
show_hudmessage(id"^n[Reproduce - %d] [R]",countdown1[id] + 1)
    }
    if(
cooldown == 10)
    {
        new 
fovn 110
        fm_set_rendering
(idkRenderFxGlowShell,255,0,0,kRenderNormal,20)
        
set_pev(id,pev_fovfovn)
        
set_pev(id,pev_speedspeed)
        
emit_sound(id,CHAN_VOICE,ability1end,1.0,ATTN_NORM,0,PITCH_NORM)
    }

Why do i get run time error 4: index out of bounds here?:
PHP Code:
if(cooldown == 0
__________________
A little of scripting makes a MIRACLE.
=============================================
DeclineD#7346 // for everyone who wants a friend..
AnimalMonster is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 08-01-2020 , 15:48   Re: Run time error 4: index out of bounds
Reply With Quote #2

First of all, your code is a mess.
You get index out of bounds because the index it's out of range, you should show where is called the public func.
__________________

Last edited by Shadows Adi; 08-01-2020 at 15:48.
Shadows Adi is offline
AnimalMonster
Member
Join Date: May 2020
Old 08-01-2020 , 15:48   Re: Run time error 4: index out of bounds
Reply With Quote #3

That's some code from my probably bad coded zombie

P.S: sunt roman, daca vrei ma poti ajuta pe dis privat daca iti e mai usor
__________________
A little of scripting makes a MIRACLE.
=============================================
DeclineD#7346 // for everyone who wants a friend..

Last edited by AnimalMonster; 08-01-2020 at 15:49.
AnimalMonster is offline
AnimalMonster
Member
Join Date: May 2020
Old 08-01-2020 , 15:52   Re: Run time error 4: index out of bounds
Reply With Quote #4

The function is called when the player gets zombie and i did set_task(1.0,"hud",id + task,_,_,"b")

Edit: May i give full code? Even if it's just a lot of trash in it but yeah

At the start i did a new countdown[33], this has something to do with this?
__________________
A little of scripting makes a MIRACLE.
=============================================
DeclineD#7346 // for everyone who wants a friend..

Last edited by AnimalMonster; 08-01-2020 at 16:10.
AnimalMonster is offline
ZaX
Senior Member
Join Date: Jan 2015
Old 08-01-2020 , 16:53   Re: Run time error 4: index out of bounds
Reply With Quote #5

countdown[33] holds 32 indexes, so you need to get users proper id in the task callback function
Code:
public task_callback(taskid)
{
    new id = taskid - task
}
Also cooldown will hold only 1 value and it will change everytime the function gets called.
ZaX is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Upplands Väsby, Sweden
Old 08-01-2020 , 17:13   Re: Run time error 4: index out of bounds
Reply With Quote #6

Quote:
Originally Posted by AnimalMonster View Post
The function is called when the player gets zombie and i did set_task(1.0,"hud",id + task,_,_,"b")

Edit: May i give full code? Even if it's just a lot of trash in it but yeah

At the start i did a new countdown[33], this has something to do with this?
Please do.
Also, please show the full error code including which line has the error and if possible, highlight it using a comment or @@ at the beginning of the row within [ pawn ] tags
__________________
Black Rose is offline
AnimalMonster
Member
Join Date: May 2020
Old 08-02-2020 , 12:02   Re: Run time error 4: index out of bounds
Reply With Quote #7

Never mind, the problem in sma was that the taskids we're confused to the player's id so that was the problem, imma reply after im trying to solve.

Edit: also got a question..
If i want to rrmove the task all from once what should i do?
__________________
A little of scripting makes a MIRACLE.
=============================================
DeclineD#7346 // for everyone who wants a friend..

Last edited by AnimalMonster; 08-02-2020 at 12:07.
AnimalMonster is offline
AnimalMonster
Member
Join Date: May 2020
Old 08-02-2020 , 12:15   Re: Run time error 4: index out of bounds
Reply With Quote #8

PHP Code:
Funtion(task)
{
      new 
id task taskid
      
new id1 task taskid1
      
if(task_exists(id))
      {
              
remove_task(id)
      }
      
//...

After first if
Doing the same if but with id2
Or
PHP Code:
Function(task)
{
      New 
id task taskid
      
If(task_exists(id))
      {
              
remove_task(id))
      }
      
id task taskid1
      
If(task_exists(id))
      {
              
remove_task(id)
      }

If i do this , that can confuse the plugin i think.




Edit: i know it s a stupid question but yesh, and ik you guys will say the the firdt one is good and the bad one is the ladt one
__________________
A little of scripting makes a MIRACLE.
=============================================
DeclineD#7346 // for everyone who wants a friend..

Last edited by AnimalMonster; 08-02-2020 at 12:29.
AnimalMonster is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-02-2020 , 14:23   Re: Run time error 4: index out of bounds
Reply With Quote #9

Both are fine.
__________________
HamletEagle is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-02-2020 , 14:23   Re: Run time error 4: index out of bounds
Reply With Quote #10

Quote:
Originally Posted by AnimalMonster View Post
Never mind, the problem in sma was that the taskids we're confused to the player's id so that was the problem, imma reply after im trying to solve.
ZaX gave you the solution.

Quote:
Originally Posted by AnimalMonster View Post
PHP Code:
Funtion(task)
{
      new 
id task taskid
      
new id1 task taskid1
      
if(task_exists(id))
      {
              
remove_task(id)
      }
      
//...

After first if
Doing the same if but with id2
Or
PHP Code:
Function(task)
{
      New 
id task taskid
      
If(task_exists(id))
      {
              
remove_task(id))
      }
      
id task taskid1
      
If(task_exists(id))
      {
              
remove_task(id)
      }

If i do this , that can confuse the plugin i think.




Edit: i know it s a stupid question but yesh, and ik you guys will say the the firdt one is good and the bad one is the ladt one
Neither one make sense. If you have a new topic, start a new thread.
__________________
fysiks is offline
Reply


Thread Tools
Display Modes

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 14:24.


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