Page 4 of 6 FirstFirst ... 23456 LastLast
Results 31 to 40 of 51

Thread: Schripting Advice (Tutorial)

  1. #31

    Default

    I think this is pretty much the final version.
    I have shortened it here and there, added some more topics and examples and removed all the code in the images and put it into tables so it is very printer friendly.

    Thanks to everyone who helped, you all are in there

    I am thinking of uploading this to gamefront and moddb, are there other sites where this would fit ?

  2. #32

    Default

    I have add your tutorial to the AAAA Database.

  3. #33

    Default

    I disagree with the use of brackets at the start of the thread. You are just adding unnesesary noise to the code. and looks like a sad face (:{)
    Instead of that i would reinforce the use of a proper indentation.

    about "DO NOT USE GOTO". I also disagree. In specific situations (not as replacement of a while loop) "goto" can come very handy to your script. You just have to know how, and where to use it.

    and the Warmup Time (g_doWarmup, g_warmup) is broken in mohaa, you should remove that.

    Besides that, very nice guide.

  4. #34

    Default

    I strongly disagree.
    The brackets make a big difference in the readability of the code, and there for not unnecessary at all.
    I make this claim based on my experience from the past 16 years I have been dealing with all kind of different code.
    Just indenting the code can and will fail you if you give the code to someone else using a different editor/os/spacers/tabs
    I can't imagine big junks of code without brackets, you get lost quickly if the indenting is messed up.

    Well, the go to thing is a endless Argument, I think it invites to much troubles and a unclean coding style.
    That is why I recommend against it. In mohaa script you might overlook the use of goto, but it is not a good habit to getting used to.
    You have to keep in mind that not everyone reading that document has been coding for years and knows how to safely use go to.

    I will have to look into the warmup thingy, because we are running on BT, I am not sure if it is broken there too.

  5. #35

    Default

    Surely a lot of this is subjective, though?

    I mean, almost no one in the MOHAA community used brackets at the beginning and end of functions in its 17 years of existence, and people have coped fine and never felt the need to. From a personal perspective, it doesn't add anything for me, and I've also used various languages for years that do and don't use them.

    And indenting-wise, the good practice is to have the function name and the bottom terminating 'end' unindented (with code inside indented), which means those start and end lines aren't often affected by using different editors, so in almost all cases it's easy to determine where a function begins and a function ends.

    But back on to the subjectivity part, it's just not a common practice in the MOHAA community. I don't know if it's the same in other communities, and I know with games like CoD the bottom bracket signals the termination (and not an 'end') so it's needed, but I honestly don't see the need here, similar to languages like Visual Basic. Yes, being able to use multiple editors makes a difference, but not often for function starts and ends, which can be obscured for other reasons. Honestly, I swap between Sublime, Notepad++, and Notepad regularly when reading MOHAA scripts, and rarely have a problem, especially one so big that the text becomes incoherent.
    Last edited by 1337Smithy; March 25th, 2019 at 04:51 AM.

  6. #36

    Default

    I strongly agree with Smithy, adding extra code and the code still compiles widhout him is unnecessary.

    When you work in a company of devs the 2 very importante things on the code is identing and add comments so everyone can understand the code does.

  7. #37
    Developer Todesengel's Avatar
    Join Date
    Dec 2013
    Location
    St. Louis, Missouri, USA
    Posts
    239

    Default

    I strongly agree with Chrissstrahl overall. A non-trivial amount of mohaa scripting was done by self-taught server owners who learned on morpheus with no prior study/experience in programming and it shows. A good chunk of the mod files found around the net have some really atrocious coding. Not just unattractive code, but code that is written in such a way as to breed really awful errors when others go to modify it. I suspect that a good percentage of this is due to many mods being nothing more than a set of copy-pastes from various sources rather than something crafted by hand. I salute chris's efforts.

    Yes, much of the document is subjective but I suspect that the vast majority of professional programmers would agree with the vast majority of his suggestions. I personally don't use braces on a function body, mainly so I can use the left margin more effectively than whitespace, which just causes future braces to be indented yet another level and on non-132+column (my window is 72x210 but I try to be considerate) editors that makes it hard to read. That being said, those braces ARE going to make it easier to find a 'end' that is missing or misplaced which is a very common error. But the way programming editors let you collapse and expand.... that is a reason that may convince me to try his way

    As for goto's, that is a religious war. IMHO - using a goto is often (but definitely not always) a sign of "I didn't really think this code through, and coded myself into a corner, and a goto is the easy way out of the mess I just created". I think beginning programmers shouldn't use goto, they need to express the procedure a different way. More advanced programmers will find the right situations to use it (and I believe those situations will be exceedingly rare, if at all). Just my two millidollars worth

    I really wish chris's document had been around in 2000, but I'm glad it's here now and hope that many beginning scripters will at least give it a look. Anyone coming after them will appreciate it

    Tode

  8. #38

    Default

    Quote Originally Posted by chrissstrahl View Post
    The brackets make a big difference in the readability of the code, and there for not unnecessary at all.
    They are unnecessary. Your statement is based in your experience with a specific text editor, Notepad++. And is not directly related to morpheus script itself.

    In Morpheus you can do:

    // THIS:
    main:
    ...
    end;

    // THIS:
    main:{
    ...
    }end;

    // OR THIS:
    main:{{{
    ...
    }}}end;

    And it will make no difference in the execution of the code. So, why the need of adding the brackets?
    That is something directly related to Notepad++ behavior only.
    Also, in modern text editors, like Sublime, Atom or Visual Studio the tab/space indentation is detected as code blocks, so you can do this:
    Spoiler: image



    Quote Originally Posted by chrissstrahl View Post
    Well, the go to thing is a endless Argument, I think it invites to much troubles and a unclean coding style.
    With goto, instead of doing this:
    Code:
        thread <label> local.arg1 local.arg2 local.arg3 local.arg4...
        end
    you can just use "goto <label>" to jump to another label without the need of passing the arguments
    I don't see how that can cause troubles or make a code unclean
    I mean, if you know how to use it, you will never have problems, and if you don't, then you should keep learning.


    Quote Originally Posted by chrissstrahl View Post
    You have to keep in mind that not everyone reading that document has been coding for years and knows how to safely use go to.
    IMO that's not a valid reason to say "do not use goto". Pass over some concepts in a scripting guide just because you don't like or understand it, is not a good thing. You should teach (properly) and let the user decide whether to use it or not.

  9. #39
    Developer Todesengel's Avatar
    Join Date
    Dec 2013
    Location
    St. Louis, Missouri, USA
    Posts
    239

    Default

    Quote Originally Posted by Zappa View Post
    With goto, instead of doing this:
    Code:
        thread <label> local.arg1 local.arg2 local.arg3 local.arg4...
        end
    you can just use "goto <label>" to jump to another label without the need of passing the arguments
    I don't see how that can cause troubles or make a code unclean
    I mean, if you know how to use it, you will never have problems, and if you don't, then you should keep learning.
    For the exact same reason they teach beginning C programmers to use functions and pass values (and made the default for most compilers by-value instead of by-reference, and you have to go out of your way to do by-reference {ie. pointers}), instead of declaring every variables scope outside of main and thus making it global (look what extra inefficient steps a compiler/interpreter has to do for global variables vs. local sometime). It defeats the whole purpose and protection mechanism of using limited variable scope! If you do it the suggested way, it tends to make your code less prone to errors related to scope. And even if you deal with it by declaring all variables as global - that choice is going to shoot the NEXT programmer in the foot very likely.

  10. #40

    Default

    Quote Originally Posted by Zappa View Post
    They are unnecessary.
    Your statement is based in your experience with a specific text editor, Notepad++.
    And is not directly related to morpheus script itself.
    And it will make no difference in the execution of the code. So, why the need of adding the brackets?
    That is something directly related to Notepad++ behavior only.
    You should teach (properly) and let the user decide whether to use it or not.
    - They might be unnecessary for you and others who know their way around, but dealing with beginners or some one who hasn't learned all the rules this is a big help, so they are clearly not unnecessary for these people. You must assume that not everyone reading your code is as good as you, some one might start learning from your code, and I doubt they understand it as easy without the brackets.
    - No, it is not, I did not only use Notepad++, I just prefer it, but I have tried many editors and other IDE, even eclipse...
    - Yes it is, I made a Coop Mod for Star Trek Elite force II and it uses the latest most advanced version of morpheus, and they force you to use brackets there, I think this is clearly a hint
    - Because clean code is not about execution and looking cool, it is about easy understanding, fast reading and finding quickly what you are looking for.
    - No it is not, there are many other editors that support that, even Visual Studio IDE supports it. But the point is not only the collapsing but they orientation in the code, if you don't need it that is great, but my Advice is to use them, because they make it easier to read the code, because you can see without thinking/understanding the code, where a block starts and where it ends.
    - Please tell me where I did not teach it properly with goto, do you have a suggestion how to improve the goto related Chapter ?
    Last edited by chrissstrahl; March 25th, 2019 at 12:24 PM.

Posting Permissions

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