Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   For Loop Only Going to 68 (https://forums.graalonline.com/forums/showthread.php?t=134268465)

baseman101 07-13-2013 11:44 PM

For Loop Only Going to 68
 
Hello,

I've made a script which checks a log on a UC server. The problem is that it only loops 68 times through the file, and stays at 68. I find this really unhelpful. Here's the script I have.

PHP Code:

function onCreated() {
    
temp.str.loadstring("logs/testlog.txt");
    echo(
searchString(temp.str"Testing123"));
}

function 
searchString(temp.stringtemp.search) {
  for (
this.0this.temp.string.length(); this.x++) {
    if(
temp.string.substring(this.x,temp.search.length()) == temp.search) {
      echo(
"Found string!");
      return 
temp.string.substring(this.100temp.search.length() + 100);
      break;
    }
  }


Thanks in advance! Also, is there a more efficient way of writing this? Say, with a log that has over 10,000 characters (the NPC Server stops the script after 10000 loops).

fowlplay4 07-14-2013 12:06 AM

Don't use this.x for starters, that's a reserved variable for NPCs. Use pos or positions instead.

PHP Code:

function onCreated() {
  
temp.str.loadstring("logs/testlog.txt");
  
temp.spos temp.str.pos("Testing123");
  if (
temp.spos >= 0) {
    echo(
"found string");
    echo(
temp.str.substring(temp.spos 100temp.spos 100));
  }
  for (
temp.spostemp.str.positions("Testing123")) {
    echo(
temp.str.substring(temp.spos 100temp.spos 100));
  }



baseman101 07-14-2013 01:37 AM

Quote:

Originally Posted by fowlplay4 (Post 1720597)
Don't use this.x for starters, that's a reserved variable for NPCs. Use pos or positions instead.

PHP Code:

function onCreated() {
  
temp.str.loadstring("logs/testlog.txt");
  
temp.spos temp.str.pos("Testing123");
  if (
temp.spos >= 0) {
    echo(
"found string");
    echo(
temp.str.substring(temp.spos 100temp.spos 100));
  }
  for (
temp.spostemp.str.positions("Testing123")) {
    echo(
temp.str.substring(temp.spos 100temp.spos 100));
  }



Ah, (facepalm), thanks!


All times are GMT +2. The time now is 12:50 AM.

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