Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Nested for() functions duplicating output (https://forums.graalonline.com/forums/showthread.php?t=84095)

thatdwarf 02-09-2009 05:40 AM

Nested for() functions duplicating output
 
Alright, the problem I am having is with a GUI control, I want to add a filtered list of the player's weapons.

The below code doesnt filter the desired content (and yes, there is an array defined already called this.bannedNPCs)

flip the for() loops around, and it filters nothing, but duplicates the output a couple times

for example: -wep, -wep, -wep, -wep, -anotherwep, and so on
PHP Code:

function LAucItem.onSelect(idtxtind) {
  
L_List.clearrows();
  if(
txt == "NPC") {
    for(
temp.weps this.bannedNPCs) {
      for(
temp.0temp.player.weapons.size(); temp.i++) {
        if(!
player.weapons[temp.i].name.starts(temp.weps))
          
L_List.addrow(temp.iplayer.weapons[temp.i].name);
      }
    }
  }


Any ideas on how to fix this?

Thanks!

Chompy 02-09-2009 05:09 PM

Hmm, I don't like the loop your doing.. hmm

PHP Code:

temp.0;
for(
temp.wep player.weapons) {
  if (
temp.wep.name in this.bannedNPCs) continue;

  
L_List.addrow(temp.i++, temp.wep.name);


Or something like that

thatdwarf 02-09-2009 05:43 PM

aha, a great alternative, thanks Chompy :D

Now how would I alter that code to accomodate prefixes?
Instead of having to go through and type in every weapon that isnt allowed (and there are a lot of them), just typing
in a prefix, say *, or -, and filtering out all weapons who's names begin with that prefix

I've tried:
a loop through the array, and then doing temp.wep.name.starts(temp.ban), no avail
using a substring(0, #).trim(), no avail

Angel_Light 02-09-2009 11:00 PM

PHP Code:

this.spec_weps = { "-""*""_""etc"};
if ( 
temp.ban.substring01in this.spec_weps)
{
  
blah;


that should work.

Chompy 02-09-2009 11:01 PM

Quote:

Originally Posted by Angel_Light (Post 1464744)
PHP Code:

this.spec_weps = { "-""*""_""etc"};
if ( 
temp.ban.substring01in this.spec_weps)
{
  
blah;


that should work.

Would only work for single characters though.

WhiteDragon 02-10-2009 12:06 AM

PHP Code:

function LAucItem.onSelect(idtxtind) {
  
L_List.clearrows();
  if (
txt == "NPC") {
    for (
temp.0temp.player.weapons.size(); temp.i++) {

      
temp.notBanned true;

      for (
temp.weps this.bannedNPCs) {
        if (
player.weapons[temp.i].name.starts(temp.weps)) {
          
temp.notBanned false;
          break;
        }
      }

      if (
temp.notBanned)
        
L_List.addrow(temp.iplayer.weapons[temp.i].name);

    }
  }


Should work, and do what you were trying to do in the first function.

thatdwarf 02-10-2009 04:33 AM

Great! works perfectly. Thanks!


All times are GMT +2. The time now is 06:59 PM.

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