YSI: Iterator and Foreach (Array size does not match!)
#1

First, the top of my script:
pawn Code:
#undef MAX_OBJECTS
#define MAX_OBJECTS 2500

new Iterator:Object<MAX_OBJECTS>;

stock _ALT_CreateDynamicObject(modelid,Float:x,Float:y,Float:z,Float:rx,Float:ry,Float:rz,worldid=-1,interiorid=-1,playerid=-1,Float:streamdistance=200.0,Float:drawdistance=0.0)
{
    new objectid = CreateDynamicObject(modelid,x,y,z,rx,ry,rz,worldid,interiorid,playerid,streamdistance,drawdistance);
    if(IsValidDynamicObject(objectid)) Iter_Add(Object, objectid);
    return objectid;
}

#if defined _ALS_CreateDynamicObject
    #undef CreateDynamicObject
#else
    #define _ALS_CreateDynamicObject
#endif
#define CreateDynamicObject _ALT_CreateDynamicObject

stock _ALT_DestroyDynamicObject(objectid)
{
    if(IsValidDynamicObject(objectid)) Iter_Remove(Object, objectid);
    return DestroyDynamicObject(objectid);
}

#if defined _ALS_DestroyDynamicObject
    #undef DestroyDynamicObject
#else
    #define _ALS_DestroyDynamicObject
#endif
#define DestroyDynamicObject _ALT_DestroyDynamicObject
I'm pretty sure this is all working fine. I get the following error on the Iter_Init line.
Quote:
Originally Posted by pawn.cc
(636) : error 048: array dimensions do not match
The following stuff is in OnGameModeInit.
pawn Code:
/*[635]*/Streamer_SetMaxItems(STREAMER_TYPE_OBJECT, MAX_OBJECTS);
/*[636]*/Iter_Init(Object);
What is the problem with that Iterator?

Ps, using YSI 3.1
Reply
#2

You don't need Iter_Init in this situation... remove it.

Iter_Init is used for multi dimensional arrays, you aren't using a multi dimensional array. Your array has 1 dimension.



Why are you even doing this?

Streamer_SetMaxItems(STREAMER_TYPE_OBJECT, MAX_OBJECTS);

--

Default maximum items: none (unlimited)
Default visible items: 500 (objects);

500 can't be increased due to sa-mp limit if your trying to do that

You really only want 2500 objects in your script?
Reply
#3

Quote:
Originally Posted by Kar
View Post
Why are you even doing this?

Streamer_SetMaxItems(STREAMER_TYPE_OBJECT, MAX_OBJECTS);
Yes it does that automatically, but I needed it to make my loop smaller, it's no harm.

Redefining MAX_OBJECTS does no harm either since I'm using streamer.

@Y_Less: Yes I read it, and the script was not working without the init, so I tried it. Before I used it I had this loop:
pawn Code:
foreach(Object, obj)
{
    printf("%d", obj);
}
That only printed this:
Quote:

1
2501
2
2501

Please note that I've created over 1200 objects, so these id's are not the only objects; and yes, they are created after I hooked the functions. Also, the objects did exist IG so they were for sure created.
Reply
#4

Maybe try using Iter_Free?
Reply
#5

Maybe:

pawn Code:
new index = Iter_Free(Object);
if(index > -1)
{
    Iter_Add(Object, objectid);
}
Reply
#6

Doesn't the iterator include do that automatically..?
Reply
#7

Quote:
Originally Posted by Y_Less
View Post
That's not valid syntax any more.
Oh... Umm, how do I do it then?
Reply
#8

Oh, I thought that was the old syntax. Or was the comma syntax just for players?

EDIT: Same results.
Reply
#9

Wow, interesting. I always used the 'new' syntax until about exactly one year ago, because somebody told me the new comma syntax was the correct syntax. I've been fooled and feel really dumb right now... :P

But anyways I fixed it. The problem was in the destroy hook, I had to make an extra SafeDestroyDynamicObject. It completes the Iter_SafeRemove.

EDIT: Just realized I never mentioned I was using the Destroy function in the loops, oops... :P
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)