Please tell me whats wrong.

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.

Moderator: POL Developer

Post Reply
User avatar
andenixa
Grandmaster Poster
Posts: 105
Joined: Tue Nov 09, 2010 1:33 am

Please tell me whats wrong.

Post by andenixa »

Got a simple snippet:

Code: Select all

var d := dictionary;
    
for i := 1 to 3
    d[i] := "test";
endfor

print(d);
Output: dict{ 4 -> "test" }

PS: core099
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Re: Please tell me whats wrong.

Post by Austin »

Good question... I did some tests with Runecl.exe and produced the following:

Code: Select all

use os;

program TestScript()
	var d := dictionary;
   
	for i := 1 to 3
		d[i] := "test";
		Print("i="+i+"   Val="+d[i]);
	endfor

	print(d);
	
	return 1;
endprogram

-------------------
i=1   Val=test
i=2   Val=test
i=3   Val=test
dict{ 4 -> "test" }

Code: Select all

use os;

program TestScript()
	var d := dictionary;
   
	for i := 1 to 4
		d[Hex(i)] := "test";
		Print("i="+i+"   Val="+d[Hex(i)]);
	endfor

	print(d);
	
	return 1;
endprogram

-------------------

i=1   Val=test
i=2   Val=test
i=3   Val=test
i=4   Val=test
dict{ "0x1" -> "test", "0x2" -> "test", "0x3" -> "test", "0x4" -> "test" }

Code: Select all

use os;

program TestScript()
	var d := dictionary;

	for i:=1 to 4
		d[CStr(i)] := "test";
		Print("i="+i+"   Val="+d[CStr(i)]);
	endfor

	print(d);

	return 1;
endprogram
-----------------------
i=1   Val=test
i=2   Val=test
i=3   Val=test
i=4   Val=test
dict{ "1" -> "test", "2" -> "test", "3" -> "test", "4" -> "test" }

Code: Select all

use os;

program TestScript()
	var d := dictionary;

	var i;
	for ( i := 1; i <= 4; i += 1 )
		d[i] := "test";
		Print("i="+i+"   Val="+d[i]);
	endfor

	print(d);

	return 1;
endprogram
----------------
i=1   Val=test
i=2   Val=test
i=3   Val=test
i=4   Val=test
dict{ 1 -> "test", 2 -> "test", 3 -> "test", 4 -> "test" }
User avatar
andenixa
Grandmaster Poster
Posts: 105
Joined: Tue Nov 09, 2010 1:33 am

Re: Please tell me whats wrong.

Post by andenixa »

Thanks a lot Austin.
It seems that a for shortcut ain't reliable. Thats too bad because I used it so frequently...
The other glitch I found is looping from "uninit" would create an infinite loop ending with a crash.

like:

Code: Select all

    var t;

    for i := t to 4       
        // pass
    endfor   
Post Reply