 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
John B.
Joined: 21 Oct 2006 Posts: 21
|
Posted: Sun Jan 21, 2007 4:32 pm Post subject: Functions cannot contain functions error |
|
|
Hi,
I'm trying to use the Internet Connection Test (http://www.autohotkey.com/forum/viewtopic.php?p=60892#60892). It works fine as long as I use just one function, but when I put in a second function and try to reload, I get the "Functions cannot contain functions" error. I've checked for missing braces (http://www.autohotkey.com/forum/topic8939.html), but they seem to be there. Here is the script:
| Code: | ^!.::
{
loopcount:=4
delay:=4000
URL := "http://www.yahoo.com"
loop, %loopcount%
{
FormatTime, nowtime, , h:mm:ss tt
If ConnectedToInternet()
status:="Online"
else
status:="Offline"
FileAppend, CTI`t%A_MM%/%A_DD%/%A_YYYY%`t%nowtime%`t%status% `n, c:\temp\Internet.txt
If InternetCheckConnection(URL)
status:="Online"
else
status:="Offline"
FileAppend, ICC`t%A_MM%/%A_DD%/%A_YYYY%`t%nowtime%`t%status% `n, c:\temp\Internet.txt
sleep, %delay%
}
ConnectedToInternet(flag=0x40) {
Return DllCall("Wininet.dll\InternetGetConnectedState", "Str", flag,"Int",0)
}
InternetCheckConnection(Url="",FIFC=1) {
Return DllCall("Wininet.dll\InternetCheckConnectionA", Str,Url, Int,FIFC, Int,0)
}
Return
} |
What am I doing wrong?
Thanks,
John B. |
|
| Back to top |
|
 |
Jaytech
Joined: 11 Dec 2006 Posts: 242 Location: Orlando, FL
|
Posted: Sun Jan 21, 2007 4:37 pm Post subject: |
|
|
I edited your script just a bit:
| Code: |
^!.::
loopcount:=4
delay:=4000
URL := "http://www.yahoo.com"
loop, %loopcount%
{
FormatTime, nowtime, , h:mm:ss tt
If ConnectedToInternet()
status:="Online"
else
status:="Offline"
FileAppend, CTI`t%A_MM%/%A_DD%/%A_YYYY%`t%nowtime%`t%status% `n, c:\temp\Internet.txt
If InternetCheckConnection(URL)
status:="Online"
else
status:="Offline"
FileAppend, ICC`t%A_MM%/%A_DD%/%A_YYYY%`t%nowtime%`t%status% `n, c:\temp\Internet.txt
sleep, %delay%
}
RETURN
ConnectedToInternet(flag=0x40) {
Return DllCall("Wininet.dll\InternetGetConnectedState", "Str", flag,"Int",0)
}
InternetCheckConnection(Url="",FIFC=1) {
Return DllCall("Wininet.dll\InternetCheckConnectionA", Str,Url, Int,FIFC, Int,0)
}
|
I just removed the outer brackets and moved the return up to the appropriate position. It does not give me the error code anymore.
Hope this helps
Note: Woot! 100th post  |
|
| Back to top |
|
 |
John B.
Joined: 21 Oct 2006 Posts: 21
|
Posted: Sun Jan 21, 2007 5:20 pm Post subject: |
|
|
Helps!
I see - functions seem to be global to the script, and can't be restricted in a hotkey block.
Thanks,
John B. |
|
| Back to top |
|
 |
Hiro Nakamura Guest
|
Posted: Tue Feb 13, 2007 6:38 pm Post subject: Functions cannot contain functions error |
|
|
I get the same type of error as John B. when reloading the script, but when removing the brackets as Jaytech suggested, then the scripts re-loads fine, but it does not loop, it just runs once and thats it.. How can I solve this?
Thanks,
| Code: |
!c::
Loop, 2
{
Random, rand1, 10000, 99999
Random, rand2, 1000, 9999
Random, rand3, 1, 9
Random, rand4, 1900, 2100
Random, rand5, 10, 59
Random, rand6, 10, 28
Random, rand7, 10, 18
var1=1
Add1(x,y)
{
return x + y
}
var5 := Add1(var1,rand5)
var2=1
Add2(x,y)
{
return x + y
}
var7 :=Add2(var2,rand7)
Send BEGIN:VCALENDAR`n
Send VERSION:1.0`n
Send BEGIN:VEVENT`n
Send UID:57a%rand1%-18fd-%rand2%-835b-bdbfecdc0e0c`n
Send SUMMARY:Quantum Physics Of Nature`n
Send DESCRIPTION:NATO ADVANCED STUDY INSTITUTE CARBON NANOTUBES: FROM`n
Send BASIC RESEARCH TO NANOTECHNOLOGY`n
Send DTSTART:%rand4%0%rand3%%rand6%T%rand7%%rand5%00Z`n
Send DTEND:%rand4%0%rand3%%rand6%T%var7%%var5%00Z`n
Send X-EPOCAGENDAENTRYTYPE:APPOINTMENT`n
Send CLASS:PUBLIC`n
Send LOCATION:Tejas 106A`n
Send SEQUENCE:0`n
Send X-METHOD:NONE`n
Send LAST-MODIFIED:20060612T125310Z`n
Send PRIORITY:0`n
Send STATUS:CONFIRMED`n
Send X-SYMBIAN-LUID:2`n
Send END:VEVENT`n
Send END:VCALENDAR`n
}
return
|
|
|
| Back to top |
|
 |
tonne
Joined: 06 Jun 2006 Posts: 1651 Location: Denmark
|
Posted: Tue Feb 13, 2007 9:24 pm Post subject: |
|
|
Why the functions?
| Quote: | Add1(x,y)
{
return x + y
}
var5 := Add1(var1,rand5) |
What's the benefit over:
| Code: | | var5 := var1 + rand5 |
If you really need the function one declaration should be enough and it can be placed before or after the loop. _________________ RegEx Powered Dynamic Hotstrings
COM
AutoHotkey 2 |
|
| Back to top |
|
 |
Hiro Nakamura Guest
|
Posted: Wed Feb 14, 2007 12:00 pm Post subject: |
|
|
Thanks a bunch Tonne ! The reason why is close aligned with my programming skills, which are not far from zero. That was the solution I found when I tried, use one random number and then add 1 into another stored value. I guess there is minit to get hooked on AHK and a lifetime to master.... |
|
| 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
|