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 

Functions cannot contain functions error

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
John B.



Joined: 21 Oct 2006
Posts: 21

PostPosted: Sun Jan 21, 2007 4:32 pm    Post subject: Functions cannot contain functions error Reply with quote

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



Joined: 11 Dec 2006
Posts: 242
Location: Orlando, FL

PostPosted: Sun Jan 21, 2007 4:37 pm    Post subject: Reply with quote

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 Smile

Note: Woot! 100th post Very Happy
Back to top
View user's profile Send private message
John B.



Joined: 21 Oct 2006
Posts: 21

PostPosted: Sun Jan 21, 2007 5:20 pm    Post subject: Reply with quote

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





PostPosted: Tue Feb 13, 2007 6:38 pm    Post subject: Functions cannot contain functions error Reply with quote

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

PostPosted: Tue Feb 13, 2007 9:24 pm    Post subject: Reply with quote

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





PostPosted: Wed Feb 14, 2007 12:00 pm    Post subject: Reply with quote

Thanks a bunch Tonne Very Happy ! 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
Display posts from previous:   
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