Forum in READ ONLY mode! All questions and discussions on Discord official server, invite link: https://discord.gg/VxsGzJ7

[SOLVED] "'BEGIN' expected"; How do I use Pascal "Units"?

Ask for help
Post Reply
Chad Joan
Neophyte
Neophyte
Posts: 12
Joined: 17.05.2020 0:11

[SOLVED] "'BEGIN' expected"; How do I use Pascal "Units"?

Post by Chad Joan »

Hello,

I am trying to make Pascal/Delphi "Units" for my scripts to use, but I think I don't understand the workflow in Stealth Client.

These are my questions:
  • How does the compiler find "Unit" scripts when I reference them in the "Uses" statement?
  • How do you troubleshoot Units? How am I supposed to compile or validate Units?
I can only get the compiler to decide if Units are good or bad, but I can't figure out how to make it give me specifics (what's wrong and on what line).

You can stop reading here if you like, but in case it helps, here are the details:

My Stealth Client version is v8.10.2 and I am running it on 64-bit Windows 7.

I wrote a Program script and a Unit like so:

Code: Select all

// Comments
// ...
// Comments
Program SpeedLooter;
Uses
	SpeedLooterLib;
...

Code: Select all

Unit SpeedLooterLib;

interface
...
When I load the SpeedLooter script and try to compile/run it, I get an error like this:
Compiler: [Error] at (21:2): Unit 'SpeedLooterLib' not found or contains errors
I have tried it with SpeedLooterLib.pas in Scripts\, then in Scripts\Uses\, and I get that same result every time.

So I wondered if it was "not found" or if it "contains errors".

I've put it in the places I expect and named it as described in the docs. I try to investigate the "contains errors" possibility next.

I loaded the SpeedLooterLib.pas script as the active script and tried to compile/run it. The compiler gave me this error:
Compiler: [Error] at (1:1): 'BEGIN' expected
To exclude the possibility that I just don't understand Pascal syntax well enough, I try the same thing with the example files that came with Stealth Client in the Scripts\Uses\ folder. I get the same result:
Compiler: [Error] at (1:1): 'BEGIN' expected
That experiment seemed important, so I took a screenshot:
Image

If that doesn't work, here's a Google Photos link:
https://photos.app.goo.gl/qTDRzDB6WoFszGpC7

Now if I replace the above SpeedLooter program with this:

Code: Select all

// Comments
// ...
// Comments
Program SpeedLooter;
Uses
	CheckSave;
...
... then the compiler gets past the "Uses" statement.

First, this suggests to me that it is possible to use Units (at all). I wasn't sure up to this point. It also suggests to me that the compiler CAN find files in the Scripts\Uses\ directory. That makes it seem more likely that the compiler IS actually finding the SpeedLooterLib.pas file/Unit when I try to use it.

I'd like better confirmation, hence why I asked, "How does the compiler find "Unit" scripts when I reference them in the "Uses" statement?"

By process of elimination, and assuming the "not found or contains errors" message is accurate, then my SpeedLooterLib unit has errors in it (and CheckSave.pas does not). However, I can't find out what they are.

If I try to compile or run ANY "Unit" file, the compiler will give me the "'BEGIN' expected" error. So this doesn't tell me what's wrong.
If I try to compile or run a "Program" script that "Uses" a unit, then it will give me the "Unit 'BlahBlahBlah' not found or contains errors" error. This tells me that something is wrong, but not what.

In either case, I can't get the compiler to proceed deeper into the SpeedLooterLib file and tell me where my mistakes are. Hence my other question, "How do you troubleshoot Units?"

Thank you!
- Chad
Last edited by Chad Joan on 20.05.2020 22:26, edited 1 time in total.
User avatar
Vizit0r
Developer
Developer
Posts: 3958
Joined: 24.03.2005 17:05
Contact:

Re: "'BEGIN' expected"; How do I use Pascal Units in Stealth

Post by Vizit0r »

do you have folder Scripts\Uses\ in your Stealth folder? There many examples there.
If not - (re) download stealth from site.
"Пишите код так, как будто сопровождать его будет склонный к насилию психопат, который знает, где вы живете". (с) Макконнелл, "Совершенный код".
Chad Joan
Neophyte
Neophyte
Posts: 12
Joined: 17.05.2020 0:11

Re: "'BEGIN' expected"; How do I use Pascal Units in Stealth

Post by Chad Joan »

Yes, I have the Scripts\Uses\ in my Stealth folder.

It has two examples in it from when I downloaded Stealth:
Scripts\Uses\checksave.pas
Scripts\Uses\hungry.pas

Whenever I try to "run" either of them, I get the "Compiler: [Error] at (1:1): 'BEGIN' expected" error. I need to have some way to "run" scripts in the Scripts\Uses\ folder so that I can debug them and find my syntax errors.
User avatar
Vizit0r
Developer
Developer
Posts: 3958
Joined: 24.03.2005 17:05
Contact:

Re: "'BEGIN' expected"; How do I use Pascal Units in Stealth

Post by Vizit0r »

you should not run the, directly.

In your script write

uses checksave;

and after this you can call procedure CheckSave from this unit.
"Пишите код так, как будто сопровождать его будет склонный к насилию психопат, который знает, где вы живете". (с) Макконнелл, "Совершенный код".
Chad Joan
Neophyte
Neophyte
Posts: 12
Joined: 17.05.2020 0:11

Re: "'BEGIN' expected"; How do I use Pascal Units in Stealth

Post by Chad Joan »

I was wondering about that. Good to know!

But when I let the main script just pull in the module, I instead get the "Unit '____' not found or contains errors" error from the calling module/program. It always points at the beginning of the module (Unit), so I still have no way to debug the Unit.

However, I think I've found some things that solve my problem.

Here's what I was looking at:
Image

Here's what I probably should be looking at:
Image

In that latter picture ("System Journal" at bottom of main GUI), I can see that this particular error in the module ("Uses") file prints as "Identifier expected" and is on line 6 at column 22. Great!

Before that, I had also found this "Uses" path configuration setting that might contribute to the "not found" facet of the error:
Image

I haven't played with these things much yet, but hopefully this will keep working.

I think there is an opportunity here to improve Stealth: have the EditScript "error log" display more than just one line from the compiler/interpreter. That would save us from having to flip back-and-forth when a module (Unit) fails (or when any other information is missing from the EditScript window). More importantly, I think this would help other people and new users avoid a pitfall (I'm fine now that I have a workaround).

It would be even more stellar if the go-to-error feature would take me to the line in the module script rather than the "Uses" line in the main script.

Do you have a bug tracker or something like a github repository? I'd write a short feature request if I could :)

Thank you for keeping in touch and for working with me on this!
User avatar
Vizit0r
Developer
Developer
Posts: 3958
Joined: 24.03.2005 17:05
Contact:

Re: [SOLVED] "'BEGIN' expected"; How do I use Pascal "Units"

Post by Vizit0r »

>>Do you have a bug tracker or something like a github repository? I'd write a short feature request if I could :)

no

about EditScript error list - will check it
"Пишите код так, как будто сопровождать его будет склонный к насилию психопат, который знает, где вы живете". (с) Макконнелл, "Совершенный код".
Chad Joan
Neophyte
Neophyte
Posts: 12
Joined: 17.05.2020 0:11

Re: [SOLVED] "'BEGIN' expected"; How do I use Pascal "Units"

Post by Chad Joan »

Wow, thank you! :D
Post Reply