Page 1 of 1

Struct arrays

Posted: Thu Jun 29, 2017 7:22 am
by Ememjr
what are the consequences if i set the array length to lets say 5

Code: Select all

packet->setSubstructArrayLengthByName("header_info", "stat_count", 5);
and then set the array data as seen below for

Code: Select all

packet->setArrayDataByName("stat_type", stat->stat_type, 0);
packet->setArrayDataByName("stat_subtype", tmp_subtype, 0);
packet->setArrayDataByName("stat_type", stat->stat_type, 1);
packet->setArrayDataByName("stat_subtype", tmp_subtype, 1);
packet->setArrayDataByName("stat_type", stat->stat_type, 2);
packet->setArrayDataByName("stat_subtype", tmp_subtype, 2);
packet->setArrayDataByName("stat_type", stat->stat_type, 3);
packet->setArrayDataByName("stat_subtype", tmp_subtype, 3);
and then go back and change the array length back to 4

Code: Select all

packet->setSubstructArrayLengthByName("header_info", "stat_count", 4);
does it wipe the 0 to 3 data i already put in or does it just change the array count
I would only be making the array smaller not larger if this is possible

the reasoning behind this is if you have an item with potency on it in the stat list and there are 5 stats, the 5 is the array size
but if you are using DOV client or another client that the stat is not in, i dont want that stat in the array and would skip adding it to the packet, but then would need to change the array size

i could work around this by reading all the stats for that item and placing them in a temp array, then reading that temp array to determine what stat number to send to the client based on the client version but that seems like double work

Re: Struct arrays

Posted: Thu Jun 29, 2017 9:17 am
by John Adams
If it were me, I'd probably just write code that checks for minimum client version, and branch to do it 2 different ways.

Code: Select all

if (version = DOV) { // do 4 elements } else { // do 5 elements }
but then, this is why I am a DB guy, not a C++ guy :)

Re: Struct arrays

Posted: Thu Jun 29, 2017 10:00 am
by Ememjr
doubt that would work beacuse there could be more than one element that doesnt apply, since dbg seems to change stats alot

Re: Struct arrays

Posted: Thu Jun 29, 2017 12:36 pm
by Zcoretri
I would think the only thing that would happen is when your array size is at 5, that 5th elements data will be sent to the client with value 0.
Hopefully Jabantiz can explain it better.