Very basic script not working properly. No errors - it just doesn't execute some lines at its own will. Tried everything, completely lost! Please help

Willkommen in der OMSI-WebDisk!
Als Gast kannst du nur Inhalte in deiner ausgewählten Sprache sehen. Registrierte Nutzer können die Sichtbarkeit anderer Sprachen in ihrem Kontrollzentrum aktivieren, weitere Infos hier.
Alle Themen sind in den Foren mit einer Sprachflagge gekennzeichnet: = Englisch [EN], = Deutsch [DE], = Französisch [FR]. Wenn du die angegebene Sprache nicht beherrschst, schreibe auf Englisch!
  • 1. Which programme do you have a problem with? (Main application, editor, SDK tools, etc.)

    Main application


    2. Please describe the problem in as much detail as possible. What happened or what might have led to the error?


    I added a trigger and a macro to the cockpit.osc file. The macro is called by the trigger (which is a simple variable incrementer).


    The relevant parts of the script file are:



    The issues are:


    In the second code block of the macro ' Steering Wheel Index 1, the lines 1 (S.L.strw1_isVisible) and 1 (S.L.smallPiece_isVisible) fails to execute or something. The variables just remain at 0


    In all remaining code blocks of the macro ' Steering Wheel Index x, the line 1 (S.L.strw1_isVisible) executes fine, if present, but the line 1 (S.L.smallPiece_isVisible) ALWAYS fails to execute.


    I have literally no clue why this is happening. I have verified that OMSI is entering the if statement because it successfully sets strw1_p1_isVisible to 1. However it just doesn't want to do the rest!


    Notes:

    - All relevant variables are in the varlist.

    - There are no spelling mistakes anywhere - I verified this by checking all scripts and model.cfg over 4 times with Notepad++ Find In Files.

    - No variable used by the script is being set in any .cti file.


    What have I tried:

    - Initialising variables to 0 even though I dont need to

    - Removing the first code block completely so there is no possibility of 0 being around in the script.

    - Changing the entry condition for if statements to greater than 0,1,2,3 etc. incase of floating point precision issues (I noticed when debugging with the Situations feature that values are 0.99999994352 - I know this never is an issue with these types of script, but worth a try)

    - Converting the .osc text file to UTF-8/ANSI incase special chars remaining were interfering

    - Using OMSI's verbose logging launch arguments to see if anything more was in the logfile (nothing)

    - Putting all the variable assignments to one line

    - Adding %stackdump% to parts of the macro and if statement all over the script in debug mode (it didnt do a thing)

    - Setting the macro to a frame

    - Putting the macro in a frame

    - Putting the macro inside another script

    - Testing the script with the OOMPH tool from Sobol's Discord server, which would highlight script errors in the log - nothing outputted to logfile when I trigger the trigger/macro, meaning it did not detect syntax errors.

    --- Monitoring the variables, they behave the same as in omsi, but if i double click any manually type a value (to the same sig fig) and hit enter it just reverts immediately - guessing thats a symptom of that variable being set to 0 every frame? I cannot find a reason for this though


    Btw - I know this is rly inefficient in terms of variables, but i still needed it for proper base cases


    3. Please add a log file to your post, either in a spoiler, code block or as a file attachment.


    There is literally nothing useful or related to scripts in it. But anyway, here you go:



    All help is very widely appreciated. I have been pulling my hair out for an entire day on this small issue, which feels like a bug with OMSI itself. If I can't fix it within a few hours I'll just bin the entire code and combine the o3ds instead.

    Z5843Jl.png  kjq2JB9.png

    i7 5820K @ 4.1GHz • Zotac GTX 980Ti AMP! 2-way SLI • Full PC Specs

    Einmal editiert, zuletzt von shanie ()

    • Hilfreichster Beitrag

    Hello,

    after looking at your script, I noticed pretty quickly that everything works as it should. The problem is that the script has an "error" and therefore the variables can only be set to 0. I'll explain a little more precisely what is wrong: In the macro, all steering wheel types are queried one after the other, without excluding the other steering wheel types with, so the script also checks after the correct steering wheel type has been selected whether the other conditions are met could be true. The macro should stop checking after the correct steering wheel type has been selected, so that the {else} section does not set the variables set to 1 back to 0.


    To solve the problem you have to rewrite the macro: all {endif} entries in the macro have to be moved to the end of the macro, since the {else} condition works exclusively and is no longer checked one after the other, as originally. I'll show you how it should work:

    You can try to see if it works and then maybe give a short feedback. Maybe there is another solution that may be more complicated, but I think that is the easiest and best solution.

    Btw: Incidentally, it is not necessary to include the steering_wheel_swap_visCheck macro in the frame, as it was already triggered by the trigger and thus only eats up performance unnecessarily, even if it is negligible in practice.

    Good Luck!

  • <Snip>

    You can try to see if it works and then maybe give a short feedback. Maybe there is another solution that may be more complicated, but I think that is the easiest and best solution.

    Btw: Incidentally, it is not necessary to include the steering_wheel_swap_visCheck macro in the frame, as it was already triggered by the trigger and thus only eats up performance unnecessarily, even if it is negligible in practice.

    Hey! Thanks so much for your help. Sorry for my late reply - I didn't want to reply before I had a chance to sit down and test this. You made a brilliant point and I really should have considered this. In the past when browsing scripts I often saw many many if statements that appeared nested, with a ton of endifs. I thought those were literal nested if statements, though, not just a bunch of sequential ones.


    So I replaced the code with your updated macro. But, the issue persists. I don't really know what to say.


    Everything is present in the varlist file as needed, I am using the right .bus (theres only one cockpit.osc script in the whole .bus folder anyway).


    Checking the .osn file of the saved situation, the smallPiece_isVisible doesn't even appear, presumably since it isn't initialised anywhere outside the if statements, so this tells me that its still not entering the body of the if statements.


    The other issue is, even strw1_isVisible is stuck on 0! This wasn't an issue beforehand.


    However, vis_steeringwheeltype updates properly.


    Not sure where to go with this now, I tried looking through some more scripts for similar structures but I can't seem to find what I stumbled upon before...

    Z5843Jl.png  kjq2JB9.png

    i7 5820K @ 4.1GHz • Zotac GTX 980Ti AMP! 2-way SLI • Full PC Specs

  • Alright, I guess I was doing something wrong. You were spot on, and I now understand the concept of nested if statements, just didn't see it immediately due to indentation.


    There is an even simpler script by Road-Hog 123 and some more thoughts from me in this thread.


    This issue is solved

    Z5843Jl.png  kjq2JB9.png

    i7 5820K @ 4.1GHz • Zotac GTX 980Ti AMP! 2-way SLI • Full PC Specs