Jump to content
Sign in to follow this  
ManDay

loadFile & Compile: Error with comments

Recommended Posts

^ Nuff said. Compile will produce an error when comments are in the string.

Share this post


Link to post
Share on other sites

Can you show an example? For me it does not bring up an error on comments icon_rolleyes.gif

Share this post


Link to post
Share on other sites

0 spawn( compile loadFile "test.sqf" );

test.sqf:

while{ true }

{

//Again and Again...

sleep 1;

};

---

Should bring you up an error.

Share this post


Link to post
Share on other sites

Sure. Use preprocessFile if you want to have C-like comments.

Share this post


Link to post
Share on other sites

Anyone knows why "loadFile" exist at all?

The only reason for it as I see it is for "hardcore"-scripters* who doesn't bother to add comments?

There might be some performance gains too?

the

preprocessFileLineNumbers-command

is pretty nice if you have a huge script it'll return the line-number which you have an error at.

*stupid IMHO

Share this post


Link to post
Share on other sites
Anyone knows why "loadFile" exist at all?

The only reason for it as I see it is for "hardcore"-scripters* who doesn't bother to add comments?

There might be some performance gains too?

the

preprocessFileLineNumbers-command

is pretty nice if you have a huge script it'll return the line-number which you have an error at.

*stupid IMHO

It does support comments, just not C-like ones. Use them like this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">comment "insert comment here";

I doubt there are any performance improvements with loadfile. Maybe preprocessfile will have slightly better performance?

Are there any real differences between preprocessfile and loadfile?

Share this post


Link to post
Share on other sites

IIRC, preprocessfile loads into memory and loadfile discards it when completed

[EDit] I believe I am right, because back in SOW v2.0 we used it to load big init functions at mission start and I preferred that over preprocessfile because I knew it would be discarded.

Share this post


Link to post
Share on other sites
Quote[/b] ]loadfile discards it when completed

How can you tell? In my experience, once you Loadfile it, it's there for the duration.

Share this post


Link to post
Share on other sites

preprocessFile just does C like preprocessing (Comments, macros, etc.). It should be a bit slower than loadFile, but I doubt it makes a difference in any well designed 'real life' scenario. loadFile is needed if you do not want preprocessing, for example if you do this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

hint loadFile "message.txt"

If you used preprocessfile instead of loadfile here, and message.txt would contain, for example "// hello world \\" then the result would not be what you'd expect as preprocessFile would remove the message as it would think it's a comment.

Share this post


Link to post
Share on other sites

Now if we could have the comments work on spawn and call. That would be even better for people like me who don't always pull the scripts down from files.

Share this post


Link to post
Share on other sites

Additonally, it was not possible in OFP (or only certain versions?) to use preprocessFile from addon scripts, so you had to use loadFile there. So it's also still there for compatibility uses.

Share this post


Link to post
Share on other sites
preprocessFile just does C like preprocessing (Comments, macros, etc.). It should be a bit slower than loadFile, but I doubt it makes a difference in any well designed 'real life' scenario. loadFile is needed if you do not want preprocessing,

OK, I correct myself... THAT is more of what i remember.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×