AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Make all variables that start with KITTEN blank?

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Yxel
Guest





PostPosted: Sun Jun 15, 2008 7:45 pm    Post subject: Make all variables that start with KITTEN blank? Reply with quote

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

PostPosted: Sun Jun 15, 2008 10:24 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
Yxel
Guest





PostPosted: Sun Jun 15, 2008 11:15 pm    Post subject: Reply with quote

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

PostPosted: Sun Jun 15, 2008 11:20 pm    Post subject: Reply with quote

Yxel wrote:
Is it possible to retrieve a list of ALL_VARIABLES?



_________________
Back to top
View user's profile Send private message
Krogdor



Joined: 18 Apr 2008
Posts: 1145
Location: The Interwebs

PostPosted: Mon Jun 16, 2008 3:35 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
pokercurious



Joined: 16 Dec 2007
Posts: 47

PostPosted: Mon Jun 16, 2008 6:10 pm    Post subject: Reply with quote

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
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6847
Location: Pacific Northwest, US

PostPosted: Mon Jun 16, 2008 6:10 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group