AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Run time error 4: index out of bounds (https://forums.alliedmods.net/showthread.php?t=326469)

AnimalMonster 08-01-2020 15:43

Run time error 4: index out of bounds
 
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


Shadows Adi 08-01-2020 15:48

Re: Run time error 4: index out of bounds
 
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.

AnimalMonster 08-01-2020 15:48

Re: Run time error 4: index out of bounds
 
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

AnimalMonster 08-01-2020 15:52

Re: Run time error 4: index out of bounds
 
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?

ZaX 08-01-2020 16:53

Re: Run time error 4: index out of bounds
 
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.

Black Rose 08-01-2020 17:13

Re: Run time error 4: index out of bounds
 
Quote:

Originally Posted by AnimalMonster (Post 2712651)
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

AnimalMonster 08-02-2020 12:02

Re: Run time error 4: index out of bounds
 
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?

AnimalMonster 08-02-2020 12:15

Re: Run time error 4: index out of bounds
 
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

HamletEagle 08-02-2020 14:23

Re: Run time error 4: index out of bounds
 
Both are fine.

fysiks 08-02-2020 14:23

Re: Run time error 4: index out of bounds
 
Quote:

Originally Posted by AnimalMonster (Post 2712718)
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 (Post 2712720)
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.


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

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