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. Getting variables/objects from other scripts

Getting variables/objects from other scripts

Scheduled Pinned Locked Moved Unsolved ScriptAPI
6 Posts 4 Posters 694 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    allison
    wrote on last edited by
    #1

    I'm trying to make an "Enemies" list to integrate with a suite of custom scripts that I'm developing; I have figured out how to create and use a FriendsConfig object to do this with the following:

    FriendsConfig = Java.type("net.ccbluex.liquidbounce.file.configs.FriendsConfig");
    jFile = Java.type("java.io.File");
    dir = new jFile(mc.mcDataDir, LiquidBounce.CLIENT_NAME + "-" + LiquidBounce.MINECRAFT_VERSION);
    
    EnemiesConfig = new FriendsConfig(new jFile(dir, "enemies.json"));
    EnemiesConfig.createConfig();
    
    saveMethod = EnemiesConfig.getClass().getDeclaredMethod("saveConfig");
    saveMethod.setAccessible(true);
    
    loadMethod = EnemiesConfig.getClass().getDeclaredMethod("loadConfig");
    loadMethod.setAccessible(true);
    loadMethod.invoke(EnemiesConfig);
    

    My problem is that I need to transfer the FriendsConfig object stored in the EnemiesConfig variable to my other scripts to be able to check if a player is an enemy (for example, a killaura script that prioritizes targeting enemies over other players).
    I have tried import/export but have not been able to figure out how it works; whenever I reload my script shows an error saying something like "Expected an operand but found export".

    A possible solution I've thought of is to create a separate FriendsConfig object that reads from enemies.json in each script, but that seems like a messy solution as it would require constant re-reading from the file to check for changes.

    (I already have all of the code to add/remove/list enemies working via a command, I just need help getting the object from one script to the other)
    If it is of any importance, I am using CzechHek's Core.lib for all my scripts.

    CzechHekC 1 Reply Last reply
    0
    • A Offline
      A Offline
      Aftery
      wrote on last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • A allison

        I'm trying to make an "Enemies" list to integrate with a suite of custom scripts that I'm developing; I have figured out how to create and use a FriendsConfig object to do this with the following:

        FriendsConfig = Java.type("net.ccbluex.liquidbounce.file.configs.FriendsConfig");
        jFile = Java.type("java.io.File");
        dir = new jFile(mc.mcDataDir, LiquidBounce.CLIENT_NAME + "-" + LiquidBounce.MINECRAFT_VERSION);
        
        EnemiesConfig = new FriendsConfig(new jFile(dir, "enemies.json"));
        EnemiesConfig.createConfig();
        
        saveMethod = EnemiesConfig.getClass().getDeclaredMethod("saveConfig");
        saveMethod.setAccessible(true);
        
        loadMethod = EnemiesConfig.getClass().getDeclaredMethod("loadConfig");
        loadMethod.setAccessible(true);
        loadMethod.invoke(EnemiesConfig);
        

        My problem is that I need to transfer the FriendsConfig object stored in the EnemiesConfig variable to my other scripts to be able to check if a player is an enemy (for example, a killaura script that prioritizes targeting enemies over other players).
        I have tried import/export but have not been able to figure out how it works; whenever I reload my script shows an error saying something like "Expected an operand but found export".

        A possible solution I've thought of is to create a separate FriendsConfig object that reads from enemies.json in each script, but that seems like a messy solution as it would require constant re-reading from the file to check for changes.

        (I already have all of the code to add/remove/list enemies working via a command, I just need help getting the object from one script to the other)
        If it is of any importance, I am using CzechHek's Core.lib for all my scripts.

        CzechHekC Offline
        CzechHekC Offline
        CzechHek
        wrote on last edited by CzechHek
        #3

        @allison Since you are already using Core, this should work. I've even fixed more stuff with Reflector to make this easy to do.

        Export.js script:

        ///api_version=2
        (script = registerScript({
        	name: "Export",
        	authors: ["CzechHek"],
        	version: "1.0"
        })).import("Core.lib");
        
        FriendsConfig = Java.type("net.ccbluex.liquidbounce.file.configs.FriendsConfig");
        dir = LiquidBounce.fileManager.dir;
        
        EnemiesConfig = new Reflector(new FriendsConfig(new File(dir, "enemies.json")));
        EnemiesConfig.createConfig();
        EnemiesConfig.loadConfig();
        

        Import.js script

        ///api_version=2
        (script = registerScript({
        	name: "Import",
        	authors: ["CzechHek"],
        	version: "1.0"
        })).import("Core.lib");
        
        module = {
        	onEnable: function () {
        		targetScript = new Reflector(Java.from(scriptManager.scripts).find(function (script) script.scriptName == "Export"));
        		config = targetScript.scriptEngine.get("EnemiesConfig");
        	}
        }
        
        CzechHekC 1 Reply Last reply
        0
        • CzechHekC CzechHek

          @allison Since you are already using Core, this should work. I've even fixed more stuff with Reflector to make this easy to do.

          Export.js script:

          ///api_version=2
          (script = registerScript({
          	name: "Export",
          	authors: ["CzechHek"],
          	version: "1.0"
          })).import("Core.lib");
          
          FriendsConfig = Java.type("net.ccbluex.liquidbounce.file.configs.FriendsConfig");
          dir = LiquidBounce.fileManager.dir;
          
          EnemiesConfig = new Reflector(new FriendsConfig(new File(dir, "enemies.json")));
          EnemiesConfig.createConfig();
          EnemiesConfig.loadConfig();
          

          Import.js script

          ///api_version=2
          (script = registerScript({
          	name: "Import",
          	authors: ["CzechHek"],
          	version: "1.0"
          })).import("Core.lib");
          
          module = {
          	onEnable: function () {
          		targetScript = new Reflector(Java.from(scriptManager.scripts).find(function (script) script.scriptName == "Export"));
          		config = targetScript.scriptEngine.get("EnemiesConfig");
          	}
          }
          
          CzechHekC Offline
          CzechHekC Offline
          CzechHek
          wrote on last edited by
          #4

          @czechhek said in Getting variables/objects from other scripts:

          @allison Since you are already using Core, this should work. I've even fixed more stuff with Reflector to make this easy to do.

          This is now built into Core since 4.11.

          EnemiesConfig = importFromScript("ScriptName", "EnemiesConfig");
          
          I 1 Reply Last reply
          0
          • CzechHekC CzechHek

            @czechhek said in Getting variables/objects from other scripts:

            @allison Since you are already using Core, this should work. I've even fixed more stuff with Reflector to make this easy to do.

            This is now built into Core since 4.11.

            EnemiesConfig = importFromScript("ScriptName", "EnemiesConfig");
            
            I Offline
            I Offline
            idk my name
            wrote on last edited by
            #5

            @czechhek What about trying to get a variable from all available scripts in __noSuchProperty__?

            CzechHekC 1 Reply Last reply
            0
            • I idk my name

              @czechhek What about trying to get a variable from all available scripts in __noSuchProperty__?

              CzechHekC Offline
              CzechHekC Offline
              CzechHek
              wrote on last edited by CzechHek
              #6

              @idk-my-name Wouldn't that be too intrusive and confusing?

              I guess it would be better to do importProperties("scriptname") which would add script to list that no such property uses.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              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