Scripts not disabling

so I found out recently that mudlet doesn't actually turn off scripts even if you click em off our use an alias/trigger via disableScript("Blahblah") and I know it's not turning off the script because several others stop functioning properly when I have it on or off..so does anyone know how to actually fix this or a work around? Because it breaking my offense stuff really sucks :(

Comments

  • Why would you want to disable scripts?

    An easy workaround is to create a boolean variable that's set to false to disable the scripts. At the beginning of each script you want to disable do the following check:

    if turnOffScript then
      return
    end
  • If all it does is create functions and such then you need to restart Mudlet. Disabling the script doesn't undo everything it has already done, so those functions are still there.

    I've never tried but disabling it might be enough if it's an event handler. The function would still exist but probably wouldn't be called.
  • As for why I would need to stop it, because I have two functions interfering with each other. I tried to make the functions different names and separate them completely but they continued to fight each other or something. I'm only a beginner at this stuff so I don't understand/know what I am doing just how to do it.
  • To see changes to function names and such, you will need to restart mudlet as Antonius writes. The reason is the following: on startup, each script is run and function declarations are made. Changing a function declaration doesn't change the old name, because mudlet doesn't "remember" the code that creates a function. It's simply there and after the change there is even ANOTHER function that does something.

    Whereas 2 functions/variables (functions are saved in variables in lua as well) with the same name (or saving a script with unchanged function and variables) overwrite each other.

    You could also delete the script with the unneeded function, if there are no other things in it.
  • edited December 2014
    function functionName()
    insert real function stuff here
    end

    Create a new function below it that has a blank script.

    function functionName()

    end

    Or disable and restart.


  • JonathinJonathin Retired in a hole.
    If it's only a couple functions and you really don't want to restart, you could probably just functionName = nil and then reload the scripts after changing one of them.
    I am retired and log into the forums maybe once every 2 months. It was a good 20 years, live your best lives, friends.
  • To offer a little more explanation, scripts don't work the way you probably think they do.

    A function definition in a script isn't the function itself. Think of it like a recipe - if you've already cooked the meal, throwing away the recipe doesn't get rid of the dish.

    What a script does is just run a bunch of code whenever you start Mudlet or save the script. That's it.

    So if you have a script that defines a function, you save it or start Mudlet and it runs the script, creating the function. That function is now a thing - it lives somewhat invisibly in Mudlet. Disabling the script won't disable the function because the script doesn't contain the function, only the instructions for how to create the function, which has already happened.

    If you restart Mudlet with the script disabled, the function won't get created in the first place. Alternatively, if you do functionName = nil and save the script again, it'll also get rid of it (at which point you can just remove all references of it from the script and resave).

    You can use a boolean (a true/false) if you really want to use the same name for your functions, but the sensible solution is probably just to give them different names and then restart Mudlet.
  • Thanks for all the suggestions and explaining it. I get it now!
Sign In or Register to comment.