SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 18/06/2012, 04:51 PM   #591
Gigi-The-Beast
Huge Clucker
 
Join Date: Jan 2010
Posts: 230
Reputation: 5
Default Re: foreach - 0.3 compatible - updated 06/08/10

edit: found the problem, please delete the post
Gigi-The-Beast is offline   Reply With Quote
Old 18/06/2012, 10:00 PM   #592
Kar
High-roller
 
Join Date: May 2010
Location: Black Asylum
Posts: 2,876
Reputation: 280
Default Re: foreach - 0.3 compatible - updated 06/08/10

Quote:
Originally Posted by Y_Less View Post
This is officially the most useful bug report I've had on this! A few people have mentioned crashes before, but none have bothered to mention that they were using multi-dimensional arrays declared with the new unified syntax instead of the old "IteratorArray:" tag! As a result, I have found and fixed at least one bug that may solve your problem.

I was confused before, because they were always complaining that it crashed at "id = size", which actually isn't invaliad in foreach because some parts of the array are declared to be 1 cell bigger than you think they are for technical reasons.
I updated foreach and it's fixed now, thanks! Multi-Dimensional Arrays really helped the stability of my new server

I got another bug for you, the reason why I'm clearing the iterator is because Iter_Init isn't doing it.

Use this code

pawn Code:
#define MAX_PLAYERS 64
#define MAX_COMPLETE_SLOTS 26 //These are just my conditions, nothing specific.

new
    Iterator:pSlots_In_Use[MAX_PLAYERS]<MAX_COMPLETE_SLOTS>;

public OnGameModeInit()
{
    Iter_Init(pSlots_In_Use);
    return 1;
}

public OnPlayerConnect(playerid) // I use it in a timer, but this should work.
{
    foreach(pSlots_In_Use[playerid], mu_slot)
    {
        printf("mu_slot: %d", mu_slot);
    }
    return 1;
}

Result:

pawn Code:
[18:08:26] [debug] Run time error 4: "Array index out of bounds"
[18:08:26] [debug]   Accessing element at index 28 past array upper bound 25
[18:08:26] [debug] Backtrace:
[18:08:26] [debug] #0  00071edc in public MissileUpdate () at C:\DOCUME~1\MYDOCU~1\GRANDT~1\SA-MPS~2\GAMEMO~1\T_M.pwn:9209

This must be a bug, isn't Iter_Init surpose to clear the iterator?
__________________

  • Twisted Metal's Website & Forums are up! http://tm.lvcnr.net

    Are you prepared to get your wish? Twisted Metal SA-MP is coming soon! Join the IRC Channel: #tm on irc.tl - @tmsamp_dev

server.lvcnr.net:7777 | samp://server.lvcnr.net:7777
www.lvcnr.net | @kcnrdev
Channel: #lvcnr on irc.tl

Last edited by Kar; 18/06/2012 at 11:27 PM.
Kar is offline   Reply With Quote
Old 18/06/2012, 11:12 PM   #593
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 17,857
Reputation: 2478
Default Re: foreach - 0.3 compatible - updated 06/08/10

There's no MissileUpdate there...
Y_Less is offline   Reply With Quote
Old 18/06/2012, 11:18 PM   #594
Kar
High-roller
 
Join Date: May 2010
Location: Black Asylum
Posts: 2,876
Reputation: 280
Default Re: foreach - 0.3 compatible - updated 06/08/10

pawn Code:
forward MissileUpdate();
SetTimer("MissileUpdate", 80, true);

new mu_id,
    mu_objectid,
    mu_vehicleid;
    //mu_slot;
   
public MissileUpdate()
{
    foreach(Player, i)
    {
        if(PlayerInfo[i][pSpawned] == 0) continue;
        mu_id = GetPlayerVehicleID(i);
        //for(mu_slot = 0; mu_slot < MAX_COMPLETE_SLOTS; mu_slot++)
        foreach(pSlots_In_Use[i], mu_slot)//crashes here.. same thing basically
        {
            //printf("%s mu_slot: %d", Playername(i), mu_slot);
            mu_objectid = Vehicle_Missile[mu_id][mu_slot];
            //rest code
        }
    }
}

Not much of a difference?
__________________

  • Twisted Metal's Website & Forums are up! http://tm.lvcnr.net

    Are you prepared to get your wish? Twisted Metal SA-MP is coming soon! Join the IRC Channel: #tm on irc.tl - @tmsamp_dev

server.lvcnr.net:7777 | samp://server.lvcnr.net:7777
www.lvcnr.net | @kcnrdev
Channel: #lvcnr on irc.tl
Kar is offline   Reply With Quote
Old 19/06/2012, 06:59 AM   #595
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 17,857
Reputation: 2478
Default Re: foreach - 0.3 compatible - updated 06/08/10

Just made an updated version, try that.
Y_Less is offline   Reply With Quote
Old 20/06/2012, 04:15 AM   #596
cyber_punk
Gangsta
 
Join Date: Feb 2008
Location: Det. Mi. USA.....
Posts: 588
Reputation: 9
Default Re: foreach - 0.3 compatible - updated 06/08/10

Very nice the update fixed my issue. Thanks.
__________________
cyber_punk is offline   Reply With Quote
Old 20/06/2012, 10:44 AM   #597
Kar
High-roller
 
Join Date: May 2010
Location: Black Asylum
Posts: 2,876
Reputation: 280
Default Re: foreach - 0.3 compatible - updated 06/08/10

It's fixed now. Great job.
__________________

  • Twisted Metal's Website & Forums are up! http://tm.lvcnr.net

    Are you prepared to get your wish? Twisted Metal SA-MP is coming soon! Join the IRC Channel: #tm on irc.tl - @tmsamp_dev

server.lvcnr.net:7777 | samp://server.lvcnr.net:7777
www.lvcnr.net | @kcnrdev
Channel: #lvcnr on irc.tl
Kar is offline   Reply With Quote
Old 26/06/2012, 08:26 AM   #598
SDraw
Gangsta
 
SDraw's Avatar
 
Join Date: Apr 2011
Location: Russia
Posts: 664
Reputation: 147
Default Re: foreach - 0.3 compatible - updated 06/08/10

I have a question:
Can I use iterator in enum like
PHP Code:
enum paramS one,two,Iterator:This<128> };
new 
Info[128][paramS]; 
?
__________________
I leave SAMP. It's not perspective anymore.

Last edited by SDraw; 26/06/2012 at 02:39 PM.
SDraw is offline   Reply With Quote
Old 28/06/2012, 12:55 PM   #599
wups
High-roller
 
wups's Avatar
 
Join Date: Apr 2010
Location: Lithuania
Posts: 1,369
Reputation: 132
Default Re: foreach - 0.3 compatible - updated 06/08/10

Bug:

Quote:
[14:56:58] [debug] Run time error 4: "Array index out of bounds"
[14:56:58] [debug] Accessing element at index 501 past array upper bound 499
[14:56:58] [debug] AMX backtrace:
[14:56:58] [debug] #0 00374168 in public Check () at GameMode.pwn:32865
Code:
pawn Code:
new Busy[MAX_PLAYERS]; // max_players 500
    foreach (Player, playerid)
    {
        if(Busy[playerid]) // line 32865
        {

The callback is called once every second, but this appears only sometimes.
wups is offline   Reply With Quote
Old 28/06/2012, 01:11 PM   #600
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 17,857
Reputation: 2478
Default Re: foreach - 0.3 compatible - updated 06/08/10

I have never seen it hit something two above the max index (I fixed a one above bug). But without more information there's not much I can do.
Y_Less 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
Updated Foreach, but then i got a compiling problem. Zack_Burton Scripting Help 0 01/05/2012 05:39 PM
Mac Compatible? Zeeee Client Support 7 12/12/2011 08:40 PM
[>>>SSA<<<] SuperSimpleAdmin [0.3x COMPATIBLE!] [mad]MLK Filterscripts 10 10/12/2009 06:28 AM


All times are GMT. The time now is 06:54 AM.


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