-
mrvette134
- Posts: 4
- Joined: 15 May 2020, 00:20
Error: Unexpected «{«
Just started using AutoHotkey 2 days ago, already expected with the endless possibilities.
Sscreen shot of error attached.
Problem is in 2 parts, when I assigned a list of entries to be placed when I press F9 1) it sends it so fast that i need to slow it down, 2) and now i try to run the script and I get a pop-up error «Error: Unepcted «{«
Code: Select all
; ---- Admin Hot Keys
; DO NOT send commands too fast, Sleep 1-2 sec between each command
; ---------------------------------------------------------
F2::Send,{Enter} /tp -1600 70 1800{Enter}{Esc} ;Union Base behind hills
F3::Send,{Enter} /tp -1325 85 1200{Enter}{Esc} ;Union Apt # 1 Roof
F4::Send,{Enter} /tp 1927 70 1045{Enter}{Esc} ;Sage Roof
F5::Send,{Enter} /tp 3276 -5 -789{Enter}{Esc} ;Adders Tower
F6::Send,{Enter} /tp 2707 -40 -3063{Enter}{Esc} ;Blackrock Roof
F7::Send,{Enter} /tp -1605 -20 -2393{Enter}{Esc};Old Town Roof
F8::Send,{Enter} ; Car Parts
/give 2522 4{Enter} ;Spark plugs
Sleep, 1000
/give 2569 {Enter} ;Small Carb
Sleep, 1000
/give 2579{Enter} ;Long Oil Filter
Sleep, 1000
/give 2578{Enter} ;Short Oil Filter
Sleep, 1000
/give 2513{Enter} ;Fan Belt
Sleep, 1000
/give 2501{Enter} ;Alternator
Sleep, 1000
/give 2571{Enter}{Esc} ;Jerry Can
F9::Send,{Enter}; Generator Kit
Send, /give 4001 0{Enter};Generator
Send, /give 2569{Enter};Small Carburator
Send, /give 2522 4{Enter};Spark Plugs
Send, /give 2570 0{Enter};Pull Start
Send, /give 2532 0{Enter};Ext Cord
Send, /give 2506 10{Enter};Circuit Breakers
Send, /give 2571 0{Enter};Jerry Can
return
[Mod edit: [code][/code] tags added]
I’ve Googled, looked at the AHK help files, and now hoping for assistance here.
Keith
-
Attachments
-
- Error Unexpected curly bracket.png (15.74 KiB) Viewed 782 times
-
Rohwedder
- Posts: 6454
- Joined: 04 Jun 2014, 08:33
- Location: Germany
Re: Error: Unexpected «{«
15 May 2020, 01:01
Hallo,
instead of:
Code: Select all
F8::Send,{Enter} ; Car Parts
/give 2522 4{Enter} ;Spark plugs
Sleep, 1000
/give 2569 {Enter} ;Small Carb
Sleep, 1000
/give 2579{Enter} ;Long Oil Filter
Sleep, 1000
/give 2578{Enter} ;Short Oil Filter
Sleep, 1000
/give 2513{Enter} ;Fan Belt
Sleep, 1000
/give 2501{Enter} ;Alternator
Sleep, 1000
/give 2571{Enter}{Esc} ;Jerry Can
use:
Code: Select all
F8::Send,{Enter} ; Car Parts
Send, /give 2522 4{Enter} ;Spark plugs
Sleep, 1000
Send, /give 2569 {Enter} ;Small Carb
Sleep, 1000
Send, /give 2579{Enter} ;Long Oil Filter
Sleep, 1000
Send, /give 2578{Enter} ;Short Oil Filter
Sleep, 1000
Send, /give 2513{Enter} ;Fan Belt
Sleep, 1000
Send, /give 2501{Enter} ;Alternator
Sleep, 1000
Send, /give 2571{Enter}{Esc} ;Jerry Can
Return ; you need this Return!
-
Helgef
- Posts: 4693
- Joined: 17 Jul 2016, 01:02
-
Contact:
Re: Error: Unexpected «{«
15 May 2020, 01:21
Your code is written for ahk v1.
In v2 you need to quote text and remove initial commas, eg,
Cheers.
-
Rohwedder
- Posts: 6454
- Joined: 04 Jun 2014, 08:33
- Location: Germany
Re: Error: Unexpected «{«
15 May 2020, 01:35
I believe,
Just started using AutoHotkey 2 days ago
means:
Just started using AutoHotkey (2 days) ago
-
Helgef
- Posts: 4693
- Joined: 17 Jul 2016, 01:02
-
Contact:
Re: Error: Unexpected «{«
15 May 2020, 02:16
Hehe, I see, it is supposed to be …two days ago then.
Thanks for your continued support @Rohwedder .
Cheers.
-
mrvette134
- Posts: 4
- Joined: 15 May 2020, 00:20
Re: Error: Unexpected «{«
15 May 2020, 16:13
Hi guys,
FYI: AutoHotkey_1.1.32.00 (sorry if i confused it with AutoHotkey ver 2.
Thanks for the tip, i was not clearly seeing how i was writing both F8 & F9 different with the «Send, /give»
And, I’ve learned i have to put a space between {Enter} ,but before ;Spark plugs, or it included the comment in the output.
As of now, when I Save and Run, press F8 or F9, and I get is 1 carriage return ???
Current Code:
F8::Send,{Enter} ;Car Parts
Send, /give 2522 4 {Enter} ;Spark plugs
Send, /give 2569 0 {Enter} ;Small Carburetor
Send, /give 2579 0 {Enter} ;Long Oil Filter
Send, /give 2578 0 {Enter} ;Short Oil Filter
Send, /give 2513 0 {Enter} ;Fan Belt
Send, /give 2501 0 {Enter} ;Alternator
Send, /give 2571 0 {Enter}{Esc} ;Jerry Can
return
F9::Send,{Enter} ;Generator Kit
Send, /give 4001 {Enter} ;Generator
Send, /give 2569 {Enter} ;Small Carburetor
Send, /give 2522 {Enter} ;Spark Plugs
Send, /give 2570 {Enter} ;Pull Start
Send, /give 2532 {Enter} ;Ext Cord
Send, /give 2506 10{Enter} ;Circuit Breakers
Send, /give 2571 {Enter} ;Jerry Can
return
-
swagfag
- Posts: 5799
- Joined: 11 Jan 2017, 17:59
Re: Error: Unexpected «{«
15 May 2020, 16:17
should be
Code: Select all
F8::
Send,{Enter} ;Car Parts
Send, /give 2522 4 {Enter} ;Spark plugs
Send, /give 2569 0 {Enter} ;Small Carburetor
Send, /give 2579 0 {Enter} ;Long Oil Filter
Send, /give 2578 0 {Enter} ;Short Oil Filter
Send, /give 2513 0 {Enter} ;Fan Belt
Send, /give 2501 0 {Enter} ;Alternator
Send, /give 2571 0 {Enter}{Esc} ;Jerry Can
return
otherwise «the return is implicit»
-
mrvette134
- Posts: 4
- Joined: 15 May 2020, 00:20
Re: Error: Unexpected «{«
15 May 2020, 17:39
Hi Swag,
That got it to work. You’re a big help and thank you.
May i ask, as i tried using pause, to slow down the keystrokes or add a 1 sec pause between commands. It goes so fast, some of it gets skipped.
I was unaware that the indention of the lines between F8 to Return was a thing. I appreciate you pointing that out. Lesson learned.
WORKS (minus going so fast it skips a line or two)
F8::
Send,{Enter} ;Car Parts
Send, /give 2522 4 {Enter} ;Spark plugs
Send, /give 2569 1 {Enter} ;Small Carburetor
Send, /give 2579 1 {Enter} ;Long Oil Filter
Send, /give 2578 1 {Enter} ;Short Oil Filter
Send, /give 2513 1 {Enter} ;Fan Belt
Send, /give 2501 1 {Enter} ;Alternator
Send, /give 2571 1 {Enter}{Esc} ;Jerry Can
return
-
boiler
- Posts: 13611
- Joined: 21 Dec 2014, 02:44
Re: Error: Unexpected «{«
15 May 2020, 18:41
Pause is not the command that causes it to wait for a certain period of time. That command is Sleep. The amount it waits is specified in msec, so a value of 1000 will cause it to wait for 1 second. If you want that amount of delay between your Send commands, it would be like this:
Code: Select all
F8::
Send,{Enter} ;Car Parts
Send, /give 2522 4 {Enter} ;Spark plugs
Sleep, 1000
Send, /give 2569 0 {Enter} ;Small Carburetor
Sleep, 1000
Send, /give 2579 0 {Enter} ;Long Oil Filter
Sleep, 1000
Send, /give 2578 0 {Enter} ;Short Oil Filter
Sleep, 1000
Send, /give 2513 0 {Enter} ;Fan Belt
Sleep, 1000
Send, /give 2501 0 {Enter} ;Alternator
Sleep, 1000
Send, /give 2571 0 {Enter}{Esc} ;Jerry Can
return
If you want to slow down how fast the individual characters are sent within a Send command, use SetKeyDelay. The default is 10 ms, so if you want to have the characters «typed» at about half the speed, you could put the line SetKeyDelay, 20 at the top of your script.
By the way, the indenting doesn’t affect the execution of the code, but it is good practice to do so because it visually groups the F8 hotkey subroutine’s commands (it becomes more helpful when working with larger scripts).
Regarding the space before the {Enter}, it doesn’t seem that it would be necessary. You might want to try it without to confirm that even though it doesn’t seem to hurt in this case.
-
mrvette134
- Posts: 4
- Joined: 15 May 2020, 00:20
Re: Error: Unexpected «{«
16 May 2020, 00:16
Praise everyone for their input. Everything is working and the sleep,20 helped. Also, i appreciate you guys explaining how the code works. I stumbled across this software and even with the YouTube tutorial i was left in the dark.
Thanks again and I am looking forward to learning more.
Return to “Ask for Help”
Who is online
Users browsing this forum: Bing [Bot], Google [Bot], noswall and 102 guests
I created a script to manage some raspberry pi units I have. It’s saying that the closing bracket near the end of the code for the loop isn’t correct. I’m not sure what to change it seems like an error. Specifically it’s the closing bracket after » octopicounter++» is incorrect.
I’m using the most current version of autohotkey
Can someone help me understand what’s wrong with this?
capslock & j::
InputBox,octopiinput,Select Octoprint Instance(1-3), Select Octoprint Instance(1-3),
octopicounter=0
loop, 4
{
run "C:Program Files (x86)GoogleChromeApplicationchrome.exe"
sleep 300
if octopicounter=0
{
sleep 100
if octopiinput=3
{
run, C:Program Files (x86)GoogleChromeApplicationchrome.exe http://192.168.1.14
;sendinput, ^lhttp://192.168.2.167{enter}
}
else if octopiinput=2
{
;sendinput, ^lhttp://192.168.1.13/{enter}
run, C:Program Files (x86)GoogleChromeApplicationchrome.exe http://192.168.1.13
}
else if octopiinput=1
{
run C:Program Files (x86)GoogleChromeApplicationchrome.exe http://192.168.1.12
;sendinput, ^lhttp://192.168.1.12/{enter}
}
}
if octopicounter=1
{
if octopiinput=3 {
run C:Program Files (x86)GoogleChromeApplicationchrome.exe http://192.168.1.14:5001
;sendinput, ^lhttp://192.168.2.167:5001{enter}
}
else if octopiinput=2
{
;sendinput, ^lhttp://192.168.1.13/{enter}
run C:Program Files (x86)GoogleChromeApplicationchrome.exe http://192.168.1.13:5001
}
else if octopiinput=1
{
run C:Program Files (x86)GoogleChromeApplicationchrome.exe http://192.168.1.12:5001
;sendinput, ^lhttp://192.168.1.12/{enter}
}
}
if octopicounter=2
{
if octopiinput=3
{
;sendinput, ^lhttp://192.168.2.167:5002{enter}
run C:Program Files (x86)GoogleChromeApplicationchrome.exe http://192.168.1.14:5002
}
else if octopiinput=2
{
;sendinput, ^lhttp://192.168.1.13/{enter}
run C:Program Files (x86)GoogleChromeApplicationchrome.exe http://192.168.1.13:5002
}
else if octopiinput=1
{
run C:Program Files (x86)GoogleChromeApplicationchrome.exe http://192.168.1.12:5002
;sendinput, ^lhttp://192.168.1.12/{enter}
}
}
if octopicounter=3
{
if octopiinput=3
{
;sendinput, ^lhttp://192.168.2.167:5003{enter}
run C:Program Files (x86)GoogleChromeApplicationchrome.exe http://192.168.1.14:5003
}
else if octopiinput=2
{
;sendinput, ^lhttp://192.168.1.13/{enter}
run C:Program Files (x86)GoogleChromeApplicationchrome.exe http://192.168.1.13:5003
}
else if octopiinput=1
{
run C:Program Files (x86)GoogleChromeApplicationchrome.exe http://192.168.1.12:5003
;sendinput, ^lhttp://192.168.1.12/{enter}
}
}
sleep 20
sendinput,{enter}
octopicounter++
}
if octopiinput=1
{
winwait,Mini1 [OctoPrint]
winwait,Mini2 [OctoPrint]
winwait,Mini3 [OctoPrint]
winwait,Mini4 [OctoPrint]
sleep 1000
winmove,Mini1 [OctoPrint],,0,0,960,1040
winmove,Mini2 [OctoPrint],,960,0,960,1040
winmove,Mini3 [OctoPrint],,1920,0,960,1040
winmove,Mini4 [OctoPrint],,2880,0,960,1040
}
if octopiinput=2
{
winwait,Mini5 [OctoPrint]
winwait,Mini6 [OctoPrint]
winwait,Mini7 [OctoPrint]
winwait,Mini8 [OctoPrint]
winmove,Mini5 [OctoPrint],,0,0,960,1040
winmove,Mini6 [OctoPrint],,960,0,960,1040
winmove,Mini7 [OctoPrint],,1920,0,960,1040
winmove,Mini8 [OctoPrint],,2880,0,960,1040
}
if octopiinput=3
{
winwait,I3-1 [OctoPrint]
winwait,I3-2 [OctoPrint]
winwait,I3-3 [OctoPrint]
winwait,I3-4 [OctoPrint]
winmove,I3-1 [OctoPrint],,0,0,960,1040
winmove,I3-2 [OctoPrint],,960,0,960,1040
winmove,I3-3 [OctoPrint],,1920,0,960,1040
winmove,I3-4 [OctoPrint],,2880,0,960,1040
}
return
I hope i can help.
;#NoTrayIcon
#Persistent
#SingleInstance force
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn ; Recommended for catching common errors.
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 0
#UseHook
ListLines Off
Process, Priority, , H
SetBatchLines, -1
SetKeyDelay, -1, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetControlDelay, -1
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
OnExit(«cleanup_before_exit»)
SetFormat, Float, 0.3
global volLvlB0 = -36.0
global VMR_FUNCTIONS := {}
global VMR_DLL_DRIVE := «C:»
global VMR_DLL_DIRPATH := «Program Files (x86)VBVoicemeeter»
global VMR_DLL_FILENAME_32 := «VoicemeeterRemote.dll»
global VMR_DLL_FILENAME_64 := «VoicemeeterRemote64.dll»
global VMR_DLL_FULL_PATH := VMR_DLL_DRIVE . «» . VMR_DLL_DIRPATH . «»
Sleep, 500
if (A_Is64bitOS) {
VMR_DLL_FULL_PATH .= VMR_DLL_FILENAME_64
} else {
VMR_DLL_FULL_PATH .= VMR_DLL_FILENAME_32
}
; == START OF EXECUTION ==
; ========================
; Load the VoicemeeterRemote DLL:
; This returns a module handle
global VMR_MODULE := DllCall(«LoadLibrary», «Str», VMR_DLL_FULL_PATH, «Ptr»)
if (ErrorLevel || VMR_MODULE == 0)
die(«Attempt to load VoiceMeeter Remote DLL failed.»)
; Populate VMR_FUNCTIONS
add_vmr_function(«Login»)
add_vmr_function(«Logout»)
add_vmr_function(«RunVoicemeeter»)
add_vmr_function(«SetParameterFloat»)
add_vmr_function(«GetParameterFloat»)
add_vmr_function(«IsParametersDirty»)
; «Login» to Voicemeeter, by calling the function in the DLL named ‘VBVMR_Login()’…
login_result := DllCall(VMR_FUNCTIONS[«Login»], «Int»)
if (ErrorLevel || login_result < 0)
die(«VoiceMeeter Remote login failed.»)
; If the login returns 1, that apparently means that Voicemeeter isn’t running,
; so we start it; pass 1 to run Voicemeeter, or 2 for Voicemeeter Banana:
if (login_result == 1) {
DllCall(VMR_FUNCTIONS[«RunVoicemeeter»], «Int», 2, «Int»)
if (ErrorLevel)
die(«Attempt to run VoiceMeeter failed.»)
Sleep 2000
}
spoOpen := 0
; == HOTKEYS ==
; =============
loop{
WinGetTitle, spotifyname, ahk_class SpotifyMainWindow
if(spotifyname != «» && spoOpen = 0){
DllCall(VMR_FUNCTIONS[«SetParameterFloat»], «AStr», «Bus[0].mode.Repeat», «Float», 1.0, «Int»)
spoOpen := 1
} else if (spoOpen = 1 && spotifyname = «»){
DllCall(VMR_FUNCTIONS[«SetParameterFloat»], «AStr», «Bus[0].mode.Normal», «Float», 1.0, «Int»)
spoOpen := 0
} else {
;do nothing
}
Sleep, 5000
ToolTip
}
Volume_Up::
readVolLvl()
;volLvlB0 += 1
;adjustVolLvl()
return
Volume_Down::
readVolLvl()
;volLvlB0 -= 1
;adjustVolLvl()
return
; == Functions ==
; ===============
;DllCall(VMR_FUNCTIONS[«SetParameterFloat»], «AStr», «Strip[0].B1», «Float», 1.0, «Int»)
readVolLvl(){
DLLCall(VMR_FUNCTIONS[«IsParametersDirty»])
statusLvlB0 = DllCall(VMR_FUNCTIONS[«GetParameterFloat»], «AStr», «Bus[0].Gain», «Ptr», &volLvlB0, «Int»)
if (statusLvlB0 < 0){
MsgBox, Error: %statusLvlB0%
} else {
SetFormat, Float, 0.3
MsgBox, %volLvlB0%
}
}
adjustVolLvl() {
if (volLvlB0 > 12.0){
volLvlB0 = 12.0
} else if (volLvlB0 < -60.0) {
volLvlB0 = -60.0
}
DllCall(VMR_FUNCTIONS[«SetParameterFloat»], «AStr», «Bus[0].Gain», «Float», volLvlB0, «Int»)
}
add_vmr_function(func_name) {
VMR_FUNCTIONS[func_name] := DllCall(«GetProcAddress», «Ptr», VMR_MODULE, «AStr», «VBVMR_» . func_name, «Ptr»)
if (ErrorLevel || VMR_FUNCTIONS[func_name] == 0)
die(«Failed to register VMR function » . func_name . «.»)
}
cleanup_before_exit(exit_reason, exit_code) {
DllCall(VMR_FUNCTIONS[«Logout»], «Int»)
; OnExit functions must return 0 to allow the app to exit.
return 0
}
die(die_string:=»UNSPECIFIED FATAL ERROR.», exit_status:=254) {
MsgBox 16, FATAL ERROR, %die_string%
ExitApp exit_status
}
FHex( int, pad=8 ) { ; Function by [VxE]. Formats an integer (decimals are truncated) as hex. NOT IN USE FOR NOW
; «Pad» may be the minimum number of digits that should appear on the right of the «0x».
Static hx := «0123456789ABCDEF»
If !( 0 < int |= 0 )
Return !int ? «0x0» : «-» FHex( -int, pad )
s := 1 + Floor( Ln( int ) / Ln( 16 ) )
h := SubStr( «0x0000000000000000», 1, pad := pad < s ? s + 2 : pad < 16 ? pad + 2 : 18 )
u := A_IsUnicode = 1
Loop % s
NumPut( *( &hx + ( ( int & 15 ) << u ) ), h, pad — A_Index << u, «UChar» ), int >>= 4
Return h
}
The 2 red lines should solve your problem.
info out of the VoicemeeterRemote.h:
/**
@brief Check if parameters have changed.
Call this function periodically (typically every 10 or 20ms).
(this function must be called from one thread only)
@return: 0: no new paramters.
1: New parameters -> update your display.
-1: error (unexpected)
-2: no server.
*/
Don’t worry your script was very helpful to understand this API.
Thanks for it too.