PDA

View Full Version : Enum & Dynamic array


KissLick
10-08-2014, 12:48
Ciao guys,

I'd like to use dynamic array of enums, I got this code, but I also have a lot of error and I am not sure why...


enum Enum_Fence {
m_iIndex,
Float:m_fPosA[3],
Float:m_fPosC[3]
}
new Handle:g_hFences;

/*
.
.
.
*/

g_hFences = CreateArray(_:Enum_Fence);
new eFence[Enum_Fence];

if (KvGotoFirstSubKey(hKeyValues)) {
do {
if ((eFence[m_iIndex] = KvGetNum(hKeyValues, "index", -1)) == -1) {
LogError("Reading Error in %s. (Invalid index)", sPath);
return;
}

KvGetVector(hKeyValues, "PositionA", eFence[m_fPosA]); // error 047: array sizes do not match, or destination array is too small
KvGetVector(hKeyValues, "PositionC", eFence[m_fPosC]); // error 047: array sizes do not match, or destination array is too small

new iIndex = PushArrayArray(g_hFences, eFence); // warning 229: index tag mismatch (symbol "eFence")
CreateFence(eFence[m_fPosA], eFence[m_fPosC], iIndex); // error 047: array sizes do not match, or destination array is too small

} while (KvGotoNextKey(hKeyValues));
}
Can someone help me please?

EDIT: CreateFence header
CreateFence(Float:a[3], Float:c[3], iIndex)

Dr. Greg House
10-08-2014, 13:25
These vector calls don't work with the enum hack afaik. You need to copy those values over manually.
The warning is just another bug you can circumvent by "myArray[0]".

KissLick
10-08-2014, 13:45
Thx! :-)

friagram
10-09-2014, 06:17
You could make a linked list, just make lots of datapacks and store your enums in there

KissLick
10-09-2014, 07:05
I got new warning! O:-) Can anyone help me please?


new iFencesCount = GetArraySize(g_hFences);
new iIndex;
new Float:fPosA[3], Float:fPosC[3];
new eFence[Enum_Fence];

for (new i = 0; i < iFencesCount; i++) {
GetArrayArray(g_hFences, i, eFence[0]);

iIndex = eFence[m_iIndex];
fPosA = eFence[m_fPosA]; // warning 229: index tag mismatch (symbol "eFence")
fPosC = eFence[m_fPosC]; // warning 229: index tag mismatch (symbol "eFence")

CreateFence(fPosA, fPosC, iIndex);
}
You could make a linked list, just make lots of datapacks and store your enums in there
Already had that idea :-D -> https://forums.alliedmods.net/showthread.php?t=232675

Mitchell
10-09-2014, 10:00
Kind of like what Dr Grag said you cant do it in that kind of way. you have to set each value individually.

fPosA[0] = eFence[m_fPosA][0];
fPosA[1] = eFence[m_fPosA][1];
fPosA[2] = eFence[m_fPosA][2];
etc...

KissLick
10-09-2014, 10:02
Kind of like what Dr Grag said you cant do it in that kind of way. you have to set each value individually.

fPosA[0] = eFence[m_fPosA][0];
fPosA[1] = eFence[m_fPosA][1];
fPosA[2] = eFence[m_fPosA][2];
etc...

Oh nooooo..... :'-( that's what I was afraid of...

friagram
10-09-2014, 19:43
I got new warning! O:-) Can anyone help me please?


new iFencesCount = GetArraySize(g_hFences);
new iIndex;
new Float:fPosA[3], Float:fPosC[3];
new eFence[Enum_Fence];

for (new i = 0; i < iFencesCount; i++) {
GetArrayArray(g_hFences, i, eFence[0]);

iIndex = eFence[m_iIndex];
fPosA = eFence[m_fPosA]; // warning 229: index tag mismatch (symbol "eFence")
fPosC = eFence[m_fPosC]; // warning 229: index tag mismatch (symbol "eFence")

CreateFence(fPosA, fPosC, iIndex);
}

Already had that idea :-D -> https://forums.alliedmods.net/showthread.php?t=232675

And as you can see, i said it was a bad idea.
Linked lists are pretty bad in pawn. But then again, enums of mixed types are also really bad. Imo the only point of an enum here is to type check your vars.

Dr. Greg House
10-09-2014, 20:28
[...]bad[...]

Definition please.

friagram
10-10-2014, 02:35
Definition please.

https://www.google.com/#safe=off&q=define:bad

Dr. Greg House
10-10-2014, 07:28
Thanks. Seems to be an adjective, so its subjective in nature if used by itself without proper explanation.

friagram
10-10-2014, 07:58
VtBtiAR2tI4