gcue Posted November 25, 2016 Posted November 25, 2016 (edited) hello. i am trying to exit a function and return a value to another function. Test is not a working function. There are several components to make it working that would take me time to put together. Hopefully there is enough to illustrate the issue. Issue: I can always get $recipient to output correctly in consolewrite, but i don't always get it back to Test() where i am calling it from. I think Return isn't exiting the GetRecipient function as expected. I have a bunch of IF statements and several instances where GetRecipient gets called multiple times (when i cant get a recipient) so i think that's where the issue lies any help is greatly appreciated! expandcollapse popupFunc Test() $sender = "bob" $recipient = GetRecipient($sender) consolewrite($recipient & @crlf) endfunc Func GetRecipient($sender) $recipient_found = False ConsoleWrite(@CRLF & @CRLF & "sender:" & $sender & @CRLF) $record = GetRandom($master_array) $recipient = $master_array[$record][0] ConsoleWrite("recipient:" & $recipient & @CRLF) If $sender <> $recipient Then ConsoleWrite("sender not same as recipeint" & @CRLF) $block = $master_array[$record][3] If $block = "" Then $recipient_found = True ConsoleWrite("0 unassigned recipeint found! " & $recipient & @CRLF) ;;;;RECIPIENT IS OUTPUT CORRECTLY IN CONSOLEWRITE BUT NOT ALWAYS RETURNED $master_array[$record][5] = "ASSIGNED" Return $recipient EndIf $block_array = StringSplit($block, ",") If @error Then ConsoleWrite("only 1 blocked for recipient" & @CRLF) If $sender = $block Then GetRecipient($sender) Else If $master_array[$record][5] = "ASSIGNED" Then ConsoleWrite("recipeint already assigned" & @CRLF) GetRecipient($sender) Else $recipient_found = True ConsoleWrite("1 unassigned recipeint found! " & $recipient & @CRLF);;;;RECIPIENT IS OUTPUT CORRECTLY IN CONSOLEWRITE BUT NOT ALWAYS RETURNED $master_array[$record][5] = "ASSIGNED" ;~ Debug($master_array) Return $recipient EndIf EndIf Else _ArraySearch($block_array, $sender) If Not @error Then ConsoleWrite("recipeint found in block array" & @CRLF) GetRecipient($sender) Else ConsoleWrite("recipeint not found in block array" & @CRLF) If $master_array[$record][5] = "ASSIGNED" Then ConsoleWrite("recipeint already assigned" & @CRLF) GetRecipient($sender) Else $recipient_found = True ConsoleWrite("2 unassigned recipeint found! " & $recipient & @CRLF);;;;RECIPIENT IS OUTPUT CORRECTLY IN CONSOLEWRITE BUT NOT ALWAYS RETURNED $master_array[$record][5] = "ASSIGNED" ;~ Debug($master_array) Return $recipient EndIf EndIf EndIf Else ConsoleWrite("sender same as recipeint" & @CRLF) GetRecipient($sender) EndIf Consolewrite("ERROR" & @crlf);sometimes the script gets to this point which i have no idea why EndFunc ;==>GetRecipient Edited November 25, 2016 by gcue
gcue Posted November 25, 2016 Author Posted November 25, 2016 (edited) ok here's a working sample (wasnt as hard as i thought it would be )-- line 113 outputs $sender and $recipient. sometimes i do not get $recipient, even though $recipient was in the consolewrite just before the Return expandcollapse popup#include <array.au3> $msg_normal = 0 Global $array[4][3] Test() Func GetRandom($array) $record = Random(0, UBound($array) - 1, 1) Return $record EndFunc ;==>GetRandom Func GetRecipient($sender) $recipient_found = False ConsoleWrite(@CRLF & @CRLF & "sender:" & $sender & @CRLF) $record = GetRandom($array) $recipient = $array[$record][0] ConsoleWrite("recipient:" & $recipient & @CRLF) If $sender <> $recipient Then ConsoleWrite("sender not same as recipeint" & @CRLF) $block = $array[$record][1] If $block = "" Then $recipient_found = True ConsoleWrite("0 unassigned recipeint found! " & $recipient & @CRLF) $array[$record][2] = "ASSIGNED" Return $recipient EndIf $block_array = StringSplit($block, ",") If @error Then ConsoleWrite("only 1 blocked for recipient" & @CRLF) If $sender = $block Then GetRecipient($sender) Else If $array[$record][2] = "ASSIGNED" Then ConsoleWrite("recipeint already assigned" & @CRLF) GetRecipient($sender) Else $recipient_found = True ConsoleWrite("1 unassigned recipeint found! " & $recipient & @CRLF) $array[$record][2] = "ASSIGNED" ;~ Debug($array) Return $recipient EndIf EndIf Else _ArraySearch($block_array, $sender) If Not @error Then ConsoleWrite("recipeint found in block array" & @CRLF) GetRecipient($sender) Else ConsoleWrite("recipeint not found in block array" & @CRLF) If $array[$record][2] = "ASSIGNED" Then ConsoleWrite("recipeint already assigned" & @CRLF) GetRecipient($sender) Else $recipient_found = True ConsoleWrite("2 unassigned recipeint found! " & $recipient & @CRLF) $array[$record][2] = "ASSIGNED" ;~ Debug($array) Return $recipient EndIf EndIf EndIf Else ConsoleWrite("sender same as recipeint" & @CRLF) GetRecipient($sender) EndIf EndFunc ;==>GetRecipient Func Array() ;0 - name ;1 - block list ;2 - assigned or not $array[0][0] = "bob" $array[0][1] = "mary,beth" $array[1][0] = "mary" $array[1][1] = "tom" $array[2][0] = "beth" $array[2][1] = "" $array[3][0] = "tom" $array[3][1] = "" Return $array EndFunc ;==>Array Func Test() ;~ local $final_array[1][1] $array = Array() For $x = 0 To UBound($array) - 1 $sender = $array[$x][0] $recipient = GetRecipient($sender) Debug($sender, $recipient) Next EndFunc ;==>Test Func Debug($variable1 = "", $variable2 = "", $variable3 = "", $variable4 = "", $variable5 = "") If IsArray($variable1) Or IsArray($variable2) Then If IsArray($variable1) Then _ArrayDisplay($variable1, $variable2) If IsArray($variable2) Then _ArrayDisplay($variable2, $variable1) Else $variable = "" If $variable1 <> "" Then $variable &= $variable1 & ": " & Execute($variable1) & @CRLF If $variable2 <> "" Then $variable &= $variable2 & ": " & Execute($variable2) & @CRLF If $variable3 <> "" Then $variable &= $variable3 & ": " & Execute($variable3) & @CRLF If $variable4 <> "" Then $variable &= $variable4 & ": " & Execute($variable4) & @CRLF If $variable5 <> "" Then $variable &= $variable5 & ": " & Execute($variable5) & @CRLF $variable = StringStripWS($variable, 2) ClipPut($variable) MsgBox($msg_normal, "Debug", $variable) EndIf EndFunc ;==>Debug Edited November 25, 2016 by gcue
Moderators Melba23 Posted November 25, 2016 Moderators Posted November 25, 2016 gcue, That script is full of horrible recursive calls which are undoubtedly the root of your problem - and which mean I am not even prepared to examine the script in detail. How about explaining what you want to do so that we can provide a better solution. M23 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
gcue Posted November 25, 2016 Author Posted November 25, 2016 LOL thanks Melba i am trying to do a secret santa utility. where i have a list of people in array array[0][0]= name array[0][1]=email array[0][2]=block list (used so person A doesnt get their kid or spouse) array[0][3]=assigned or not so i want to through the list and assign a recipient for every person from the same list (someone cant get themselves or someone from their block list) hope that makes sense thank you in advance!
Moderators Melba23 Posted November 25, 2016 Moderators Posted November 25, 2016 gcue, Sounds like a fun project. I am visiting the in-laws next week and need a distraction - can you wait that long? M23 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
gcue Posted November 25, 2016 Author Posted November 25, 2016 yea its fun.. actually i was supposd to have it done by yesterday sigh so trying to scramble now would it be easier to fix my horrible recursive one? haha
gcue Posted November 25, 2016 Author Posted November 25, 2016 my family wanted to do their shopping today (black friday) so ya thats why im late :-/
Moderators Melba23 Posted November 25, 2016 Moderators Posted November 25, 2016 gcue, Quote would it be easier to fix my horrible recursive one? Certainly not!!!!!! Already working on the problem - but do not hold your breath. M23 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
Moderators Melba23 Posted November 26, 2016 Moderators Posted November 26, 2016 gcue, Here you go: expandcollapse popup#include <Array.au3> Global $aDonor[][] = [["Index", "Name", "Family", "Email", "Recipient"], _ [1, "Tom", 1, "", ""], _ [2, "Dick", 1, "", ""], _ [3, "Harry", 1, "", ""], _ [4, "Peter", 2, "", ""], _ [5, "Paul", 2, "", ""], _ [6, "Mary", 2, "", ""], _ [7, "Steve", 3, "", ""], _ [8, "Dave", 4, "", ""], _ [9, "Jane", 5, "", ""], _ [10, "Anne", 6, "", ""]] $aRecip = $aDonor _ArrayShuffle($aRecip, 1) ;_ArrayDisplay($aRecip, "", Default, 8) For $iDonor = 1 To UBound($aDonor) - 1 ConsoleWrite("Checking " & $aDonor[$iDonor][1] & @CRLF) For $iRecip = 1 To UBound($aRecip) - 1 ConsoleWrite(@TAB & "Against : " & $aRecip[$iRecip][1] & @CRLF) If $aRecip[$iRecip][0] <> $iDonor Then If $aRecip[$iRecip][2] <> "" And $aRecip[$iRecip][2] <> $aDonor[$iDonor][2] Then If $aRecip[$iRecip][4] = "" Then ConsoleWrite(@TAB & @TAB & "Valid recip" & @CRLF) $aRecip[$iRecip][4] = 1 $aDonor[$iDonor][4] = $aRecip[$iRecip][1] ExitLoop Else ConsoleWrite(@TAB & @TAB & "Already set" & @CRLF) EndIf Else ConsoleWrite(@TAB & @TAB & "Same family" & @CRLF) EndIf Else ConsoleWrite(@TAB & @TAB & "Same person" & @CRLF) EndIf Next Next _ArrayDisplay($aDonor, "", Default, 8) Just make sure members of the same family get the same family number so they are blocked from each other's choices of recipient. You can comment out the ConsoleWrite lines when you are happy it works - let me know if it does not and post the array you used. M23 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
gcue Posted November 26, 2016 Author Posted November 26, 2016 awesome thank youuuu! ill try it and let you know
gcue Posted November 26, 2016 Author Posted November 26, 2016 works beautifully!!!! thank youuuuuuuuu very much!! hope you and your family enjoy the holidays
Moderators Melba23 Posted November 26, 2016 Moderators Posted November 26, 2016 gcue, Glad I could help - it was a fun little problem. M23 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
spudw2k Posted November 28, 2016 Posted November 28, 2016 Not exactly sure how the stars aligned in my testrun, but the last donor didn't have a recipient (which would've been themself by elimination--so I suspect that's why.) Just wanted to mention the condition; it did not replicate on subsequent trials...but could at some point. Perhaps you could remove the donor from the recipient list first? Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
Jfish Posted November 28, 2016 Posted November 28, 2016 FYI only ... wrote this a couple years back ... I ran into the issue where you could get yourself ... not always but sometimes so I reshuffled at that point. Not suggesting it is great code but showing it just in case you find it helpful. Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt
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