open.mp forum
[Pawn] Error 4: Index Out Of Bound - Printable Version

+ open.mp forum (https://forum.open.mp)
-- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3)
--- Forum: Pawn Scripting (https://forum.open.mp/forumdisplay.php?fid=10)
--- Thread: [Pawn] Error 4: Index Out Of Bound (/showthread.php?tid=1277)



Error 4: Index Out Of Bound - Jonies - 2020-10-25

Whats wrong with my code?


PHP Code:
#define MAX_GIFT 100

LoadGiftEvent()
{
? ? new 
rows;
? ? 
cache_get_row_count(rows);? 
? ? if(!
rows) return 0;

? ? for(new 
0MAX_GIFTi)
? ? {
? ? ? ? 
cache_get_value_name_int(i"id"g_gift[i][G_SQL_ID]);
? ? ? ? 
cache_get_value_name_float(i"x"g_gift[i][G_POS_X]);
? ? ? ? 
cache_get_value_name_float(i"y"g_gift[i][G_POS_Y]);
? ? ? ? 
cache_get_value_name_float(i"z"g_gift[i][G_POS_Z]);
? ? ? ? 
TotalGift;
? ? }
? ? 
RandomizeGift();
? ? 
printf("[MySQL R41-3]: Gift diunggah: %i pcs."TotalGift);
? ? return 
1;
}

Randomize()
{
    
//No Error There


Error :?
PHP Code:
[debugRun time error 4"Array index out of bounds"
[21:50:52] [debug]  Attempted to read/write array element at index 1034098284 in array of size 100
[21:50:52] [debugAMX backtrace:
[
21:50:52] [debug#0 00535c3c in ?? () from new.amx
[21:50:52] [debug#1 00511eb4 in public LoadGiftEvent () from new.amx 

Database
PHP Code:
+---+---------+---------+-------
id x? ? ? ? | y? ? ? ? | z? ? ? |
+---+---------+---------+-------
|? 
|? 961.241 | -1445.19 13.452 |
|? 
|? 1480.38 | -1638.49 14.148 |
|? 
|? 2157.07 | -1591.43 14.367 |
|? 
|? 1911.26 | -1776.76 13.383 |
|? 
|? 1110.03 | -1794.52 16.594 |
|? 
|? 835.95 | -2001.94 12.887 |
|? 
|? 348.408 | -1799.52 |? 4.815 |
|? 
|? 311.593 | -1797.88 |? 4.558 |
|? 
|? 389.555 | -1521.73 32.278 |
10 |? 484.068 | -1514.09 20.305 |
11 |? 1007.2 | -1349.95 13.384 |
12 |? 660.498 | -457.695 16.336 |
13 |? 701.584 | -457.038 16.336 |
14 |? 33.179 | -230.749 |? 5.499 |
15 |? 207.187 | -173.123 |? 1.594 |
16 |? 155.693 | -167.684 |? 1.578 |
17 |? -62.499 |? 45.752 |? 3.11 |
18 |? -39.79 |? 52.641 |? 6.484 |
19 |? 1347.72 |? 346.591 20.068 |
20 |? 1319.34 |? 402.335 21.041 |
21 |? 1626.3 |? 613.707 |? 7.781 |
22 |? 1637.01 |? 723.854 |? 10.82 |
23 |? 1668.25 |? 1012.54 10.846 |
24 |? 2119.13 |? 1332.83 |? 10.82 |
25 |? 2003.2 |? 1544.19 13.586 |
26 |? 1973.1 |? 1623.26 12.862 |
27 |? 1878.8 |? 1794.85 18.934 |
28 |? 2215.83 | -1167.89 25.743 |
29 |? 2290.2 | -1527.98 26.875 |
30 |? 2459.42 |? -1711.8 13.569 |
31 |? 2262.56 | -1788.16 13.547 |
32 |? 2162.9 | -1775.89 19.838 |
33 |? 1993.77 | -1779.85 17.362 |
34 |? 1862.91 | -1872.31 |? 13.51 |
35 |? 1199.06 | -1731.43 13.605 |
36 |? 665.22 | -1865.49 |? 5.492 |
37 |? 154.094 |? -1963.4 |? 3.815 |
38 | -376.609 | -1424.06 25.754 |
39 | -1678.19 | -581.488 |? 14.18 |
40 | -1609.76 | -492.925 |? 22.11 |
41 | -1250.41 |? -99.605 14.186 |
42 | -1991.22 |? 148.402 27.611 |
43 |? -1927.3 |? 264.146 41.065 |
44 | -2255.51 |? 539.933 35.191 |
45 | -2490.46 |? 1078.68 56.197 |
46 | -2666.56 |? 1809.75 68.217 |
47 |? 206.315 |? 2506.19 16.515 |
48 |? 1692.45 |? 1445.19 10.783 |
49 |? 1610.13 |? 1599.86 |? 10.86 |
50 |? 1766.05 | -1919.73 |? 13.6 |
+---+---------+---------+------- 



RE: Error 4: Index Out Of Bound - Pinch - 2020-10-25

Code:
#define MAX_GIFT 100



LoadGiftEvent()

{

    new rows;

    cache_get_row_count(rows);  

    if(!rows) return 0;



    for(new i = 0; i < rows; i)

    {

        cache_get_value_name_int(i, "id", g_gift[i][G_SQL_ID]);

        cache_get_value_name_float(i, "x", g_gift[i][G_POS_X]);

        cache_get_value_name_float(i, "y", g_gift[i][G_POS_Y]);

        cache_get_value_name_float(i, "z", g_gift[i][G_POS_Z]);

        TotalGift;

    }

    RandomizeGift();

    printf("[MySQL R41-3]: Gift diunggah: %i pcs.", TotalGift);

    return 1;

}



Randomize()

{

    //No Error There

}

This shouldn't fix it, however I "fixed" the loop



Give us the structure of g_gift (enum declaration)


RE: Error 4: Index Out Of Bound - Expert* - 2020-10-26

PHP Code:
for(new 0rows && MAX_GIFTi

or

PHP Code:
for(new 0rowsi)
{
? ? if( 
==?MAX_GIFT ) break;
? ? 
// ... 



RE: Error 4: Index Out Of Bound - Pinch - 2020-10-26

(2020-10-26, 10:06 AM)Expert* Wrote:
PHP Code:
for(new 0rows && MAX_GIFTi



or



PHP Code:
for(new 0rowsi)

{

? ? if( 
==?MAX_GIFT ) break;

? ? 
// ... 

Uhm, it obviously isn't a problem because their database's ending is 50 and their loop was already limiting it to MAX_GIFT :D

But yeah, if( i ==?MAX_GIFT ) break; is fine



It's something else, probably related to g_gift


RE: Error 4: Index Out Of Bound - Expert* - 2020-10-26

(2020-10-26, 10:30 AM)Pinch Wrote:
(2020-10-26, 10:06 AM)Expert* Wrote:
PHP Code:
for(new 0rows && MAX_GIFTi



or



PHP Code:
for(new 0rowsi)

{

? ? if( 
==?MAX_GIFT ) break;

? ? 
// ... 

Uhm, it obviously isn't a problem because their database's ending is 50 and their loop was already limiting it to MAX_GIFT :D

But yeah, if( i ==?MAX_GIFT ) break; is fine



It's something else, probably related to g_gift



Just in case. He doesn't look like someone who knows what he is doing...


RE: Error 4: Index Out Of Bound - Pinch - 2020-10-26

(2020-10-26, 10:47 AM)Expert* Wrote:
(2020-10-26, 10:30 AM)Pinch Wrote:
(2020-10-26, 10:06 AM)Expert* Wrote:
PHP Code:
for(new 0rows && MAX_GIFTi

or

PHP Code:
for(new 0rowsi)
{
? ? if( 
==?MAX_GIFT ) break;
? ? 
// ... 
Uhm, it obviously isn't a problem because their database's ending is 50 and their loop was already limiting it to MAX_GIFT :D
But yeah, if( i ==?MAX_GIFT ) break; is fine

It's something else, probably related to g_gift

Just in case. He doesn't look like someone who knows what he is doing...
I know but in his code it's impossible to go over 100 anyways... It's < MAX_GIFTS....


RE: Error 4: Index Out Of Bound - Jonies - 2020-10-27

Btw from whare 1034098284 come out?


RE: Error 4: Index Out Of Bound - Expert* - 2020-10-30

(2020-10-26, 11:02 AM)Pinch Wrote:
(2020-10-26, 10:47 AM)Expert* Wrote:
(2020-10-26, 10:30 AM)Pinch Wrote:
(2020-10-26, 10:06 AM)Expert* Wrote:
PHP Code:
for(new 0rows && MAX_GIFTi



or



PHP Code:
for(new 0rowsi)

{

? ? if( 
==?MAX_GIFT ) break;

? ? 
// ... 

Uhm, it obviously isn't a problem because their database's ending is 50 and their loop was already limiting it to MAX_GIFT :D

But yeah, if( i ==?MAX_GIFT ) break; is fine



It's something else, probably related to g_gift



Just in case. He doesn't look like someone who knows what he is doing...

I know but in his code it's impossible to go over 100 anyways... It's < MAX_GIFTS....



I was commenting on your example.. ?

Unless we think that his?SQL statement is?limited to MAX_GIFT??... ( We can't see it so i doubt it?)


RE: Error 4: Index Out Of Bound - Expert* - 2020-10-30

(2020-10-27, 06:42 AM)Jonies Wrote: Btw from whare 1034098284 come out?

Give us RandomizeGift.


Btwm, your?Signature picture is too big, can u make it like 3 times?smaller plz (h)


RE: Error 4: Index Out Of Bound - Pinch - 2020-10-30

(2020-10-30, 07:53 PM)Expert* Wrote:
(2020-10-27, 06:42 AM)Jonies Wrote: Btw from whare 1034098284 come out?



Give us RandomizeGift.





Btwm, your?Signature picture is too big, can u make it like 3 times?smaller plz (h)

If I understood correctly, Randomize() is RandozimeGift() ??