SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 14/02/2020, 10:21 AM   #1
Vizi10
Huge Clucker
 
Join Date: May 2017
Location: Iran
Posts: 312
Reputation: 8
Default Loop starts from 100 to 0

pawn Code:
new count;
for(new c = MAX_ADS, e = ad_LastMessageID[0]; e<c; --c) //`MAX_ADS` is 100 and `ad_LastMessageID[0]` is 0
{
     if(Advertisement[c][Ads_Type] == ADS_TYPE_HOUSE) ad_LastMessageID[0] = c, count++;
     break;
}
if(!count) //If there is no ad
{
     ads_TimeCounter[2] = 10*60;
     ad_LastMessageID[0] = 0;
     return 1;
}

Code:
[03:17:27] [debug] Run time error 4: "Array index out of bounds"
[03:17:27] [debug]  Attempted to read/write array element at index 100 in array of size 100
[03:17:27] [debug] AMX backtrace:
[03:17:27] [debug] #0 00063c14 in AdvertisementUpdate () at ..\include\adv.inc:1657
[03:17:27] [debug] #1 0008b850 in public OnServerUpdate () at E:\[AG]\gamemodes\local.pwn:1065
Where am I wrong?
Vizi10 is online now   Reply With Quote
Old 14/02/2020, 10:48 AM   #2
Boarden
Little Clucker
 
Boarden's Avatar
 
Join Date: Jun 2014
Location: (Formerly Great) Britain
Posts: 33
Reputation: 4
Default Re: Loop starts from 100 to 0

Code:
for(new i = MAX_ADS - 1; i >= 0; i--)
{

}
Arrays start at position 0, so allocating 100 indexes to the array gives you 0-99.
__________________
Boarden is offline   Reply With Quote
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Ajuda] Loop parando a funcao (meio que nao continua depois do loop) Axll PortuguÍs/Portuguese 16 15/02/2014 05:34 PM
for( ) loop vs while( ) loop | While( ) loop is 143x faster? zgintasz Scripting Help 17 03/07/2012 12:57 PM
[HELP] Compile starts GTA SA. Lynn Client Support 11 22/04/2012 12:26 PM
How to get script that starts EXACTLY when an NPC's path starts MisterTickle Scripting Help 11 18/09/2011 09:03 AM


All times are GMT. The time now is 12:45 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.