| 4 | |
| 5 | Edit: The problem arises because the 2 variables in the passed statement are ''Local'' to the ''WTF'' function and so are not recognised by the ''_Assert'' function. So the passed string is executed as a literal string and fails. You can see this happening in this example script: |
| 6 | {{{ |
| 7 | #include <MsgBoxConstants.au3> |
| 8 | |
| 9 | Global $sTest1, $sTest2 ; Comment out to see the fail <<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
| 10 | |
| 11 | WTF() ; works, if outside of func |
| 12 | MsgBox(0, Default, "Yep!") |
| 13 | |
| 14 | Func WTF() |
| 15 | Local $MAP[] |
| 16 | $MAP["mod"] = "Mod" |
| 17 | $MAP["more"] = "More actions" |
| 18 | $MAP["delete"] = "Delete" |
| 19 | |
| 20 | For $vKey In MapKeys($MAP) |
| 21 | ConsoleWrite($vKey & " - " & $Map[$vKey] & @CRLF) |
| 22 | Next |
| 23 | |
| 24 | $sTest1 = $MAP["more"] |
| 25 | |
| 26 | For $vKey In MapKeys($MAP) |
| 27 | ConsoleWrite($vKey & " - " & $Map[$vKey] & @CRLF) |
| 28 | Next |
| 29 | ConsoleWrite("$sTest1: " & $sTest1 & @CRLF) |
| 30 | |
| 31 | $sTest2 = $MAP["more"] |
| 32 | |
| 33 | For $vKey In MapKeys($MAP) |
| 34 | ConsoleWrite($vKey & " - " & $Map[$vKey] & @CRLF) |
| 35 | Next |
| 36 | ConsoleWrite("$sTest2: " & $sTest2 & @CRLF) |
| 37 | |
| 38 | ConsoleWrite(@CRLF) |
| 39 | |
| 40 | _Assert_Mod("$sTest1 == $sTest2") |
| 41 | EndFunc |
| 42 | |
| 43 | Func _Assert_Mod($sCondition, $bExit = True, $nCode = 0x7FFFFFFF, $sLine = @ScriptLineNumber, Const $iCurERR = @error, Const $iCurEXT = @extended) |
| 44 | Local $bCondition = Execute($sCondition) |
| 45 | |
| 46 | ConsoleWrite($sCondition & " : " & $bCondition & " - " & Execute($sCondition) & @CRLF) |
| 47 | |
| 48 | If Not $bCondition Then |
| 49 | MsgBox($MB_SYSTEMMODAL, "AutoIt Assert", "Assertion Failed (Line " & $sLine & "): " & @CRLF & @CRLF & $sCondition) |
| 50 | If $bExit Then Exit $nCode |
| 51 | EndIf |
| 52 | Return SetError($iCurERR, $iCurEXT, $bCondition) |
| 53 | EndFunc ;==>_Assert |
| 54 | }}} |
| 55 | As you can see the Map contents are unchanged, but when the passed variables are not ''Global'' in scope the ''_Assert'' function fails. |
| 56 | |
| 57 | The basic problem is that ''Execute'' needs to recognise the variable names in the passed string as variables - and it seems that it only looks in the ''Global'' variable list. So a possible bug, but nothing to do with Maps ''per se'' I suggest that you open a new ticket that covers the failure of ''_Assert'' when passed ''Local'' variables. |
| 58 | |
| 59 | M23 |