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 07-13-2013, 11:44 PM
baseman101 baseman101 is offline
Scripter
baseman101's Avatar
Join Date: Nov 2012
Location: Purcellville, VA
Posts: 76
baseman101 will become famous soon enough
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).
Reply With Quote
  #2  
Old 07-14-2013, 12:06 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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));
  }

__________________
Quote:
Reply With Quote
  #3  
Old 07-14-2013, 01:37 AM
baseman101 baseman101 is offline
Scripter
baseman101's Avatar
Join Date: Nov 2012
Location: Purcellville, VA
Posts: 76
baseman101 will become famous soon enough
Quote:
Originally Posted by fowlplay4 View Post
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!
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 10:18 AM.


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