Load functions from another script

Hi, I have a lot’s of scripts on-up / on-down / on-login / on-logout and etc,…

I some of them I’m using same functions that I made, Can I put the function in script and call it from those scripts (on-up/on-down and etc…) ?

This is my useful functions, It’s get input and return output… for example:

:local str "NAME1=TEST1;NAME2=TEST2;NAME3=TEST3"
:set str [$setKeyValue string=[:tostr $str] name="NAME2" value="CHANGED"]

The str output will be “NAME1=TEST1;NAME2=CHANGED;NAME3=TEST3”


:local getKeyValue do={
	:if ([:type [:find $string $name]]!="nil") do={
		:local cut [:pick $string ([:find $string $name]+[:len $name]+1) [:len $string]]
		:if ([:len [:find $cut ";"]]>0) do={
			:return [:pick $cut 0 [:find $cut ";"]]
		} else={
			:return [:pick $cut 0 [:len $cut]]
		}
	} else={
		:return ""
	}
}

:local setKeyValue do={
	:if ([:typeof [:find $string $name]]!="nil") do={
		:local current
		:local cut [:pick $string ([:find $string $name]) [:len $string]]
		:if ([:len [:find $cut ";"]]>0) do={
			:set current [:pick $cut 0 [:find $cut ";"]]
		} else={
			:set current [:pick $cut 0 [:len $cut]]
		}
		:return ([:pick $string 0 [:find $string $current]]."$name=$value".[:pick $string ([:find $string $current]+[:len $current]) [:len $string]])
	} else={
		:return ("$name=$value;".$string)
	}
}

Yes, you can :slight_smile:.

  1. Make the getKeyValue and setKeyValue functions :global instead of :local
  2. Run the one script defining all those global functions on startup
  3. In the beginning of your script using the functions put:
    :global getKeyValue;
    :global setKeyValue;

So the globals are in the memory all the time, in each script you just “declare” you’re using the global value, so script knows where to look that variable/function name.

I know that way, I prefer put it in another script and call (load) it from each script that I need it… If there is way to do it…

You prefer to “load” it… where? Isn’t “loading” to /system script environment, to the list of global variables/functions, enough?
That’s what I use - I have an .rsc file with “functions” I just run - and it loads the functions to globals. And other file to remove them. And in the main script I just /import the file, use the functions, and then “clear” them.