Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

LiquidBounce Forum

  1. Home
  2. ScriptAPI
  3. plz help #2

plz help #2

Scheduled Pinned Locked Moved ScriptAPI
3 Posts 2 Posters 230 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KnechtRobert5
    wrote on last edited by
    #1

    Is this the optimal way to check wether a setting was changed while a module is enabled?
    This is my example script:

    /// api_version=2
    var script = registerScript({
    	name: "ExamplePfiff",
    	version: "0.0",
    	authors: ["KnechtRobert5"]
    });
    script.registerModule({
    	name: "Pfiff",
    	category: "Misc",
    	description: "Does some Pfiff here and there.",
    	settings: {
    		examplesetting: Setting.boolean({
    			name: "enable",
    			default: true
    		})
    	}
    }, function(module) {
    	var wasenabled = false;
    	module.on("enable", function() {
    		if (module.settings.examplesetting.get()) {
    			Chat.print("§aon")
    			wasenabled = true;
    			//module enabled
    		}
    	});
    	module.on("disable", function() {
    		if (module.settings.examplesetting.get()) {
    			Chat.print("§coff")
    			wasenabled = false;
    			//module disabled
    		}
    	});
    	module.on("update", function() {
    		if (module.settings.examplesetting.get() && !wasenabled) {
    			Chat.print("§aon")
    			wasenabled = true;
    			//setting enabled
    		}
    		if (!module.settings.examplesetting.get() && wasenabled) {
    			Chat.print("§coff")
    			wasenabled = false;
    			//setting disabled
    		}
    		
    	});
    });
    

    The main module here does nothing, only if the setting in it is true / false it loads / unloads code. this script works perfectly for what im trying to do, but is it the optimal way to check for that and does it impact the performance of the game if it checks every tick (while module is enabled) if the setting is true or false? (Sorry if this sounds dumb but im new to this kinda stuff)
    If asked for what this is needed, i want to make a clean module which doesent break that easily or in general doesnt break (user friendly)

    1 Reply Last reply
    0
    • Senk JuS Offline
      Senk JuS Offline
      Senk Ju Admin
      wrote on last edited by Senk Ju
      #2

      If you just want to check if the state of a setting has changed, the following code might be an simpler solution:

      // <your code>
      
      var lastState = null;
      
      module.on("enable", function() {
          lastState = module.settings.examplesetting.get();
      });
      
      module.on("update", function() {
          var currentState = module.settings.examplesetting.get();
      
          if (lastState !== currentState) {
              Chat.print("State has been changed! New state: " + currentState);
              lastState = currentState;
          }
      });
      
      // <your code>
      
      

      From a performance point of view you should not expect any problems here. Getting the state of a setting should require very little runtime.

      K 1 Reply Last reply
      0
      • K Offline
        K Offline
        KnechtRobert5
        replied to Senk Ju on last edited by
        #3

        @Senk-Ju thanks 🙂

        1 Reply Last reply
        0

        About
        • Terms of Service
        • Privacy Policy
        • Status
        • Contact Us
        Downloads
        • Releases
        • Source code
        • License
        Docs
        • Tutorials
        • CustomHUD
        • AutoSettings
        • ScriptAPI
        Community
        • Forum
        • Guilded
        • YouTube
        • Twitter
        • D.Tube
        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups