Page 2 of 6 FirstFirst 1234 ... LastLast
Results 11 to 20 of 60

Thread: Schripting Advice (Tutorial)

  1. #11
    Developer RyBack's Avatar
    Join Date
    Apr 2014
    Location
    In Front of the screen
    Posts
    1,603

    Default

    there is try catch in Morpheus , but I don't think it'll do memory leaks or crashes.
    maybe infinite loops but who knows.
    I never liked try catch-es anyways. They're kinda lame.
    You could add a try catch on every piece of code in any program/script. which makes it more clustered/inreadable for no reason.
    function call returns error/errorcode is better for me

  2. #12
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    You could do both. Reborn has them all over. Not just return codes/errors but try/catch to try and prevent bad stuff from happening.
    Yes, it might appear a bit more cluttered, but I think the additional 2 lines of code could benefit in the long run, especially when you start developing very convoluted scripts and such. Take something like the freeze-tag mod by mefy... A fantastic mod, but I have come across several threads on this forum alone of users having issues with MEFY's mod. It could be something as simple as 2 different mods not being compatible with each other, but with a try/catch I think you could potentially avoid the game/server from crashing if you catch it.

    You're right, maybe memory leaks can't be caught because that's typically internal coding (binaries), but for sure you should be able to avoid infinite loops or even incompatibilities with other mods.

    I'm actually surprised this hasn't been tried before. Maybe it has, but it doesn't have as much support as in programming; but I think if one could make use of it, then it can open doors to much cleaner code and more stable mods. That's just my opinion though.

    When I program stuff, I always try to develop with "worst case scenario" in mind... Meaning, if something works; fantastic, but if it doesn't work, what are all the different variables that can prevent it from working and why? And in scenarios like this a try/catch along with a switch with different cases could be useful.

  3. #13
    Developer RyBack's Avatar
    Join Date
    Apr 2014
    Location
    In Front of the screen
    Posts
    1,603

    Default

    Quote Originally Posted by James View Post
    You could do both. Reborn has them all over. Not just return codes/errors but try/catch to try and prevent bad stuff from happening.
    Yes, it might appear a bit more cluttered, but I think the additional 2 lines of code could benefit in the long run, especially when you start developing very convoluted scripts and such. Take something like the freeze-tag mod by mefy... A fantastic mod, but I have come across several threads on this forum alone of users having issues with MEFY's mod. It could be something as simple as 2 different mods not being compatible with each other, but with a try/catch I think you could potentially avoid the game/server from crashing if you catch it.

    You're right, maybe memory leaks can't be caught because that's typically internal coding (binaries), but for sure you should be able to avoid infinite loops or even incompatibilities with other mods.

    I'm actually surprised this hasn't been tried before. Maybe it has, but it doesn't have as much support as in programming; but I think if one could make use of it, then it can open doors to much cleaner code and more stable mods. That's just my opinion though.

    When I program stuff, I always try to develop with "worst case scenario" in mind... Meaning, if something works; fantastic, but if it doesn't work, what are all the different variables that can prevent it from working and why? And in scenarios like this a try/catch along with a switch with different cases could be useful.
    Totally agree, but here is the thing:
    This is how I think about implementing try-catch in my code,
    Code:
    -Ok , so portion 1 of func 2 needs a try catch, ezpz.
    -oh! adding another one to portion 2 will be good.
    -hold on! I could add another trycatch to the func2 call
    -maybe another one for func1 call that calls func2.
    and I keep overthinking about minor insecurities in the whole code that are try-catch-able.
    I kinda panic over how I'd need to add trycatches everywhere and whether or not I should re-implement the whole thing with trycatches in mind .

  4. #14

    Default

    That is a excellent question James, I didn't think it would.
    It could come in very handy for beginners or if you are testing code.
    I shall include it in my tutorial, assuming it works with stock Mohaa.

    But I suspect you guys are talking about features that are in reborn, not in the stock version.
    The only issue I have so far is that everyone can get the stock version, but what if the reborn site it gone and users can't find the reborn patch ?
    Then nothing will work, so I tend to either provide the required files with it (unless it is a official patch) or don't use them at all.

  5. #15

    Default

    Someone was speaking about the threads and theres 3 things you can do with them:

    Delay

    Code:
    local.thread wait 3
    Pause

    Code:
    local.thread pause
    End

    Code:
    local.thread end
    @chrissstrahl: The most dangerous code in mohaa is the while loop or threads can create a loop because they are enought to crash a server.

    You speaking about a try{catch} but im not understandyng how works. Can someone put a example in code so i can understand please?
    Last edited by DoubleKill; July 10th, 2018 at 03:49 AM.

  6. #16

    Default

    It's exception handling.

    Commonly they look something like:

    Code:
    try 
    {
     // something
    }
    catch (Exception e) 
    {
     // something
    }
    So if the code executed in the try block results in an exception, it'll run the catch block.

    I tried this morning in MOHAA and it recognises the syntax and the code is executed inside the try block, but I can't get it to catch anything. E.g.:


    Code:
    try
    {
    	while (1)
    		println "infinity"
    }
    catch 
    {
    	println "caught"
    }
    Oh, and this is where I saw it referenced:

    Code:
    statement:
    ----------
    identifier event_parameter_list :
    case integer event_parameter_list :
    case identifier event_parameter_list :
    compound_statement
    if prim_expr statement
    if prim_expr statement else statement
    while prim_expr statement
    for ( statement ; expr ; statement_list ) statement
    try compound_statement catch compound_statement
    switch prim_expr compound_statement
    break
    continue
    identifier event_parameter_list
    nonident_prim_expr identifier event_parameter_list
    nonident_prim_expr = expr
    nonident_prim_expr += expr
    nonident_prim_expr -= expr
    nonident_prim_expr ++
    nonident_prim_expr --
    Last edited by 1337Smithy; July 10th, 2018 at 05:47 AM.

  7. #17

    Default

    If you tried catch with reborn, I think I have read something somewhere saying it prevents certain kind of crashes, that might include while and for infinity loops, by waiting a frame instead of printing a error message ?
    This is just a wild guess.

  8. #18

    Default

    Ah right, I don't use Reborn so can't test this.

  9. #19

    Default

    Quote Originally Posted by chrissstrahl View Post
    If you tried catch with reborn, I think I have read something somewhere saying it prevents certain kind of crashes, that might include while and for infinity loops, by waiting a frame instead of printing a error message ?
    This is just a wild guess.
    He tested without Reborn so the "try" have already a waitframe.

    I think i know how to catch a error, going to test later.

  10. #20

    Default

    I don't think the try has a waitframe, I was suggesting that one way to fix a for or while runaway loop would be to insert a pause just like waitframe does, instead of letting it error out as it does do now.

    The try should never error out no matter what code you use, it will simply execute the code given in catch instead.
    In c# you can retrieve the error that was catched, I dono how it is in mohaa, perhaps is something like parm.error or local.error or script.error.
    I can only speculate at this point.

Posting Permissions

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