 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Yxel Guest
|
Posted: Sun Jun 15, 2008 7:45 pm Post subject: Make all variables that start with KITTEN blank? |
|
|
I am using AHK to create object so to speak. Like we have the object kitten. Kitten is described by the variables:
| Code: |
kitten_color
kitten_fur
kitten_weight
kitten_paws
...
...
(and so on)
|
Can I reset all of these variables in some clever way without having to list aaall of them.
Something like this would be great!
| Code: |
Varables("kitten", "") ;varables containing kitten are set to ""
|
Has anyone made a function for this? I would have tremendous use of this! |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 1145 Location: The Interwebs
|
Posted: Sun Jun 15, 2008 10:24 pm Post subject: |
|
|
| use InStr() to find if the first letters of the variable are kitten, then if they are, set the variable to be blank |
|
| Back to top |
|
 |
Yxel Guest
|
Posted: Sun Jun 15, 2008 11:15 pm Post subject: |
|
|
| Krogdor wrote: | | use InStr() to find if the first letters of the variable are kitten, then if they are, set the variable to be blank |
Can I loop all variables some way without knowing all of their names?
e.g.
| Code: |
Loop, % ALL_VARIABLES
{
if (InStr(A_Variable, "Kitten"))
{
A_Variable := ""
}
}
|
I hope that is possible. If it isn't then I don't know how to do what you suggest without having to find out and list the names of all variables active in the script. Is it possible to retrieve a list of ALL_VARIABLES? |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6264
|
Posted: Sun Jun 15, 2008 11:20 pm Post subject: |
|
|
| Yxel wrote: | | Is it possible to retrieve a list of ALL_VARIABLES? |
_________________
 |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 1145 Location: The Interwebs
|
Posted: Mon Jun 16, 2008 3:35 am Post subject: |
|
|
| Code: | allvariables:=GetAHKStats("variables")
Loop, Parse, allvariables, `n
If (InStr(A_LoopField,"kitten")=1)
{
variablename:=SubStr(A_LoopField,1,Instr(A_LoopField,"[")-1)
%variablename%:=""
}
return
GetAhkStats(Section="") {
DetectHiddenWindows, On
IfEqual Section,, SetEnv Section, Key
HidWin := WinExist(A_ScriptFullPath " - AutoHotkey v")
OldPar := DllCall("GetParent", UInt,HidWin)
GUI +LastFound
DllCall("SetParent", UInt,HidWin, UInt,WinExist("ahk_class Shell_TrayWnd"))
WinMenuSelectItem ahk_id %HidWin%,,View, %Section%
Sleep 0
ControlGetText Out1, Edit1, ahk_id %HidWin%
WinHide ahk_id %HidWin%
DllCall("SetParent", UInt,HidWin, UInt,OldPar)
Return Out1
} |
|
|
| Back to top |
|
 |
pokercurious
Joined: 16 Dec 2007 Posts: 47
|
Posted: Mon Jun 16, 2008 6:10 pm Post subject: |
|
|
This was what I came up with a while ago - pretty close to krogdor's solution.
| Code: | ; Usage:
; ClearArray("kitten_")
ClearArray(prefix)
{
global
lgv := ListGlobalVars()
Loop, parse, lgv, |
{
If (InStr(A_LoopField, prefix) = 1)
%A_LoopField% =
}
}
;==================+
; ListGlobalVars() |
; by Lexikos +====================================+
; http://www.autohotkey.com/forum/viewtopic.php?t=22692 |
;==============================================================================
ListGlobalVars()
{
static hwnd, hwndEdit, pSFW, pSW, bkpSFW, bkpSW
if !hwndEdit
{
dhw := A_DetectHiddenWindows
DetectHiddenWindows, On
Process, Exist
hwnd := WinExist("ahk_class AutoHotkey ahk_pid " ErrorLevel)
ControlGet, hwndEdit, Hwnd,, Edit1
DetectHiddenWindows, %dhw%
hmod := DllCall("GetModuleHandle", "str", "user32.dll")
pSFW := DllCall("GetProcAddress", "uint", hmod, "str", "SetForegroundWindow")
pSW := DllCall("GetProcAddress", "uint", hmod, "str", "ShowWindow")
DllCall("VirtualProtect", "uint", pSFW, "uint", 8, "uint", 0x40, "uint*", 0)
DllCall("VirtualProtect", "uint", pSW, "uint", 8, "uint", 0x40, "uint*", 0)
bkpSFW := NumGet(pSFW+0, 0, "int64")
bkpSW := NumGet(pSW+0, 0, "int64")
}
NumPut(0x0004C200000001B8, pSFW+0, 0, "int64") ; return TRUE
, NumPut(0x0008C200000001B8, pSW+0, 0, "int64") ; return TRUE
, DllCall("SendMessage", "uint", hwnd, "uint", 0x111, "uint", 65407, "uint", 0)
, NumPut(bkpSFW, pSFW+0, 0, "int64")
, NumPut(bkpSW, pSW+0, 0, "int64")
ControlGetText, text,, ahk_id %hwndEdit%
RegExMatch(text, "sm)(?<=^Global Variables \(alphabetical\)`r`n-{50}`r`n).*", text)
pos = 1
Loop {
pos := RegExMatch(text, "m)^[\w#@$?\[\]]+(?=\[\d+ of \d+\]: )", var, pos)
if ! pos
break
list .= var "|"
pos += StrLen(var)
}
return SubStr(list, 1, -1)
}
;==============================================================================
|
Last edited by pokercurious on Mon Jun 16, 2008 6:11 pm; edited 1 time in total |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6847 Location: Pacific Northwest, US
|
Posted: Mon Jun 16, 2008 6:10 pm Post subject: |
|
|
for Krogdor's code, and maybe the other one, keep in mind that the listvars window only shows as many variables as it has memory for. I think it stops around 10000 variables or so. _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|