Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-14-2007, 07:00 PM
calani calani is offline
Scriptess
calani's Avatar
Join Date: Aug 2003
Location: asmgarden.gmap
Posts: 606
calani is on a distinguished road
Send a message via AIM to calani
Post fun with .index(), or rather a distinct lack thereof

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:

PHP Code:
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(
iplayer.weaponsthiso.temp_test0@="|"@i;
    echo(
"element 74 is: "@player.weapons[73]);
    if (
player.weapons.index("+System")>=0thiso.temp_test1=true;
    if (
player.weapons.index("+WeaponControl")>=0thiso.temp_test2=true;
    for (
iplayer.weapons) if (i=="+System"thiso.temp_test3=true;
    for (
iplayer.weaponsthis.temp_test4@="|"@(player.weapons.index(i)>=0);
    if (
player.weapons.index(player.weapons[0])>=0thiso.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);

PHP Code:
Element 73 is$Frenzy
----------------
Weapon list is: |+System|+WeaponControl|+ArmorControl|+Class|+Crafting|+CTF|+Events|+GUI|+Guild|+Inventory|+ItemControl|+PetControl|+Radio|+SpellControl|+Status|+Target|+Trade|+SkillMenu|+Shop|+Options|+Message|+Party|+Macro|+Movement|+Nation|$Tailor|+JobsControl|+Environment|+Hacker|+ClassTrainer|+Map|+Misc|+PartyMaking|+ClassMasteryPoints|+CharacterSlots|+Ganis|+JChat|+Time|+Mail|+Swim|+Instrument|+Quest|+HouseSystem|+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|$Mug|$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|$ImbueFire|$ImbueEarth|$Sprint|$Split Shot|$ImbueWind|$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 [0with .index() returns 1
"+System"==player.weapons[0returns 1
"+WeaponControl"==player.weapons[1returns 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 _
__________________
Reply With Quote
  #2  
Old 03-14-2007, 07:05 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
I think it is probably misbehaving because player.weapons[] is actually an array of weapon objects:
PHP Code:
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.
__________________
Skyld
Reply With Quote
  #3  
Old 03-14-2007, 07:37 PM
calani calani is offline
Scriptess
calani's Avatar
Join Date: Aug 2003
Location: asmgarden.gmap
Posts: 606
calani is on a distinguished road
Send a message via AIM to calani
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.
__________________
Reply With Quote
  #4  
Old 03-24-2007, 03:58 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
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)
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 07:46 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.