Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-09-2009, 05:40 AM
thatdwarf thatdwarf is offline
Former UN Dev Admin
Join Date: Nov 2005
Posts: 42
thatdwarf is on a distinguished road
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!
Reply With Quote
  #2  
Old 02-09-2009, 05:09 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
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
__________________
Reply With Quote
  #3  
Old 02-09-2009, 05:43 PM
thatdwarf thatdwarf is offline
Former UN Dev Admin
Join Date: Nov 2005
Posts: 42
thatdwarf is on a distinguished road
aha, a great alternative, thanks Chompy

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

Last edited by thatdwarf; 02-09-2009 at 06:03 PM..
Reply With Quote
  #4  
Old 02-09-2009, 11:00 PM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
PHP Code:
this.spec_weps = { "-""*""_""etc"};
if ( 
temp.ban.substring01in this.spec_weps)
{
  
blah;

that should work.
__________________
Deep into the Darkness peering...
Reply With Quote
  #5  
Old 02-09-2009, 11:01 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by Angel_Light View Post
PHP Code:
this.spec_weps = { "-""*""_""etc"};
if ( 
temp.ban.substring01in this.spec_weps)
{
  
blah;

that should work.
Would only work for single characters though.
__________________
Reply With Quote
  #6  
Old 02-10-2009, 12:06 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
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.
Reply With Quote
  #7  
Old 02-10-2009, 04:33 AM
thatdwarf thatdwarf is offline
Former UN Dev Admin
Join Date: Nov 2005
Posts: 42
thatdwarf is on a distinguished road
Great! works perfectly. Thanks!
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 11:57 AM.


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