Helper Function Logic....Placement?
-
I have a helper function inside of a namespace. Should I be able to call it from anywhere else in the script?
Interface { HelperFunction(); // Does it work here? namespace SomeFunctions { HelperFunction(); // Does it work here? inline function HelperFunction() { // doing something } HelperFunction(); // Does it work here? } }
-
@Chazrox Wouldn't you have to call
SomeFunctions.HelperFunction()
outside the namespace? -
@Chazrox if you're calling it from outside the namespace you need to included the namespace in the call. SomeFunctions.helperFunction()
-
@dannytaurus @d-healey wow. Thanks..testing that now. So just for my understanding, can you do that with any function inside of a function?
-
@Chazrox said in Helper Function Logic....Placement?:
can you do that with any function inside of a function?
Do you mean calling a function from within another function?
-
@d-healey yes. and If the functions you're calling on is in another namespace on an external file. That should work with the method you suggested yes?
-
@Chazrox Yes, doesn't matter if there in an external file or the same file though.
-
@d-healey That just opened my mind to so much. Crucial fact. Thanks guys!
-
@d-healey What if you're inside of a namespace, and you have a function calling to a helper on onInit. Does that need special method?
-
@Chazrox Where is the function call?
-
interface { inline function myHelper() } // Need to do this call } namespace SomeFunctions { inline function SystemFunction() { myHelper(); } } }
-
-
@d-healey aww that was a typo just right here. in my code its proper. what about the structure of the whole thing and the way the code flows? Does it reach my helper on interface script?
Sorry I feel like I wasted your time with that stupid typo.
-
Here's an example
namespace HelperFunctions { inline function doAThing() { Console.print("Hello World"); } doAThing(); } HelperFunctions.doAThing();
-
@d-healey Heres my exact use case...
I have a file drop panel that saves a copy of a midi files to the app data folder.
I just want the combobox to reflect the added items.I tried adding namespace.updateMidiFilesComboBox();
and
just .updateMidiFilesComboBox();
but both give the error that '.updateMidiFilesComboBox' expression is not a function (both ways)
hence me trying to figure out how to jump around namespaces rn...
I've tried calling this function FROM the end of the panel drop function but that gives the same error hence me trying a timer callback.// This is in a namespace const var appDataDir2 = FileSystem.getFolder(FileSystem.AppData); var midiFiles = FileSystem.findFiles(appDataDir2, "*.mid", false); cmbMidiFiles.set("items", ""); inline function updateMidiFilesComboBox() { for (i = 0; i < midiFiles.length; i++) { Console.print(midiFiles[i]); cmbMidiFiles.addItem(midiFiles[i].toString(Filename).replace("/Users/user/Library/Application Support/MANGO WORLD/KEYZIE V29/", "").replace(".mid")); } Console.print("PANEL MIDI MIDI" + trace(pnlMIDIFiles)); } updateMidiFilesComboBox();
//this is in onInit const var midiComboBoxTimer = Engine.createTimerObject(); midiComboBoxTimer.setTimerCallback(function(component, value) { updateMidiFilesComboBox(); }); midiComboBoxTimer.startTimer(200);
-
C Chazrox marked this topic as a question
-
@Chazrox what's the timer for? Show me where you're calling it after the file drop.
-
@d-healey
The timer is just a hacky attempt to see if I can get it to work.Im trying to get my combobox to update after a drop a new file. The combobox searches the appData folder for .mid files and populates the combobox items list.
I want it to happen here somewhere. Someplaces I drop it, it doesnt do anything...in another spot, it duplicates everything in the combobox like 3-4 times and if I keep going it just stacks up.
can you suggest where to put .updateMidiFilesComboBox(); ?
inline function onpnlMIDIFilesFileDrop_B(obj) { //Console.print(trace(obj) + "TRACE TRACE TRACE"); // HOVER STATE local prevHover = this.data.hover ? 1 : 0; this.data.hover = (obj.hover && !obj.drop) ? 1 : 0; if ((this.data.hover ? 1 : 0) != prevHover) { this.repaint(); } // HOVER CHECK if (obj.hover && !obj.drop) { this.data.text = "Drop to load!"; this.data.dropped = false; this.changed(); return; } if (!obj.drop || obj.fileName == undefined) { return; } // PARSE BASE NAME local full = obj.fileName; local slash = Math.max(full.lastIndexOf("/"), full.lastIndexOf("\\")); local dot = full.lastIndexOf("."); //============ Console.print("full contains:" + full); //============= if (dot < 0) { dot = full.length; } local base = full.substring(slash + 1, dot); this.data.filename = base; // paint() this.data.fileName = base; // sync Console.print("BASE__" + base); // HIDE RANGE SLIDER WHILE NO EVENTS RangeSlider.set("visible", 0); // LOAD MIDI PLAYER TRACK 1 MIDIPlayer1.setFile(full, true, true); if (MIDIPlayer1.setTrack != undefined) MIDIPlayer1.setTrack(1); // START POLLING EVENTS midiRangeTimer.stopTimer(); midiRangeTimer.startTimer(50); // ----------------------------------------------------------- // COPY DROPPED FILE INTO AppData // ----------------------------------------------------------- local original = FileSystem.fromAbsolutePath(full); //=========== Console.print("Original contains:" + original); Console.print("Original is defined ==:" + (original != undefined)); Console.print("Original is a file ==:" + (original != undefined)); //=========== local filename = full.substring(slash + 1 ); if (original != undefined) { Console.print(filename + "IS DEFINED"); Console.print("ORIGINAL__" + original); local appDataDir = FileSystem.getFolder(FileSystem.AppData); local newFile = appDataDir.getChildFile(base + ".mid"); original.copy(newFile); newFile.move(appDataDir); Console.print("NEWNEWNEW" + newFile); Console.print("Saved copy to AppData: " + base); } setAnalysisWindowFull(); disableAllChords(); disableAllChords(); // UI flags this.data.text = "Loaded"; this.data.dropped = true; this.data.hover = false; this.changed(); this.repaint(); knbSmartStrength.changed(); pnlCustomMidiPanel.sendRepaintMessage(); pnlCustomMidiRipView.sendRepaintMessage(); Console.print("DROP PANEL B WAS USED"); }
-
@Chazrox said in Helper Function Logic....Placement?:
this.data.filename = base; // paint()
this.data.fileName = base;What's going on here?
@Chazrox said in Helper Function Logic....Placement?:
disableAllChords();
disableAllChords();And here?
I think you need to start by breaking that massive function into smaller more manageable sub functions. It's too chaotic at the moment.
-
-
@d-healey said in Helper Function Logic....Placement?:
What's going on here?
setting panel data for other functions to read like my paint functions.
its a mess in here at the moment. but i'll def clean it up. i've been doing the most trying to fix this but im def making a mess.