Runaway Script Help

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.
Post Reply
drath
New User
Posts: 7
Joined: Tue May 30, 2006 2:44 am

Runaway Script Help

Post by drath »

Hello, i've been using the following structure to do a lot of things including displaying my players kills in the following example.

Code: Select all

	foreach acctname in ListAccounts() 
		acct := FindAccount(acctname); 
		for i:=1 to 5 
			getcharname := acct.GetCharacter(i); 
			if(kills <= CInt(GetObjProperty(getcharname, "arenawins")))
				kills := CInt(GetObjProperty(getcharname, "arenawins"));
				charname := getcharname.name;
			endif
		endfor 
	endforeach 
But everytime I use one of these snippets in my code, I am getting runaway script errors. Here is the actual runaway error in the script.log that i get from this specific code:

Code: Select all

[06/03 18:48:40] Logfile opened.
[06/03 19:18:57] Runaway script[5586]: pkg/systems/saver/saver.ecl (20000 cycles)
 98: local #12
 99: Call Method getcharacter (1 params)
 100: local6 := 
 101: local #1
 102: local #6
>103: "frags"
 104: Func(3,10): GetObjProperty
 105: Func(0,0): CInt
 106: <=
 107: if false goto 116
 108: local #6
I was wondering what I am doing wrong?
Danielle
Grandmaster Poster
Posts: 104
Joined: Tue Feb 07, 2006 3:32 pm

Post by Danielle »

You must have a lot of accounts... anyway, just insert a sleepms() function within the loop, that'll reset the clock cycles. It should be the foreach loop causing the issues, since the for loop is only looping 5 times.

Code: Select all

   foreach acctname in ListAccounts() 
      acct := FindAccount(acctname); 
      for i:=1 to 5 
         getcharname := acct.GetCharacter(i); 
         if(kills <= CInt(GetObjProperty(getcharname, "arenawins"))) 
            kills := CInt(GetObjProperty(getcharname, "arenawins")); 
            charname := getcharname.name; 
         endif 
      endfor
      sleepms(1); // Sleep here to prevent runaway scripts!
   endforeach 
drath
New User
Posts: 7
Joined: Tue May 30, 2006 2:44 am

Post by drath »

Well there has to be another problem, because my threshold is at 20,000, and I know I don't have 20,000 accounts :P. But anyways, your suggestion did work for whatever reason. Thanks :).
Shinigami
Former Developer
Posts: 308
Joined: Mon Jan 30, 2006 9:28 am

Post by Shinigami »

first: it's a warning and not an error
second: nobody has said u have 20.000 accounts... but runned script cycles

Shinigami
User avatar
CWO
POL Expert
Posts: 1160
Joined: Sat Feb 04, 2006 5:49 pm

Post by CWO »

drath wrote:Well there has to be another problem, because my threshold is at 20,000, and I know I don't have 20,000 accounts :P. But anyways, your suggestion did work for whatever reason. Thanks :).
If you generate listings with ecompile (the .lst files) you'll find out theres a lot of instructions you're doing in your script. 1 line doesnt mean 1 instruction.
drath
New User
Posts: 7
Joined: Tue May 30, 2006 2:44 am

Post by drath »

Shinigami wrote:first: it's a warning and not an error
second: nobody has said u have 20.000 accounts... but runned script cycles

Shinigami
An annoying warning at that. Danielle mentioned I "must have a lot of accounts". I was just saying that I don't have up to the threshold in accounts.
CWO wrote:If you generate listings with ecompile (the .lst files) you'll find out theres a lot of instructions you're doing in your script. 1 line doesnt mean 1 instruction.
Hmm true.
Shinigami
Former Developer
Posts: 308
Joined: Mon Jan 30, 2006 9:28 am

Post by Shinigami »

drath wrote:An annoying warning at that.
not really... it should help u to trim your scripts to multi-threading... sleeps inside will switch cpu to other scripts waiting. if u just ignore such warnings than u should never ask here why u got lags ingame.

u can modify the 10.000 cycle limit via pol.cfg:

Code: Select all

#
# RunawayScriptThreshold: a script executing this many instructions without sleeping will be
#                         reported as a runaway script
#
RunawayScriptThreshold=10000
Shinigami
Lagoon
Grandmaster Poster
Posts: 118
Joined: Sun Mar 05, 2006 7:25 am

Post by Lagoon »

Danielle wrote:You must have a lot of accounts... anyway, just insert a sleepms() function within the loop, that'll reset the clock cycles. It should be the foreach loop causing the issues, since the for loop is only looping 5 times.
Well, your code is correct, but probably you should add a bit longer sleep. The point is that if you just want to get rid of the warning you have an easyer way to do that:
set_script_option(SCRIPTOPT_NO_RUNAWAY);
But as written in POL Performance Guide "increasing the runaway treshold is just ignoring the problem, not fixing it", so disabling runaway detection is even worse. So... what you really should do is add a sleepms() in the loop, but not the shortest the possible, but the smartest the possible. You shouldn't just care to "reset the clock cycles", but to have your core, as Shini sayd, be able to achieve a real constant multi-threading

Now, how to choose a smart value? Well, I haven't so much experience about this because I still have to test my script on a live shard and "tune" them properly, but basically for you critical scripts you should find the right alchemy of sleepms and script priority. I saw newest stadard distro often uses sleepms(2) in this kind of script, probably it's a good setting which should give the core the time to switch to other script. Maybe sleepms(1) is a bit too short?

And finally.. a question to Shini (or whoever knows the answer): when you say "runned script cycles" do you mean instructions executed by the core all at once? I should't take it as the number of loops of the foreach, should I?
User avatar
CWO
POL Expert
Posts: 1160
Joined: Sat Feb 04, 2006 5:49 pm

Post by CWO »

script cycles means actual instructions executed by the core, not how many times its looped.

and basically to go over what I said with "1 line doesnt mean 1 instruction" Heres a good example just from this post

Code: Select all

 99: Call Method getcharacter (1 params)
 100: local6 :=
 101: local #1
 102: local #6
>103: "frags"
 104: Func(3,10): GetObjProperty
 105: Func(0,0): CInt
 106: <=
 107: if false goto 116 
From what I can see here, this block of 9 instructions is from just these 2 lines:

Code: Select all

       getcharname := acct.GetCharacter(i);
        if(kills <= CInt(GetObjProperty(getcharname, "arenawins"))) 
Lagoon
Grandmaster Poster
Posts: 118
Joined: Sun Mar 05, 2006 7:25 am

Post by Lagoon »

Ok, thanx :)
Post Reply