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-03-2012, 12:27 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Bug: The max loop limit can no longer be avoided serverside with a sleep.

In the past, this code would not have hit the max loop limit because of the sleep.

PHP Code:
function onCreated() {
  for (
temp.0temp.100000temp.++) {
    echo(
temp.i);
    
    if ((
temp.1) % this.maxlooplimit == 0) {
      echo(
"sleeping");
      
sleep(10);
    }
  }

Now, the loop limit is hit on the next iteration after the sleep, regardless of the length of the sleep; the result is the same with a 0.1 second sleep and a 10 second one.

Quote:
Originally Posted by RC Output
9996
9997
9998
9999
sleeping
Script: Loop limit exceeded at line 2 in script of TempLoopTest
This bug exists on at least Era Dev, Era, and Kingdoms Debug.
__________________
Reply With Quote
  #2  
Old 02-03-2012, 12:45 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
I encountered this problem on Classic too.
Reply With Quote
  #3  
Old 02-06-2012, 03:56 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
I've never received a max loop error. Is that anything similar to how php breaks when it takes to long to execute a script? and times out?

or what exactly causes this problem? 1000 loops?
Reply With Quote
  #4  
Old 02-06-2012, 04:19 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by scriptless View Post
I've never received a max loop error. Is that anything similar to how php breaks when it takes to long to execute a script? and times out?

or what exactly causes this problem? 1000 loops?
10,000 by default. I don't know exactly how it works, Stefan's said it's more complicated than just loop counters, but basically a loop exceeding 10,000 iterations is halted and the entire script stops.
__________________
Reply With Quote
  #5  
Old 03-27-2012, 02:02 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Bump, also seems to happen clientside.
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #6  
Old 03-27-2012, 07:42 PM
Devil_Lord2 Devil_Lord2 is offline
David K?
Devil_Lord2's Avatar
Join Date: Apr 2011
Location: PA, MD.
Posts: 643
Devil_Lord2 can only hope to improve
Is this of the same problem?

I added more for loops because it use to be only this.tempStaff, and 20 strings in the array..

Then the original code only had this one else if for loop checking through the staff. :/

It would then say there was an error in the RC but the level editor still worked.. I didn't really know how to fix the problem but to split the work out into different else ifs...

It still doesn't work all that well but does work.
Sadly, I think the RC will state a lot of errors, but the people will not know...


Is there a way to fix this, or is it the same error as everyone else?
I tried to fix it, but I thought the problem was going through all the arrays..
It just says reached a loop limit at 0, 0.

Original (20 people / levels)
PHP Code:
this.tempStaff  = { //This will be deleted after the contest.
    
"Graal774127","lat-01.nw""Graal781370","lat-02.nw""Graal779529","lat-03.nw""acc","lat-04.nw""acc","lat-05.nw",
  }; 



else if (
player.account in this.tempStaff){
        for (
i=0this.tempStaff.size(); i++){
          if  (
player.account == this.tempStaff[i] && player.level == this.tempStaff[i+1]){
            for (
temp.i=0temp.params[1].size(); temp.++){
              
player.level.tiles[(temp.i%params[2])+params[3],int(temp.i/params[2])+params[4]] = params[1][temp.i];
              
player.level.updateboard2(params[3],params[4],params[2],params[1].size()/params[2]);
            }
          }
        }  
      } 




Code now.
PHP Code:
  this.tempStaff  = { //This will be deleted after the contest.
    
"Graal774127","lat-01.nw""Graal781370","lat-02.nw""Graal779529","lat-03.nw""acc","lat-04.nw""acc","lat-05.nw",
  };    
  
this.tempStaff2  = { //This will be deleted after the contest.
    
"acc","lat-06.nw""acc","lat-07.nw""acc","lat-08.nw""acc","lat-09.nw""acc","lat-10.nw",  
  };
  
this.tempStaff3  = {
    
"acc","lat-11.nw""acc","lat-12.nw""acc","lat-13.nw""acc","lat-14.nw""acc","lat-15.nw",
  };
  
this.tempStaff4  = {  
    
"acc","lat-16.nw""acc","lat-17.nw""acc","lat-18.nw""acc","lat-19.nw""acc","lat-20.nw"
  };                  
// Can only edit certain levels 
  
  
  
switch (action) {
    case 
"SaveLevel":
      if (
player.account in this.regStaff || player.account in this.trialStaff) {
        for (
temp.i=0temp.params[1].size(); temp.++)
          
player.level.tiles[(temp.i%params[2])+params[3],int(temp.i/params[2])+params[4]] = params[1][temp.i];
          
player.level.updateboard2(params[3],params[4],params[2],params[1].size()/params[2]);
      } 
      
      
      
//Deleting this after the contest
      
else if (player.account in this.tempStaff){
        for (
i=0this.tempStaff.size(); i++){
          if  (
player.account == this.tempStaff[i] && player.level == this.tempStaff[i+1]){
            for (
temp.i=0temp.params[1].size(); temp.++){
              
player.level.tiles[(temp.i%params[2])+params[3],int(temp.i/params[2])+params[4]] = params[1][temp.i];
              
player.level.updateboard2(params[3],params[4],params[2],params[1].size()/params[2]);
            }
          }
        }  
      }
      else if (
player.account in this.tempStaff2){
        for (
i=0this.tempStaff.size(); i++){
          if  (
player.account == this.tempStaff2[i] && player.level == this.tempStaff2[i+1]){
            for (
temp.i=0temp.params[1].size(); temp.++){
              
player.level.tiles[(temp.i%params[2])+params[3],int(temp.i/params[2])+params[4]] = params[1][temp.i];
              
player.level.updateboard2(params[3],params[4],params[2],params[1].size()/params[2]);
            }
          }
        }  
      }
      else if (
player.account in this.tempStaff3){
        for (
i=0this.tempStaff.size(); i++){
          if  (
player.account == this.tempStaff3[i] && player.level == this.tempStaff3[i+1]){
            for (
temp.i=0temp.params[1].size(); temp.++){
              
player.level.tiles[(temp.i%params[2])+params[3],int(temp.i/params[2])+params[4]] = params[1][temp.i];
              
player.level.updateboard2(params[3],params[4],params[2],params[1].size()/params[2]);
            }
          }
        }  
      }
      else if (
player.account in this.tempStaff4){
        for (
i=0this.tempStaff.size(); i++){
          if  (
player.account == this.tempStaff4[i] && player.level == this.tempStaff4[i+1]){
            for (
temp.i=0temp.params[1].size(); temp.++){
              
player.level.tiles[(temp.i%params[2])+params[3],int(temp.i/params[2])+params[4]] = params[1][temp.i];
              
player.level.updateboard2(params[3],params[4],params[2],params[1].size()/params[2]);
            }
          }
        }  
      } 
__________________

Digital Media Artist - David K? </3 (UnLoved)
www.davidkrout.com
www.twitch.com/DavidKkz



Reply With Quote
  #7  
Old 03-27-2012, 07:54 PM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
Quote:
Originally Posted by Devil_Lord2 View Post
Is this of the same problem?
No, it's because you're attempting to use the same 'i' variable within loops contained within loops, which basically resets the first loop back to 0 and repeats infinitely until the engine cancels it.

The rest of the code is also terribly inefficient, can be accomplished by much easier means, and it doesn't really make sense that you're defining this. variables as if they're a temp. variable while using a prefix in the name. Those arrays should be set one time onCreated.
Reply With Quote
  #8  
Old 03-27-2012, 10:34 PM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Oh boy

PHP Code:
function onCreated() {
  
this.trigger("YourTerribleCodeFixed"0this.maxlooplimit*2);
}

function 
onYourTerribleCodeFixed(starttotal) {
  
temp.sub min(totalthis.maxlooplimit);
  for (
temp.0temp.temp.subtemp.i++) {
    echo(
start temp.i);
  }
  
total -= temp.sub;
  if (
total 0) {
    
this.scheduleevent(1"YourTerribleCodeFixed",
                       
start temp.subtotal);
  }

e: You could also forgo the scheduleevent, but triggers have their own per-frame limit (10 or so).
e2: but at least if you do it will fail silently!
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #9  
Old 03-29-2012, 03:31 PM
Devil_Lord2 Devil_Lord2 is offline
David K?
Devil_Lord2's Avatar
Join Date: Apr 2011
Location: PA, MD.
Posts: 643
Devil_Lord2 can only hope to improve
Quote:
Originally Posted by ffcmike View Post
No, it's because you're attempting to use the same 'i' variable within loops contained within loops, which basically resets the first loop back to 0 and repeats infinitely until the engine cancels it.

The rest of the code is also terribly inefficient, can be accomplished by much easier means, and it doesn't really make sense that you're defining this. variables as if they're a temp. variable while using a prefix in the name. Those arrays should be set one time onCreated.
Ahh, didn't see the same 'i' being used, I'll have to add temp later.
My much easier means that I thought of was doing the .index() but I didn't know how. ^.^; didn't feel like bothering you so I did it with a for loop.

Also, they are temp since most of the staff will be deleted after the LAT contest. o.O; I put temp for my own purposes.


I believe this was all I had to do. ^.^;;
I don't know why I used 'i' twice. Late at night I do stupid things.
Added temp. as well, not sure why I left that out either.
PHP Code:
      else if (player.account in this.tempStaff){
        for (
temp.a=0this.tempStaff.size(); a++){
          if  (
player.account == this.tempStaff[a] && player.level == this.tempStaff[a+1]){
            for (
temp.i=0params[1].size(); i++){ 
Thank you all, lets see if it works on the fourth. o.O;;
I guess my problem was stupidity and drowsiness.

-EDIT-

However, my friend is trying to create a baddy using a specific algorithm and he is having problems with maxing out the loop only if he doesn't add a sleep .05 in..

I believe he wants something like an onTimeout calling an onTimeout right after the end of checking... Perhaps that is the same problem? I don't know. I doubt he will post on the forums though..
__________________

Digital Media Artist - David K? </3 (UnLoved)
www.davidkrout.com
www.twitch.com/DavidKkz




Last edited by Devil_Lord2; 03-29-2012 at 04:07 PM..
Reply With Quote
  #10  
Old 03-29-2012, 06:48 PM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
Quote:
Originally Posted by Devil_Lord2 View Post
PHP Code:
      else if (player.account in this.tempStaff){
        for (
temp.a=0this.tempStaff.size(); a++){
          if  (
player.account == this.tempStaff[a] && player.level == this.tempStaff[a+1]){
            for (
temp.i=0params[1].size(); i++){ 
Do you realise you have 2 conditions which are exactly the same?
If you were to remove the first line of player.account in this.tempStaff, it would still work.

player.level is an object rather than a string, the correct value to check is 'player.level.name'.

It's a bad practise to loop through non-changing arrays and use .size(); for every cycle, as the function will occur every time rather than once, this can generate a lot of overhead with very large arrays. The array size can be defined as a temporary variable beforehand, which can then be used in the loop condition.

Quote:
Originally Posted by Devil_Lord2 View Post
However, my friend is trying to create a baddy using a specific algorithm and he is having problems with maxing out the loop only if he doesn't add a sleep .05 in..

I believe he wants something like an onTimeout calling an onTimeout right after the end of checking... Perhaps that is the same problem? I don't know. I doubt he will post on the forums though..
onTimeout(); occuring within function onTimeout(){} without any specification for it would run infinitely until cancelled by the engine/NPC-Server.
Reply With Quote
  #11  
Old 03-29-2012, 11:23 PM
Devil_Lord2 Devil_Lord2 is offline
David K?
Devil_Lord2's Avatar
Join Date: Apr 2011
Location: PA, MD.
Posts: 643
Devil_Lord2 can only hope to improve
Quote:
Originally Posted by ffcmike View Post
Do you realise you have 2 conditions which are exactly the same?
If you were to remove the first line of player.account in this.tempStaff, it would still work.
Yes, I did that so if the first part didn't check, it wouldn't have to do the for loop, I assumed it would speed up what ever else it is doing if the first part was not correct.

The second part is only to add +1 to whatever the i is for the level, which I believe I could do with .index() but don't know how...


Quote:
Originally Posted by ffcmike View Post
player.level is an object rather than a string, the correct value to check is 'player.level.name'.
I have been told this many times, and I still don't quite understand it since the results are always the same. :[

Quote:
Originally Posted by ffcmike View Post
It's a bad practise to loop through non-changing arrays and use .size(); for every cycle, as the function will occur every time rather than once, this can generate a lot of overhead with very large arrays. The array size can be defined as a temporary variable beforehand, which can then be used in the loop condition.
for instance temp.num = something.size(); and stick that in the loop?
I shall do that!

Quote:
Originally Posted by ffcmike View Post
onTimeout(); occuring within function onTimeout(){} without any specification for it would run infinitely until cancelled by the engine/NPC-Server.
I'll ask you later, he says it does not work but I don't know what he had done. All I know is he had many loops inside of his and said it kept maxing out or something...

He is not on for me to ask. :[

-Correction-
He gave it to me to see, but I don't know if I have the right to expose it. :X
So I must ask.
__________________

Digital Media Artist - David K? </3 (UnLoved)
www.davidkrout.com
www.twitch.com/DavidKkz



Reply With Quote
  #12  
Old 03-30-2012, 01:16 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Devil_Lord2 View Post
I have been told this many times, and I still don't quite understand it since the results are always the same. :[
I feel like I've explained this before to you. Objects are typically coerced into strings (using their name property) when you abuse them like strings. It's better to compare the strings yourself for clarity.
__________________
Reply With Quote
  #13  
Old 03-31-2012, 05:38 PM
Devil_Lord2 Devil_Lord2 is offline
David K?
Devil_Lord2's Avatar
Join Date: Apr 2011
Location: PA, MD.
Posts: 643
Devil_Lord2 can only hope to improve
Quote:
Originally Posted by cbk1994 View Post
I feel like I've explained this before to you. Objects are typically coerced into strings (using their name property) when you abuse them like strings. It's better to compare the strings yourself for clarity.
You probably have and I still don't get it..
They just equal the same things in testing, unless I see an error of some kind giving physical evidence why it shouldn't be used I'll probably never fully understand. D:



ZeroG's algorithm I'll explain but won't show. It checks every tile within 32x32 of a level spreading out from the NPC. It finds the nearest path to the player, and comes back to it self in the check. After that it moves once...

This process repeats over and over and over until it moves towards the player.

It uses MANY for loops in the timeout, however, at the end it seems to NOT work if you do not have a sleep(.05); and having that makes it seriously slow...

Yet this algorythm works fine on another game that he is making in Simple. He doesn't want me to post it because he doesn't believe anyone else has tried it, nor does he believe anyone can fix it.

Is Graal not fast enough to do these type of things?

He uses V5 and it slowly comes to him, I use V6 and it seems to do the loop about 3 times before stopping.. if it finds me and I'm close to it then it will move to me once or twice... if I'm about 6 tiles away the finding part of the gets to me and stops... if I'm farther it stops in the same spot too..

If this cannot be helped without images or code than it is fine.
__________________

Digital Media Artist - David K? </3 (UnLoved)
www.davidkrout.com
www.twitch.com/DavidKkz



Reply With Quote
  #14  
Old 03-31-2012, 05:57 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
Quote:
Originally Posted by Devil_Lord2 View Post
You probably have and I still don't get it..
They just equal the same things in testing, unless I see an error of some kind giving physical evidence why it shouldn't be used I'll probably never fully understand. D:
PHP Code:
function onCreated()
{
  
temp.obj = new TStaticVar("SomeObject");
  
  
temp.one = new SomeObject();
  
temp.two = new SomeObject();
  
  
temp.one.asdf "hi";
  
temp.two.asdf "foo";
  
  echo(
format("Object one is '%s'"temp.one));
  echo(
format("Object two is '%s'"temp.two));
  echo(
format("Object keys: '%s', '%s'"temp.one.asdftemp.two.asdf));
  
  
// Compare the objects as objects
  
if (temp.one == temp.two)
    echo(
"Objects are the same");
  else
    echo(
"Objects are different");
  
  
// Compare the objects after being coerced to strings
  
if (@temp.one == @temp.two)
    echo(
"Object names are equal");
  else
    echo(
"Object names are different");  

Output:
NPC Code:
Object one is 'SomeObject'
Object two is 'SomeObject'
Object keys: 'hi', 'foo'
Objects are different
Object names are equal


When the objects are coerced into strings, you get the object names only typically. In this example, it results in two objects appearing to be the same (because their object names are the same) even though we have just proven them to be different.

This is something you MUST be aware of when coercing objects into strings in GScript. It doesn't always work how you expect.
__________________
Skyld
Reply With Quote
  #15  
Old 03-31-2012, 06:47 PM
Devil_Lord2 Devil_Lord2 is offline
David K?
Devil_Lord2's Avatar
Join Date: Apr 2011
Location: PA, MD.
Posts: 643
Devil_Lord2 can only hope to improve
Quote:
Originally Posted by Skyld View Post
PHP Code:
function onCreated()
{
  
temp.obj = new TStaticVar("SomeObject");
  
  
temp.one = new SomeObject();
  
temp.two = new SomeObject();
  
  
temp.one.asdf "hi";
  
temp.two.asdf "foo";
  
  echo(
format("Object one is '%s'"temp.one));
  echo(
format("Object two is '%s'"temp.two));
  echo(
format("Object keys: '%s', '%s'"temp.one.asdftemp.two.asdf));
  
  
// Compare the objects as objects
  
if (temp.one == temp.two)
    echo(
"Objects are the same");
  else
    echo(
"Objects are different");
  
  
// Compare the objects after being coerced to strings
  
if (@temp.one == @temp.two)
    echo(
"Object names are equal");
  else
    echo(
"Object names are different");  

Output:
NPC Code:
Object one is 'SomeObject'
Object two is 'SomeObject'
Object keys: 'hi', 'foo'
Objects are different
Object names are equal


When the objects are coerced into strings, you get the object names only typically. In this example, it results in two objects appearing to be the same (because their object names are the same) even though we have just proven them to be different.

This is something you MUST be aware of when coercing objects into strings in GScript. It doesn't always work how you expect.
Sorry, I know you are trying to help, but I'm confused as to what any of that means..

Can you do it in layman's terms and possibly actually use levels?
Also, why are levels objects and not only strings?
I thought levels were only names of a textfiles converted to .nw..
__________________

Digital Media Artist - David K? </3 (UnLoved)
www.davidkrout.com
www.twitch.com/DavidKkz



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 04:07 PM.


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