• 0
utofaery

N>advice and help on comparing array loop

Question

First off don't get mad to link from rathena:

https://rathena.org/board/topic/118192-on-checking-array-items-infinite-loop/

 

This is the test case I try to redo the thing but it's gotten into loop again and again.

Don't get mad at me for not understanding this stuff.  I always ask things till I get it.

Spoiler


function    script    F_testarraycompare    {
        setarray ( [email protected][getarraysize([email protected])]    ,
19500, 19501, 19502, 19503, 19504, 19505, 19506, 19507, 19508, 19509, 19510, 19511, 19512, 19513, 19514, 
19515, 19516, 19517, 19518, 19519, 19520, 19521, 19522, 19523, 19524, 19525, 19526, 19527, 19528, 19529, 
19530, 19531, 19532, 19533, 19534, 19535, 19536, 19537, 19538, 19539, 19540, 19541, 19542, 19543, 19544, 
19545, 19546, 19547, 19548, 19549, 19550, 19551, 19552, 19553, 19554, 19555, 19556, 19557, 19558, 19559, 
19560, 19561, 19562, 19563, 19564, 19565, 19566, 19567, 19568, 19569, 19570, 19571, 19572, 19573, 19574, 
19575, 19576, 19577, 19578, 19579, 19580, 19581, 19582, 19583, 19584, 19585, 19586, 19587, 19588, 19589, 
19590, 19591, 19592, 19593, 19594, 19595, 19596, 19597, 19598, 19599, 19600, 19601, 19602, 19603, 19604, 
19605, 19606, 19607, 19608, 19609, 19610, 19611, 19612, 19613, 19614, 19615, 19616, 19617, 19618, 19619, 
19620, 19621, 19622, 19623, 19624, 19625, 19627, 19628, 19629, 19630, 19631, 19632, 19633, 19634, 19635, 
19636, 19637, 19638, 19639, 19640, 19641, 19642, 19643, 19644, 19645, 19646, 19647, 19648, 19649, 19650, 
19651, 19652, 19653, 19654, 19655, 19656, 19657, 19658, 19659, 19660, 19661, 19662, 19663, 19664, 19665, 
19666, 19667, 19668, 19669, 19670, 19671, 19672, 19673, 19674, 19675, 19676, 19677, 19678, 19679, 19680, 
19681, 19682, 19683, 19684, 19685, 19686, 19687, 19688, 19689, 19690, 19691, 19692, 19693, 19694, 19695, 
19696, 19697, 19698, 19699, 19700, 19701, 19702, 19703, 19704, 19705, 19706, 19707, 19708, 19709, 19710, 
19711, 19712, 19713, 19714, 19715, 19716, 19717, 19718, 19719, 19720, 19721, 19722, 19723, 19724, 19725, 
19726, 19727, 19728, 19729, 19730, 19731, 19732, 19733, 19734, 19735, 19736, 19737, 19738, 19739, 19741, 
19740, 19742, 19743, 19744, 19745, 19746, 19747, 19748, 19749, 19750, 19751, 19752, 19753, 19754, 19755, 
19756, 19757, 19758, 19759, 19760, 19761, 19762, 19763, 19764, 19765, 19767, 19766, 19768, 19769, 19770, 
19771, 19772, 19773, 19774, 19775, 19776, 19777, 19778, 19779, 19780, 19781, 19782, 19783, 19784, 19785, 
19786, 19787, 19788, 19789, 19790, 19791, 19792, 19793, 19794, 19795, 19796, 19797, 19798, 19799, 19800, 
19801, 19802, 19803, 19804, 19805, 19806, 19807, 19808, 19809, 19810, 19811, 19812, 19813, 19814, 19815, 
19816, 19817, 19818, 19819, 19820, 19821, 19822, 19823, 19824, 19825, 19826, 19827, 19828, 19829, 19830, 
19831, 19832, 19833, 19834, 19835, 19836, 19837, 19838, 19839, 19840, 19841, 19842, 19843, 19844, 19845, 
19846, 19847, 19848, 19849, 19850, 19851, 19852, 19853, 19854, 19855, 19856, 19857, 19858, 19859, 19860, 
19861, 19862, 19863, 19864, 19865, 19866, 19867, 19868, 19869, 19870, 19871, 19872, 19873, 19874, 19875, 
19876, 19877, 19878, 19879, 19880, 19881, 19882, 19883, 19884, 19885, 19886, 19887, 19888, 19889, 19890, 
19891, 19892, 19893, 19894, 19895, 19896, 19897, 19898, 19899, 19900, 19901, 19902, 19903, 19904, 19905, 
19906, 19907, 19908, 19909, 19910, 19911, 19912, 19913, 19914, 19915, 19916, 19917, 19918, 19919, 19920, 
19921, 19922, 19923, 19924, 19925, 19926, 19927, 19928, 19929, 19930, 19931, 19932, 19934, 19935, 19936, 
19937, 19938, 19939, 19940, 19941, 19942, 19943, 19944, 19945, 19946, 19947, 19949, 19950, 19951, 19952, 
19953, 19954, 19955, 19956, 19957, 19958, 19959, 19960, 19961, 19962, 19963, 19964, 19965, 19966, 19967, 
19968, 19969, 19970, 19971, 19972, 19973, 19974, 19975, 19976, 19977, 19978, 19979, 19980, 19981, 19982, 
19983, 19984, 19985, 19986, 19987, 19988, 19989, 19990, 19991, 19992, 19993, 19994, 19996, 19997, 19998, 
19999, 20000, 20001, 20002, 20003, 20004, 20005, 20006, 20007, 20008, 20009, 20010, 20011, 20012, 20013, 
20014, 20015, 20016, 20017, 20018, 20019, 20020, 20021, 20022, 20023, 20024, 20025, 20026, 20027, 20028, 
20029, 20030, 20031, 20032, 20033, 20034, 20035, 20036, 20037, 20038, 20039, 20040, 20041, 20042, 20043, 
20044, 20045, 20046, 20047, 20048, 20049, 20050, 20051, 20052, 20053, 20054, 20055, 20056, 20057, 20058, 
20059, 20060, 20061, 20062, 20063, 20064, 20065, 20066, 20067, 20068, 20069, 20070, 20071, 20073, 20074, 
20075, 20076, 20077, 20078, 20079, 20080, 20081, 20082, 20083, 20084, 20085, 20086, 20087, 20088, 20089, 
20090, 20091, 20092, 20093, 20094, 20095, 20096, 20097, 20098, 20099, 20100, 20101, 20102, 20103, 20104, 
20105, 20106, 20107, 20108, 20109, 20110, 20111, 20112, 20113, 20114, 20115, 20116, 20117, 20118, 20119, 
20120, 20121, 20122, 20123, 20124, 20125, 20126, 20127, 20128, 20129, 20130, 20131, 20132, 20133, 20134, 
20135, 20136, 20137, 20138, 20139, 20140, 20141, 20142, 20143, 20144, 20145, 20146, 20147, 20148, 20149, 
20150, 20151, 20152, 20153, 20154, 20155, 20156, 20157, 20158, 20159, 20160, 20161, 20162, 20163, 20164, 
20165, 20166, 20167, 20168, 20169, 20170, 20171, 20172, 20173, 20174, 20175, 20176, 20177, 20178, 20179, 
20180, 20181, 20182, 20183, 20184, 20185, 20186, 20187, 20188, 20189, 20190, 20191, 20192, 20193, 20194, 
20195, 20196, 20197, 20198, 20199, 20200, 20201, 20202, 20203, 20204, 20205, 20206, 20207, 20208, 20209, 
20210, 20211, 20212, 20213, 20214, 20215, 20216, 20217, 20218, 20219, 20220, 20221, 20222, 20223, 20224, 
20225, 20226, 20227, 20228, 20229, 20230, 20231, 20232, 20233, 20234, 20235, 20236, 20237, 20238, 20239, 
20240, 20241, 20242, 20243, 20244, 20245, 20246, 20247, 20248, 20249, 20250, 20251, 20252, 20253, 20254, 
20255, 20256, 20257, 20258, 20259, 20260, 20262, 20263, 20264, 20265, 20266, 20267, 20268, 20269, 20270, 
20271, 20272, 20273, 20274, 20277, 20278, 20279, 20280, 20281, 20282, 20283, 20284, 20285, 20286, 20287, 
20288, 20291, 20292, 20293, 20294, 20295, 20296, 20297, 20298, 20299, 20300, 20301, 20302, 20303, 20304, 
20307, 20311, 20312, 20313, 20314, 20315, 20316, 20317, 20318, 20319, 20320, 20321, 20322, 20323, 20324, 
20325, 20326, 20327, 20328, 20329, 20330, 20331, 20332, 20333, 20334, 20335, 20338, 20339, 20340, 20341, 
20342, 20345, 20346, 20347, 20348, 20349, 20350, 20351, 20352, 20353, 20354, 20355, 20356, 20357, 20358, 
20359, 20360, 20361, 20362, 20363, 20364, 20365, 20366, 20367, 20368, 20369, 20370, 20371, 20372, 20373, 
20374, 20375, 20376, 20377, 20378, 20379, 20380, 20381, 20382, 20383, 20384, 20386, 20392, 20393, 20394, 
20396, 20397, 20398, 20399, 20400, 20401, 20402, 20403, 20404, 20405, 20406, 20407, 20408, 20409, 20416, 
20417, 20418, 20419, 20420, 20421, 20422, 20423, 20424, 20425, 20426, 20427, 20428, 20429, 20430, 20431, 
20432, 20433, 20434, 20435, 20436, 20437, 20438, 20439, 20440, 20441, 20442, 20446, 20447, 20448, 20449, 
20450, 20451, 20452, 20455, 20456, 20458, 20457, 20459, 20460, 20461, 20462, 20463, 20464, 20465, 20466, 
20467, 20468, 20470, 20476, 20481, 20482, 20483, 20484, 20485, 20486, 20487, 20488, 20489, 20490, 20491, 
20492, 20495, 20496, 20497, 20498, 20499, 20500, 20502, 20504, 20506, 20507, 20508, 20509, 20510, 20511, 
20512, 20514, 20515, 20516, 20517, 20530, 20533 ) ;

    disable_items;
    getinventorylist;
    for ( [email protected] = 0; [email protected] < getarraysize(@inventorylist_count); [email protected] ) {
        for ( [email protected] = 0; [email protected] < getarraysize([email protected]); [email protected] ) {
                if ( @inventorylist_id[[email protected]] == [email protected][[email protected]] ) {
                    dispbottom ( " Found item :: " + @inventory_id[[email protected]] ) ;
                    [email protected]++;
                }
                [email protected]++;
        }
    }
    dispbottom ( " [email protected] :: " + [email protected]  ) ;
    dispbottom ( " [email protected] :: " + [email protected]  ) ;
    dispbottom ( " [email protected] :: " + [email protected]  ) ;
    dispbottom ( " [email protected] :: " + [email protected]  ) ;
    return;
}

 

Share this post


Link to post
Share on other sites

9 answers to this question

  • 0

similar topic ->

and since you want method 3

prontera,155,185,5	script	kjsdhfksjf	1_F_MARIA,{
	disable_items;
	getinventorylist;
	for ( .@i = 0; .@i < @inventorylist_count; ++.@i ) {
		if ( .costumeid[ @inventorylist_id[.@i] ] && !.@compare[ @inventorylist_id[.@i] ] ) {
			.@found[.@c++] = @inventorylist_id[.@i];
			.@compare[ @inventorylist_id[.@i] ] = true;
		}
	}
	if ( !.@c ) {
		mes "no costume found on your character";
		close;
	}
	mesf "%d custome found on your character", .@c;
	for ( .@i = 0; .@i < .@c; ++.@i )
		mes getitemname( .@found[.@i] );
	close;
OnInit:
//	SQL query to fetch all the costumes
	.@nb = query_sql( "select id from item_db where equip_locations & "+( EQP_COSTUME_HEAD_TOP|EQP_COSTUME_HEAD_MID|EQP_COSTUME_HEAD_LOW|EQP_COSTUME_GARMENT ), .@id );
//	build the 'pointers' to compare later
	freeloop true;
	for ( .@i = 0; .@i < .@nb; ++.@i )
		.costumeid[ .@id[.@i] ] = true;
	end;
}

EDIT: no longer repeat the costume value

Edited by AnnieRuru

Share this post


Link to post
Share on other sites
  • 0
20 hours ago, AnnieRuru said:

EDIT: no longer repeat the costume value

Why and how does it repeat the costume at the first place ?

was it because there is not enough limitation or conditions check that causing the loop then?

and the loop can loop more than once??

because in some cases I have seen

[email protected] got bigger than [email protected] in some test
for ( .@i = 0; .@i < .@c; ++.@i )

 

side note:

for the code box thing could changes be made so that it only run Codebox script after posting?

so it load faster when trying to posting (aka before post is made)

then after the post is made only then it load it's code?

 

20 hours ago, AnnieRuru said:

similar topic ->

and since you want method 3

prontera,155,185,5	script	kjsdhfksjf	1_F_MARIA,{
	disable_items;
	getinventorylist;
	for ( .@i = 0; .@i < @inventorylist_count; ++.@i ) {
		if ( .costumeid[ @inventorylist_id[.@i] ] && !.@compare[ @inventorylist_id[.@i] ] ) {
			.@found[.@c++] = @inventorylist_id[.@i];
			.@compare[ @inventorylist_id[.@i] ] = true;
		}
	}
	if ( !.@c ) {
		mes "no costume found on your character";
		close;
	}
	mesf "%d custome found on your character", .@c;
	for ( .@i = 0; .@i < .@c; ++.@i )
		mes getitemname( .@found[.@i] );
	close;
OnInit:
//	SQL query to fetch all the costumes
	.@nb = query_sql( "select id from item_db where equip_locations & "+( EQP_COSTUME_HEAD_TOP|EQP_COSTUME_HEAD_MID|EQP_COSTUME_HEAD_LOW|EQP_COSTUME_GARMENT ), .@id );
//	build the 'pointers' to compare later
	freeloop true;
	for ( .@i = 0; .@i < .@nb; ++.@i )
		.costumeid[ .@id[.@i] ] = true;
	end;
}

 

1. How to add exclusion on this script like another array which exclude items from being found?

Share this post


Link to post
Share on other sites
  • 0
23 hours ago, utofaery said:

1. How to add exclusion on this script like another array which exclude items from being found?

prontera,155,185,5	script	kjsdhfksjf	1_F_MARIA,{
	disable_items;
	getinventorylist;
	for ( .@i = 0; .@i < @inventorylist_count; ++.@i ) {
		.@item_type = getiteminfo( @inventorylist_id[.@i], ITEMINFO_TYPE );
		if ( ( .@item_type == IT_WEAPON || .@item_type == IT_ARMOR ) && !@inventorylist_equip[.@i] && !.costumeid[ @inventorylist_id[.@i] ] )
			.@id[.@c++] = @inventorylist_id[.@i];
	}
	mes "Equipments found that are not costumes";
	if ( !.@c ) {
		mes "<none>";
		close;
	}
	mesf "Total -> %d", .@c;
	for ( .@i = 0; .@i < .@c; ++.@i )
		mes getitemname( .@id[.@i] );
	close;
OnInit:
//	SQL query to fetch all the costumes
	.@nb = query_sql( "select id from item_db where equip_locations & "+( EQP_COSTUME_HEAD_TOP|EQP_COSTUME_HEAD_MID|EQP_COSTUME_HEAD_LOW|EQP_COSTUME_GARMENT ), .@id );
//	build the 'pointers' to compare later
	freeloop true;
	for ( .@i = 0; .@i < .@nb; ++.@i )
		.costumeid[ .@id[.@i] ] = true;
	end;
}

 

Share this post


Link to post
Share on other sites
  • 0
13 hours ago, AnnieRuru said:
prontera,155,185,5	script	kjsdhfksjf	1_F_MARIA,{
	disable_items;
	getinventorylist;
	for ( .@i = 0; .@i < @inventorylist_count; ++.@i ) {
		.@item_type = getiteminfo( @inventorylist_id[.@i], ITEMINFO_TYPE );
		if ( ( .@item_type == IT_WEAPON || .@item_type == IT_ARMOR ) && !@inventorylist_equip[.@i] && !.costumeid[ @inventorylist_id[.@i] ] )
			.@id[.@c++] = @inventorylist_id[.@i];
	}
	mes "Equipments found that are not costumes";
	if ( !.@c ) {
		mes "<none>";
		close;
	}
	mesf "Total -> %d", .@c;
	for ( .@i = 0; .@i < .@c; ++.@i )
		mes getitemname( .@id[.@i] );
	close;
OnInit:
//	SQL query to fetch all the costumes
	.@nb = query_sql( "select id from item_db where equip_locations & "+( EQP_COSTUME_HEAD_TOP|EQP_COSTUME_HEAD_MID|EQP_COSTUME_HEAD_LOW|EQP_COSTUME_GARMENT ), .@id );
//	build the 'pointers' to compare later
	freeloop true;
	for ( .@i = 0; .@i < .@nb; ++.@i )
		.costumeid[ .@id[.@i] ] = true;
	end;
}

 

I really fix up a lot of other script I have by comparing your script with whatever is in my script folder...

 

On 2/11/2019 at 3:51 PM, utofaery said:

1. How to add exclusion on this script like another array which exclude items from being found?

I guess it's my bad for not explaining this correctly..

on .nb part where it query_sql to fetch all the costumes, can I have another array to 

[email protected] which include a list of item which not to be compared or "found"?  from the big list of query_sql?

Edited by utofaery

Share this post


Link to post
Share on other sites
  • 0

1 sentence ->

I cannot understand your post

Spoiler

looks like spam, but I am turning this topic to other members who can understand him

 

 

btw if you are talking about having a long list of array, isn't that already in your 1st post
yeah, can't understand you, despite we live in the same country

catch me in discord
https://discordapp.com/invite/ZUzbRSp

Share this post


Link to post
Share on other sites
  • 0
[email protected] = query_sql( "select id from item_db where equip_locations & "+( EQP_COSTUME_HEAD_TOP|EQP_COSTUME_HEAD_MID|EQP_COSTUME_HEAD_LOW|EQP_COSTUME_GARMENT ), [email protected] );

Say after collected this list EQP_COSTUME_HEAD_TOP|EQP_COSTUME_HEAD_MID|EQP_COSTUME_HEAD_LOW|EQP_COSTUME_GARMENT 

I want to put extra check which exclude some of the item from being listed in the 

[email protected][[email protected]++] = @inventorylist_id[[email protected]];

like putting in an extra check so it doesn't get included in the [email protected][[email protected]++]??

 

mes getitemname( [email protected][[email protected]] );

then in this part it won't list the excluded "certain item"?

Edited by Dastgir
Edited colors so it is readable

Share this post


Link to post
Share on other sites
  • 0
15 hours ago, utofaery said:
.@nb = query_sql( "select id from item_db where equip_locations & "+( EQP_COSTUME_HEAD_TOP|EQP_COSTUME_HEAD_MID|EQP_COSTUME_HEAD_LOW|EQP_COSTUME_GARMENT ), .@id );

Say after collected this list EQP_COSTUME_HEAD_TOP|EQP_COSTUME_HEAD_MID|EQP_COSTUME_HEAD_LOW|EQP_COSTUME_GARMENT 

I want to put extra check which exclude some of the item from being listed in the 

.@id[.@c++] = @inventorylist_id[.@i];

like putting in an extra check so it doesn't get included in the .@id[[email protected]++]??

 

mes getitemname( .@id[.@i] );

then in this part it won't list the excluded "certain item"?

Please don't use light colors, it is extremely difficult to read on this theme of forum.

Share this post


Link to post
Share on other sites
  • 0
8 hours ago, Dastgir said:

Please don't use light colors, it is extremely difficult to read on this theme of forum.

I dont really know how to change that, all I do is copy paste from previous post then go on typing then it became colourful...

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now