PDA

View Full Version : fun with .index(), or rather a distinct lack thereof


calani
03-14-2007, 07:00 PM
i've run into problems using .index() before, namely with weapon checking.
yet again, i ran into a similar problem doing the same thing. surprise, surprise.
anyway! this time i decided to investigate instead of just writing a hack to work around the problem.
here's the script followed by the output so you can puzzle over it, and hopefully offer an explination:


public function onTest_func(acct) {
this.temp_test0="";
this.temp_test1=0;
this.temp_test2=0;
this.temp_test3=0;
this.temp_test4="";
this.temp_test5=0;
this.temp_test6=0;
this.temp_test7=0;
with(findplayer(acct)) {
for(i: player.weapons) [email protected]="|"@i;
echo("element 74 is: "@player.weapons[73]);
if (player.weapons.index("+System")>=0) thiso.temp_test1=true;
if (player.weapons.index("+WeaponControl")>=0) thiso.temp_test2=true;
for (i: player.weapons) if (i=="+System") thiso.temp_test3=true;
for (i: player.weapons) [email protected]="|"@(player.weapons.index(i)>=0);
if (player.weapons.index(player.weapons[0])>=0) thiso.temp_test5=true;
thiso.temp_test6=("+System"==player.weapons[0]);
thiso.temp_test7=("+WeaponControl"==player.weapons[1]);

}
echo("----------------");
echo("Weapon list is: "@thiso.temp_test0);
echo("test for \"+System\" with .index() returns "@this.temp_test1);
echo("test for \"+WeaponControl\" with .index() returns "@this.temp_test2);
echo("test for \"+System\" with loop check returns "@this.temp_test3);
echo("loop .index test returns "@this.temp_test4);
echo("test for element [0] with .index() returns "@this.temp_test5);
echo("\"+System\"==player.weapons[0] returns "@this.temp_test6);
echo("\"+WeaponControl\"==player.weapons[1] returns "@this.temp_test7);
}


Element 73 is: $Frenzy
----------------
Weapon list is: |+System|+WeaponControl|+ArmorControl|+Class|+Craf ting|+CTF|+Events|+GUI|+Guild|+Inventory|+ItemCont rol|+PetControl|+Radio|+SpellControl|+Status|+Targ et|+Trade|+SkillMenu|+Shop|+Options|+Message|+Part y|+Macro|+Movement|+Nation|$Tailor|+JobsControl|+E nvironment|+Hacker|+ClassTrainer|+Map|+Misc|+Party Making|+ClassMasteryPoints|+CharacterSlots|+Ganis| +JChat|+Time|+Mail|+Swim|+Instrument|+Quest|+House System|+Event|+Icons|+IconShop|$Bash|+ShoutColors| +ChatColors|+GuildColors|$Enrage|$Sword Mastery|$Hard Strike|$Taunt|+Nationlog|$Magic Shot|$Minor Heal|$Iron Wall|$Exorcise|$Fist Mastery|+BloodLust|+DrawStar|$Farming|$Fireball|$M ug|$Dodge|$Stealth|$Feign Death|$Steal|$Chill|$Axe Mastery|$Rush|$Bash II|$Frenzy||$Acid Blast|$Agility|$Scamper|$Backstab|$Sand Swipe|$Payout|Gambet/BH System|$Cobra Fist|$Tough Skin|$Backstab II|$Scavenge|$Spy|$Earth Slam|$Tiger Claw|$Charge|$Throw Shuriken|$Irixyu|$Kemuri Beru|$Katana Mastery|$Seal of Incapacitation|$Tataki Koto|$Bolt|$Blight|$Blind|$Pick Lock|$Transfixion|$Throw Dagger|$Shadowbind|$Throw Pinwheel|$Viper Bite|$Finishing Blow|$Cloak of Shadows|$Frozen Lance|$Ice Coffin|$Wildfire|$Step|$Blast Wave|$Crush|$Explosion|$Grim Reaper|$Drain|$Siphon|$Seeking Missile|$Imbue: Fire|$Imbue: Earth|$Sprint|$Split Shot|$Imbue: Wind|$Battle Shriek|$Throat Stab|+gecko|$Ki Blast|$Recharge|$Blessing of Stamina|$Restore|$Dark Wave|$Sleep|$Absorb|$Shadowguard|$Shadow Swipe|$Nightmare|$Focus|$Discipline|$Pigeon Peck|$Chakra|$Entangle|$Pathfinding|$Eye of the Hawk|$Regenerate|$Dragon Fang|$War Cry|$Cleanse|$Heal|$Blessing of Strength|$Rebirth|$Blessing of Dexterity|$Energy Freeze|$Revitalize|$Revive|$Egress|$Scythe Mastery|$Mental Conditioning|$Smasher
test for "+System" with .index() returns 0
test for "+WeaponControl" with .index() returns 0
test for "+System" with loop check returns 1
loop .index test returns |1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1 |1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1 |1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|0 |1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1 |1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1 |1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1 |1|1|1|1|1|1|1|1
test for element [0] with .index() returns 1
"+System"==player.weapons[0] returns 1
"+WeaponControl"==player.weapons[1] returns 1


puzzle away.

edit: due to the php field's scrollbar, you may miss the 0 in the loop .index test at element 73
edit: also renamed the function to test_func since it gets *'d out without the _

Skyld
03-14-2007, 07:05 PM
I think it is probably misbehaving because player.weapons[] is actually an array of weapon objects:
echo(findPlayer("Skyld").weapons[0].objecttype());
... is giving "TServerNPC".

obj.index() tends to check for whatever you give it; if you give it a string and it finds TServerNPCs, then it is probably working just as expected by ignoring them.

calani
03-14-2007, 07:37 PM
That would make sense.
what about that odd 0 in the list, though? that has me quite confused.
Actually that one is element 74, I miscounted before.

Admins
03-24-2007, 03:58 PM
Might be a non-existing weapon (you can see it with RC in the weapon list of the player, but since the script doesn't exist it is a NULL object)