Jump to content
Sign in to follow this  
VictorFarbau

Conditional include possible? (Userconfig)

Recommended Posts

Hi there,

well, we all know that statement:

#include "\unserconfig\test.hpp"

If that file does not exist Arma will inevitably crash (<- btw, is this really necessary :confused:). But is there any smart way to catch the "File not found" exception?

Generally speaking I want to leave it up to the user whether to use an hpp file or to go with default values of the addon.

Thanks,

VictorFarbau

Share this post


Link to post
Share on other sites

My suggestion. Release two versions.

You could split your pbo to two, and use an include in one. The user could remove

that pbo (with the include). In that case the other uses default values / its own values.

Share this post


Link to post
Share on other sites

Kju, I take that as a no ;) The best I could come up with so far was the 2-version solution as well... kind of annoying though.

'Loadfile' on something like "/userconfig/test.hpp" also doesn't work:

Invalid path (only relative paths supported)

Well, quite obvious for a sandbox concept. However, I would wish the preprocessor would allow exception handling in a script instead of crashing the whole application.

That 2 file solution - I am not yet ready to settle for it :) No idea however what options would be left.

VictorFarbau

Share this post


Link to post
Share on other sites
No idea however what options would be left.

Depends on what your trying to change with the include?

Share this post


Link to post
Share on other sites

loadfile "\userconfig\test.hpp" will probably work better :)

To answer your question; to my knowledge there is no way to recover from the problem. Preprocessor is a little dumb :P

One side I think it would be nice if BI did something about it. On the other hand, if your config is missing includes, it could lead to weird results if still compiled, so im not sure if they should actually change it.

For description.ext I think they should... Nothing more annoying to have a minor typo, and get kicked out of an already running game :P

Edited by Sickboy

Share this post


Link to post
Share on other sites

@UNN - I'd rather leave it up to a user whether he/she chooses to create a hpp config file for an addon. If not then the addon should use its defaults. For many users the concept of creating directory trees and moving files to specific subdirs is an obstacle (plus, it would require to read the readme :D ).

@Sickboy, apart from the / \ mix (same result btw :) ). To terminate the whole app because of a potentially undefined state is a rather cheap way to deal with it, isn't it. The preprocessor could simply do this - if include file found, all nice and dandy, carry on. If include file not found, scan for "OnException" statement in the same code. If statement not present throw an error message and abort the mission / code execution (and not the application context). If statement present leave it up to the user to react accordingly. It's not that the script engine can't deal with undefined variables of functions.

Small change, big impact for addon makers in my mind. Not sure how open BIS currently is to conceptual changes of that kind.

Anyways, looks like it'll be the two versions solution for now.

Thanks,

VictorFarbau

Share this post


Link to post
Share on other sites

Thats what I mean, mission script / description.ext should not crash the game, but for the main game config, I think it's fine.

The preprocessor is not connected to the scripting engine to my knowledge, and include is a preprocessor directive.

Maybe one of the reasons preprocessors are virtually non existent in new modern languages, perhaps ? :)

I remember reading about the loadfile limitations, just didnt think you wouldnt be able to read files from the arma2 folder no more :O

I would like to know the answer to UNN's question aswell;

What are you trying to influence with the include ? Config or Script ?

(Do you include from a config, or from a script)

Edited by Sickboy

Share this post


Link to post
Share on other sites

Dear me, I just had a typo in the loadfile test. I can confirm this still works! Excellent, this should solve my problem.

I wanted to include certain parameters on script execution based on the existence of a config (hpp) file. Hence I am including it from within a script context and not in the addon config / description.ext. The latter would be critical admittedly, the script solution should be easy to handle in my mind.

However, if I get the loadfile exception (Try, Catch) to work then the whole thing should be doable. I'll get back with the details after success / failure.

EDIT: "Try" does not catch a loadfile failure :rolleyes: The script aborts with an error. At least it doesn't CTD rightaway. Back to square 1.

Thanks,

VictorFarbau

Edited by VictorFarbau

Share this post


Link to post
Share on other sites

It does work indeed. Instead of a real config file I will use regular sqf script syntax in my 'test.hpp' file to define the desired variables. The calling script will use 'call compile loadfile "\userconfig\test.hpp"' to access the file.

In case the file does not exist there will be an error message in game; however the script will continue to run (correction to my above message). Then this error can be handled (check for missing var definition = file wasn't loaded) and default values can be used.

I think that's a fair tradeoff compared to the CTD scenario caused by missing / misplaced config files otherwise.

Add1: When creating a file to be included and compiled by 'loadfile' command then you can't comment using "//". You have to use 'comment("example");' syntax instead.

Cheers,

VictorFarbau

Edited by VictorFarbau

Share this post


Link to post
Share on other sites

Yup. Workable solution for non config needs. Thanks for sharing. :)

Share this post


Link to post
Share on other sites
For many users the concept of creating directory trees and moving files to specific subdirs is an obstacle

Realy. True, I have met people who can't quite grasp the concept. But there usualy over 60? How abstract is a forum compared to a directory :)

Edited by UNN

Share this post


Link to post
Share on other sites

Congrats to your optimistic view on things UNN but I don't share it :) Foolproof today - less impact tomorrow. Specially when it comes to CTD then a bit more care is due I believe.

VictorFarbau

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  

×