Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Conditional include possible? (Userconfig)

  1. #1

    Conditional include possible? (Userconfig)

    Hi there,

    well, we all know that statement:
    Code:
    #include "\unserconfig\test.hpp"
    If that file does not exist Arma will inevitably crash (<- btw, is this really necessary ). 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

  2. #2
    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.

  3. #3
    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:
    Code:
    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

  4. #4
    No idea however what options would be left.
    Depends on what your trying to change with the include?

  5. #5
    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
    Last edited by Sickboy; Dec 21 2009 at 08:01.
    A.C.E. Advanced Combat Environment

    Dev-Heaven.net Free Project Hosting | A2 Community Issue Tracker Help BIS, Help yourself!

  6. #6
    @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 ).

    @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

  7. #7
    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)
    Last edited by Sickboy; Dec 21 2009 at 08:41.

  8. #8
    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 The script aborts with an error. At least it doesn't CTD rightaway. Back to square 1.


    Thanks,
    VictorFarbau
    Last edited by VictorFarbau; Dec 21 2009 at 10:06.

  9. #9
    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
    Last edited by VictorFarbau; Dec 22 2009 at 14:17.

  10. #10
    Yup. Workable solution for non config needs. Thanks for sharing.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •