CCBlueX Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Unsolved Getting variables/objects from other scripts

    ScriptAPI
    4
    6
    137
    Loading More Posts
    • 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
      allison last edited by

      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.

      CzechHek 1 Reply Last reply Reply Quote 0
      • A
        Aftery last edited by

        This post is deleted!
        1 Reply Last reply Reply Quote 0
        • CzechHek
          CzechHek @allison last edited by 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");
          	}
          }
          
          CzechHek 1 Reply Last reply Reply Quote 0
          • CzechHek
            CzechHek @CzechHek last edited by

            @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 Reply Quote 0
            • I
              idk my name @CzechHek last edited by

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

              CzechHek 1 Reply Last reply Reply Quote 0
              • CzechHek
                CzechHek @idk my name last edited by CzechHek

                @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 Reply Quote 0
                • First post
                  Last post
                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