HISE Logo Forum
    • Categories
    • Register
    • Login

    Look and Feel function running into undefined data when pulling from a Global

    Scheduled Pinned Locked Moved Scripting
    1 Posts 1 Posters 105 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.
    • A
      aaronventure
      last edited by aaronventure

      Here's a shortened, trimmed version of what I have. It's scattered across multiple import scripts but this is the order of execution/import.

      const var FONT_SIZE = 20;
      
      const var ControlProperties = {};
      
      // I make controls using a helper function so i can pass a bunch of properties in an object 
      // and query (the existence of) these properties from the ControlProperties later on
      inline function createSlider (param)
      {
      	ControlProperties[param.id] = param; // make input parameters accessible
      	local widget = Content.addKnob(param.id, param.x, param.y);
      
      	// set up the slider, assign properties and do a bunch of stuff
      
      	// once all is done, assign look and feel object and return the reference
      	if (param.lookAndFeelObject) widget.setLocalLookAndFeel(param.lookAndFeelObject);
      
      	return widget;
      }
      
      // set up a look and feel object
      // the function refers to the correct ControlProperties property by pulling obj.id so it can access 
      // the relevant data for each control it's painting
      const var settingsSlider = Content.createLocalLookAndFeel();
      settingsSlider.registerFunction("drawRotarySlider", function(g, obj)
      {
      	var a = obj.area;
      	var p = ControlProperties[obj.id];
      
      	var fontSize = p.fontSize;
      	
      	g.drawAlignedText(obj.text, obj.area, "centred");
      });		
      
      //
      const var volumeSlider = createSlider(
      {
      	"id": "volumeSlider",
      	"text": "Volume Slider",
      	"x": 10,
      	"y": 10,
      	"fontSize": FONT_SIZE,
      	"lookAndFeelObject": settingsSlider,
      });
      
      // 9 more createSlider function calls to make more sliders..
      

      And it works fine, exactly as I want it to. But if we change ControlProperties into a global

      global ControlProperties = {};
      

      all hell breaks loose on the first run only. Everywhere the laf function attempts to get data from ControlProperties, it runs into undefined. So for the very first run (that if you're using globals, since globals reset into "Recompile all" has not yet been implemented, can only be properly simulated by closing and reopening HISE), the interface is all messed up and the console warns of undefined variables in use for every single createSlider call i.e. every attempt to set LLAF object to a control.

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

      41

      Online

      1.7k

      Users

      11.7k

      Topics

      101.8k

      Posts