[Windows] Forward-slashes in require() still don't work

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

Post Reply
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

[Windows] Forward-slashes in require() still don't work

Post by Zutty »

Hi all,

The situation is as follows... I'm using Windows (Vista x64), and my AI has several files organised into folders. When my AI is running straight from a directory then everything works fine, but when I run it from a TAR file I get errors relating to the require statement, which causes classes not to be loaded.

I KNOW I should have tested this ages ago after TrueBrain first fixed it for me, but I just assumed it would work and went back to working as normal. Well now I've come to test the tar for v2 of PathZilla and I get the error again.

I notice that TrueBrain's fix technically worked, i.e. that the platform-agnostic forward slashes in the actual code are converted to backslashes for Windows to understand. However there seems to be another problem. Here is the error that I get...

Code: Select all

dbg: [ai] [1] [S] Your script made an error: the index 'pathzilla' does not exist
dbg: [ai] [1] [S]
dbg: [ai] [1] [S] *FUNCTION [main()] %aitar%pathzilla\struct\BinaryHeap.nut line [146]
dbg: [ai] [1] [S] *FUNCTION [require()] NATIVE line [-1]
dbg: [ai] [1] [S] *FUNCTION [constructor()] %aitar%pathzilla\main.nut line [72]
dbg: [ai] [1] [S]
dbg: [ai] [1] [S] [this] TABLE
dbg: [ai] [1] [S] [this] INSTANCE
dbg: [misc] [squirrel] Failed to compile '%aitar%pathzilla\struct\BinaryHeap.nut'
dbg: [ai] [1] [S] Your script made an error: the index 'pathzilla' does not exist
dbg: [ai] [1] [S]
dbg: [ai] [1] [S] *FUNCTION [constructor()] %aitar%pathzilla\main.nut line [72]
dbg: [ai] [1] [S]
dbg: [ai] [1] [S] [this] INSTANCE
dbg: [ai] [1] [I] Starting PathZilla.... RAWR!
dbg: [ai] [1] [I]   My home town is Dadingtown
dbg: [ai] [1] [S] Your script made an error: the index 'SortedSet' does not exist
dbg: [ai] [1] [S]
dbg: [ai] [1] [S] *FUNCTION [constructor()] %aitar%pathzilla\graph\Graph.nut line [36]
dbg: [ai] [1] [S] *FUNCTION [constructor()] %aitar%pathzilla\graph\impl\Triangulation.nut line [47]
dbg: [ai] [1] [S] *FUNCTION [InitialiseGraphs()] %aitar%pathzilla\main.nut line[172]
dbg: [ai] [1] [S] *FUNCTION [Start()] %aitar%pathzilla\main.nut line [106]
dbg: [ai] [1] [S]
dbg: [ai] [1] [S] [this] INSTANCE
dbg: [ai] [1] [S] [targetList] INSTANCE
dbg: [ai] [1] [S] [this] INSTANCE
dbg: [ai] [1] [S] [allTowns] INSTANCE
dbg: [ai] [1] [S] [this] INSTANCE
dbg: [ai] [1] [S] [i] 2
dbg: [ai] [1] [S] [this] INSTANCE
dbg: [ai] We've got a suicidal AI for player 1
Any ideas? I know you must all be busy working on NAIL right now, but this issue means that Windows users won't be able to use my AI (at least, I think so - maybe its just Vista x64 troglodytes like me!!).

Thanks.
PathZilla - A networking AI - Now with tram support.
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: [Windows] Forward-slashes in require() still don't work

Post by TrueBrain »

Code: Select all

dbg: [ai] [1] [S] Your script made an error: the index 'pathzilla' does not exist
I don't think it has anything to do with forward slashes of any kind .. sounds more like your script contains an error in the form of: using 'pathzilla' where it isn't defined. Same for 'SortedSet' .. might be worth checking out :)

(Make sure you packed all the latest files in your tar ..)
The only thing necessary for the triumph of evil is for good men to do nothing.
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: [Windows] Forward-slashes in require() still don't work

Post by Zutty »

Thanks for the quick reply TrueBrain :)

I'm pretty sure this isn't an error in the code. As I said works perfectly fine when I run the AI from a folder rather than a TAR file, and all the files are definitely there.

Line 146 of BinaryHeap.nut is the last line in the file with just a single "}", and the identifier pathzilla isn't used once in the file (outside of the comments). Line 72 in main.nut is the line that require()s BinaryHeap.nut.

However now that I look at this with a fresh pair of eyes (it was nearly 2am when I started this thread!), something stands out. Both the files that cause errors are in the same folder... the 'struct' folder.

Is 'struct' a reserved word? It isn't in Squirrel, but it imagine it is in C++. Could this be something to do with the way files are loaded from a TAR file? If it was failing for all files then it would be Edge.nut that would throw an error. However the trace clearly shows it entering Triangulation.nut, so SOME require()s must be working properly.

Still though... the fact that the previous version of PathZilla also had this folder, but that it worked in the tournament suggests that this is a quirk specific to Windows, or maybe even to my machine (or at least, the combination of libraries etc.. on my machine).

Assuming that is a bug, I imagine it will be difficult to reproduce if you don't have a Windows machine! I think it'll be easier all round if I just change the folder names in my AI (I'll do it when I get home tonight). If I can verify that this is indeed the cause, I'll put a note in the Wiki.
PathZilla - A networking AI - Now with tram support.
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: [Windows] Forward-slashes in require() still don't work

Post by TrueBrain »

I truly doubt it has anything to do with require .. as such 'problems' can not be caused by the way a slash is placed, and so the problem should exist on every target. Nevertheless, without some real code, it would only be speculating. So please attach your AI here, so we can take a look at it.
The only thing necessary for the triumph of evil is for good men to do nothing.
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: [Windows] Forward-slashes in require() still don't work

Post by Zutty »

Thanks for looking at this :) dbkblk gets the same error so this is definitely linked to my AI, though I'm still not convinced that its entirely my fault!! ;)

Here's the offending TAR...
pathzilla.tar
PathZilla v2
(174.5 KiB) Downloaded 65 times
If it'll save you a little time you can also see it online...

http://code.google.com/p/ottd-noai-path ... /PathZilla
PathZilla - A networking AI - Now with tram support.
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: [Windows] Forward-slashes in require() still don't work

Post by TrueBrain »

Okay, first of all, it has NOTHING to do with require, neither with slashes. Broken processes of the past don't guarantee the same result in the future :) So don't think that too fast, because you have a problem, it is directly related to your last ;)

Nevertheless, the problem is related to tar-loading, and in a very funny way: struct/BinaryHeap.nut doesn't have a new-line at the end of the file, which results in that the tar-loader seems to skip the character. This clearly is a trunk bug, so I will report it, and see if we can figure out what goes wrong exactly :)

So the solution is simple: hit enter at the end of struct/BinaryHeap.nut, and it works just fine.
The only thing necessary for the triumph of evil is for good men to do nothing.
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: [Windows] Forward-slashes in require() still don't work

Post by Zutty »

TrueBrain wrote:Okay, first of all, it has NOTHING to do with require, neither with slashes. Broken processes of the past don't guarantee the same result in the future :) So don't think that too fast, because you have a problem, it is directly related to your last ;)
Sorry, yeah. The error looked very similar to the one I got with the slashes problem, so I assumed the issues were related.
Nevertheless, the problem is related to tar-loading, and in a very funny way: struct/BinaryHeap.nut doesn't have a new-line at the end of the file, which results in that the tar-loader seems to skip the character. This clearly is a trunk bug, so I will report it, and see if we can figure out what goes wrong exactly :)

So the solution is simple: hit enter at the end of struct/BinaryHeap.nut, and it works just fine.
Aha! How odd.

I have updated my TAR file with a couple of newlines. Hopefully dbkblk will get time to test it once more.

Thanks very much TrueBrain :D
PathZilla - A networking AI - Now with tram support.
User avatar
glx
OpenTTD Developer
OpenTTD Developer
Posts: 622
Joined: 02 Dec 2005 15:43
Location: Drancy(93) - France
Contact:

Re: [Windows] Forward-slashes in require() still don't work

Post by glx »

More infos about this (funny) bug :)

The problem is that some of your files have a size being a mutliple of 512 bytes. So squirrel can't detect the end of file as they fit in a block and there are no padding \0. It just continue to read and find "pathzilla/somedir/somefile\0", which is perfectly valid at compile time. You can call that bad luck ;)

BTW, it's now fixed in noai r14067.
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: [Windows] Forward-slashes in require() still don't work

Post by Zutty »

glx wrote:More infos about this (funny) bug :)

The problem is that some of your files have a size being a mutliple of 512 bytes. So squirrel can't detect the end of file as they fit in a block and there are no padding \0. It just continue to read and find "pathzilla/somedir/somefile\0", which is perfectly valid at compile time. You can call that bad luck ;)

BTW, it's now fixed in noai r14067.
Wow that IS unlucky! So it was reading in blocks of 512, but because the EOF was exactly on the boundary of a block it missed it and kept reading off the edge of the file?

Thanks for the fix glx. :)
PathZilla - A networking AI - Now with tram support.
User avatar
glx
OpenTTD Developer
OpenTTD Developer
Posts: 622
Joined: 02 Dec 2005 15:43
Location: Drancy(93) - France
Contact:

Re: [Windows] Forward-slashes in require() still don't work

Post by glx »

Indeed there is no "EOF", it's up to the tar reader to handle the end of file. That's why the file size is in the header.
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: [Windows] Forward-slashes in require() still don't work

Post by Zutty »

Aaaaaah!
PathZilla - A networking AI - Now with tram support.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 35 guests