HISE Logo Forum
    • Categories
    • Register
    • Login

    Trouble passing panel.data through an inline function for mouseCallback

    Scheduled Pinned Locked Moved Scripting
    3 Posts 2 Posters 63 Views
    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.
    • VirtualVirginV
      VirtualVirgin
      last edited by VirtualVirgin

      I am trying to make my panel data drag and drop more modular by making an inline function for the mouseCallback:

      	p.setMouseCallback(function(event)
      	{	
      		altDragAndDrop(this.data.test);
      	});
      
      inline function altDragAndDrop(dataCopy)
      {
      	// show "+" cursor when alt/option is pressed
      	local cursor;
      	event.altDown ? cursor = "CopyingCursor" : cursor = "NormalCursor";
      	this.setMouseCursor(cursor, Colours.white, 1);
      	// alt/option drag copies to clipboard
      	if (event.drag && event.altDown)
      	{
      		Clipboard = dataCopy;
      	}
      	// releasing the mouse on a panel copies the clipboard to the panel, then clears the clipboard
      	if (!event.clicked && event.altDown && dataCopy != Clipboard && Clipboard != undefined)
      	{
      		dataCopy = Clipboard;
      		this.repaint();
      		Clipboard = undefined;
      	}
      };
      

      From the mouseCallback, "this" and "event" and my "Clipboard" are all passing into the inline function properly and can be seen in Console printouts:

      Screenshot 2025-02-03 at 11.57.51 AM.png

      But my problem is that trying to use the this.data.test passed into the inline function from my panels is only half-working.
      It will take that reference and copy the dataCopy (this.data.test) contents (an object) to the Clipboard,
      But then it does not allow me to copy Clipboard contents to the dataCopy (this.data.test).

      Interface:! Line 65, column 12: Cannot assign to this expression!
      

      Screenshot 2025-02-03 at 12.05.40 PM.png

      So a strange thing-
      If I just replace the argument name in (dataCopy) with a direct reference this.data.test in that particular spot, the code now works without any errors,
      but that defeats the basic convenience of having an inline function.

      Screenshot 2025-02-03 at 12.12.01 PM.png

      You can listen to my orchestral mockups here:
      https://www.virtualvirgin.net/

      d.healeyD 1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey @VirtualVirgin
        last edited by d.healey

        @VirtualVirgin Parameters are passed by value, you can't change them within the function.

        Minimal example:

        reg data = 10;
        
        test(data);
        
        inline function test(myParam)
        {
            myParam = 50;
        }
        

        It's the same as writing 10 = 50.

        Libre Wave - Freedom respecting instruments and effects
        My Patreon - HISE tutorials
        YouTube Channel - Public HISE tutorials

        VirtualVirginV 1 Reply Last reply Reply Quote 0
        • VirtualVirginV
          VirtualVirgin @d.healey
          last edited by VirtualVirgin

          @d-healey I thought in this case the parameter is the address for the data "this.data.test" being a path, not the actual data.
          So I was thinking the path variable is static, but it is just rewriting the contents at that path.
          Anyway, I fixed it by using .getValue() and .setValue():

          	p.set("allowCallbacks", "All Callbacks");
          	p.setMouseCallback(function(event)
          	{	
          		altDragAndDrop();
          	});
          
          inline function altDragAndDrop()
          {
          	// show "+" cursor when alt/option is pressed
          	local cursor;
          	event.altDown ? cursor = "CopyingCursor" : cursor = "NormalCursor";
          	this.setMouseCursor(cursor, Colours.white, 1);
          	// alt/option drag copies to clipboard
          	if (event.drag && event.altDown)
          	{
          		Clipboard = this.getValue();
          	}
          	// releasing the mouse on a panel copies the clipboard to the panel, then clears the clipboard
          	if (!event.clicked && event.altDown && this.getValue() != Clipboard && Clipboard != undefined)
          	{
          		this.setValue(Clipboard);
          		this.repaint();
          		Clipboard = undefined;
          	}
          };
          

          You can listen to my orchestral mockups here:
          https://www.virtualvirgin.net/

          1 Reply Last reply Reply Quote 0
          • First post
            Last post

          28

          Online

          1.8k

          Users

          12.1k

          Topics

          105.5k

          Posts