Thursday, January 24, 2019

How to compare a value within an array

setarray .@abc[0], 1,2,6,8,9,11,21,34,55,61;
how to determine the value 6 is in the array ?

I'm sure most people will loop it
yeah ~ this is so basic ~

Now let me show you 3 other methods

 

Method No.1 -> use while loop




Method No.2 -> compare with strings




Method No.3 -> use array as pointers




And of course don't forget, rAthena's *countinarray

OK seriously this one is cheating


-------------------------------------------------------

Of course all 3 methods has its own weakness

Method no.1 - it run an extra index within the while-loop

this one will throw error


Method no.2 - when using *countstr, countstr("#1#1#1#", "#1#"); will return 2
means, "#1#1#1#" is for *compare script command,
"#1##1##1#" is for *countstr


Method no.3 cannot use string, like IP address
.@abc["127.0.0.1"]  <-- of course doesn't work

External Links:

Help removing duplicate value from array
How to make list ID for mobs (method No. 1)
Special Party Warper (method No.2)
Please help this script about mac-address (method No.2)
getitemname2 function (method No.3)
party soul link (method No.3)

No comments:

Post a Comment

Linux compiler error that never shown on Visual Studio

let's just admit Visual Studio sux ... ok ? right now, if you want to host a Private Ragnarok Online server, its just better to choose...