Damein Posted April 25, 2011 Share Posted April 25, 2011 I thought it was just simple, you create a script with a function and etc. and then you create another script that calls on that function and you get the information back. For example: TestUDF.au3 Func _Test1() $Var = "String" $VarStripped = StringTrimLeft($Var, 1) EndFunc TestingUDF.au3 #include <TestUDF.au3> HotKeySet("{1}", "_TestRun") Func _TestRun() _Test1() MsgBox(0, "Test", $VarStripped) EndFunc But obviously not. I was just wondering on the proper way of making a UDF, but I could not find any documentation on it. Most recent sig. I made Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic Link to comment Share on other sites More sharing options...
GEOSoft Posted April 25, 2011 Share Posted April 25, 2011 That's the right principal but in all liklihood the call is incorrect.First a UDF should have the Line#Include-Onceat the top of it so you don't inadvertantly include it in another UDF and then call both.Secondly, read the help file about #include. Calling it with <filename.au3> makes AutoIt look in AutoIt's include folder. You probably wanted to call it with a specific path so it should have been#include "path\filename.au3"That is a generalization because there is a registry hack that will tell AutoIt to also look in other specific folders when using the <> method. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 25, 2011 Moderators Share Posted April 25, 2011 Damein,You need to declare $VarStripped as a Global variable so that all the functions in your script can see it. At the moment the 2 functions each see only their Local versions of the variable which is destroyed when the function ends. Your current script showing why it does not work:; #include <TestUDF.au3> ; This is expanded so AutoIt sees the following lines Func _Test1() $Var = "String" ; This variable only exists within this function $VarStripped = StringTrimLeft($Var, 1) ; As does this one - they are both destroyed when the function exits EndFunc HotKeySet("{1}", "_TestRun") Func _TestRun() _Test1() MsgBox(0, "Test", $VarStripped) ; This variable again only exists within this function EndFuncI even get an error if I try to run this code telling me that the $VarStripped variable in the MsgBox line is undeclared. You just need to add Global $VarStripped at the top of your script so that all your functions can see the variable. Take a look at the Variables - using Global, Local and ByRef tutorial in the Wiki for a more detailed explanation of Global and Local. M23P.S. You do not need the {} in your HotKey declaration either! Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Bowmore Posted April 25, 2011 Share Posted April 25, 2011 (edited) For your example a better way would be. TestUdf.au3 #include-once Func _Test1($var) $VarStripped = StringTrimLeft($Var, 1) Return $VarStripped EndFunc Used like this #include <TestUDF.au3> HotKeySet("{1}", "_TestRun") While 1 WEnd Func _TestRun() $var = "String" $VarStripped =_Test1($var) MsgBox(0, "Test", $VarStripped) EndFunc or alternatively like this #include <TestUDF.au3> HotKeySet("{1}", "_TestRun") While 1 WEnd Func _TestRun() MsgBox(0, "Test", _Test1("String")) EndFunc Edit: Fixed AutoIt tags Edited April 26, 2011 by Bowmore "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now