Welcome to the Achaea Forums! Please be sure to read the Forum Rules.

Scripts not disabling

LilianLilian Member Posts: 370 ✭✭✭ - Distinguished
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 :(


  • KeneanungKeneanung Member Posts: 618 ✭✭✭✭ - Eminent
    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
  • AntoniusAntonius Member Posts: 5,040 @@ - Legendary Achaean
    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.
  • LilianLilian Member Posts: 370 ✭✭✭ - Distinguished
    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.
  • KeneanungKeneanung Member Posts: 618 ✭✭✭✭ - Eminent
    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.
  • DunnDunn Member, Secret Squirrel Posts: 6,324 @@ - Legendary Achaean
    edited December 2014
    function functionName()
    insert real function stuff here

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

    function functionName()


    Or disable and restart.

  • JonathinJonathin Retired in a hole.Member Posts: 3,423 @@ - Legendary Achaean
    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.

    My site will remain up, but will not be maintained. The repository will continue to have scripts added to it if I decide to play another game. Maybe I'll see you around in Starmourn!
    Tutorials and scripts  The Repository

  • TaelTael Member Posts: 1,197 @ - Epic Achaean
    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.
  • LilianLilian Member Posts: 370 ✭✭✭ - Distinguished
    Thanks for all the suggestions and explaining it. I get it now!
Sign In to Comment.